| 247 | namespace dap { |
| 248 | |
| 249 | Socket::Socket(const char* address, const char* port) |
| 250 | : shared(Shared::create(address, port)) { |
| 251 | if (shared) { |
| 252 | shared->lock([&](SOCKET socket, const addrinfo* info) { |
| 253 | if (bind(socket, info->ai_addr, (int)info->ai_addrlen) != 0) { |
| 254 | shared.reset(); |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | if (listen(socket, 0) != 0) { |
| 259 | shared.reset(); |
| 260 | return; |
| 261 | } |
| 262 | }); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | std::shared_ptr<ReaderWriter> Socket::accept() const { |
| 267 | std::shared_ptr<Shared> out; |