| 232 | } |
| 233 | |
| 234 | ISocketStream* do_connect(const sockaddr_storage* remote, |
| 235 | const sockaddr_storage* local = nullptr) { |
| 236 | auto stream = create_stream(remote->store.ss_family); |
| 237 | auto deleter = [&](KernelSocketStream*) { |
| 238 | auto errno_backup = errno; |
| 239 | delete stream; |
| 240 | errno = errno_backup; |
| 241 | }; |
| 242 | std::unique_ptr<KernelSocketStream, decltype(deleter)> ptr(stream, deleter); |
| 243 | if (!ptr || ptr->fd < 0) { |
| 244 | LOG_ERROR_RETURN(0, nullptr, "Failed to create socket fd"); |
| 245 | } |
| 246 | if (m_opts.setsockopt(ptr->fd) < 0) { |
| 247 | return nullptr; |
| 248 | } |
| 249 | ptr->timeout(m_timeout); |
| 250 | if (local != nullptr) { |
| 251 | if (::bind(ptr->fd, local->get_sockaddr(), local->get_socklen()) != 0) { |
| 252 | LOG_ERRNO_RETURN(0, nullptr, "fail to bind socket"); |
| 253 | } |
| 254 | } |
| 255 | auto ret = fd_connect(ptr->fd, remote->get_sockaddr(), remote->get_socklen()); |
| 256 | if (ret < 0) { |
| 257 | LOG_ERRNO_RETURN(0, nullptr, "Failed to connect to ", remote->to_endpoint()); |
| 258 | } |
| 259 | return ptr.release(); |
| 260 | } |
| 261 | }; |
| 262 | |
| 263 | class KernelSocketServer : public SocketServerBase { |
nothing calls this directly
no test coverage detected