36 {
39 throw std::runtime_error("cannot create socket");
40
41 sockaddr_in addrhint{};
42 addrhint.sin_family = AF_INET;
43 addrhint.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
44 addrhint.sin_port = htons(INADDR_ANY);
45
46 static const int yes { 1 };
47 if(setsockopt(*
mListenSocket, SOL_SOCKET, SO_REUSEADDR,
reinterpret_cast<const char*
>(&yes),
sizeof(yes)) ==
SOCKET_ERROR)
48 throw std::runtime_error("cannot configure listen socket");
49
51 throw std::runtime_error("socket bind error");
52
54 throw std::runtime_error("socket listen error");
55
56 sockaddr_in addr{};
57 socklen_t addr_len { sizeof (addr) };
59 throw std::runtime_error("failed to get socket name");
60
62
63 mChannel = std::make_unique<BufferedIPCChannel>();
65 {
67
68 while(true)
69 {
70 {
71
72
73 std::lock_guard lck {
mSync};
75 return;
76
77 if(connfd)
78 {
80 try
81 {
83 }
84 catch(...)
85 {
87 }
88
89 break;
90 }
91 }
92
93 fd_set readfds, exceptfds;
94 FD_ZERO(&readfds);
95 FD_ZERO(&exceptfds);
98
100 if(ret == 1)
101 {
103 if(!connfd)
104 {
106 break;
107 }
108
109 }
110 else
111 {
113 break;
114 }
115 }
116 });
117 }
virtual void OnConnectionError() noexcept=0
Called when connection attempt fails.
socket_guard mListenSocket
std::unique_ptr< BufferedIPCChannel > mChannel
std::unique_ptr< std::thread > mConnectionRoutine
RAII-style socket wrapper. Since socket is closed on wrapper destruction, initializing multiple guard...
void reset() noexcept
Closes the socket.
SOCKET release() noexcept
Returns the socket descriptor and releases ownership.