MCPcopy Create free account
hub / github.com/3rdparty/libprocess / connect

Method connect

src/posix/poll_socket.cpp:116–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114
115
116Future<Nothing> PollSocketImpl::connect(
117 const Address& address)
118{
119 Try<Nothing, SocketError> connect = network::connect(get(), address);
120 if (connect.isError()) {
121 if (net::is_inprogress_error(connect.error().code)) {
122 // Need to hold a copy of `this` so that the underlying socket
123 // doesn't end up getting reused before we return from the call
124 // to `io::poll` and end up connecting incorrectly.
125 auto self = shared(this);
126
127 return io::poll(get(), io::WRITE)
128 .then([self, address]() -> Future<Nothing> {
129 // Now check that a successful connection was made.
130 int opt;
131 socklen_t optlen = sizeof(opt);
132
133 // NOTE: We cast to `char*` here because the function
134 // prototypes on Windows use `char*` instead of `void*`.
135 if (::getsockopt(
136 self->get(),
137 SOL_SOCKET,
138 SO_ERROR,
139 reinterpret_cast<char*>(&opt),
140 &optlen) < 0) {
141 return Failure(SocketError(
142 "Failed to get status of connect to " + stringify(address)));
143 }
144
145 if (opt != 0) {
146 return Failure(SocketError(
147 opt,
148 "Failed to connect to " +
149 stringify(address)));
150 }
151
152 return Nothing();
153 });
154 }
155
156 return Failure(connect.error());
157 }
158
159 return Nothing();
160}
161
162#ifdef USE_SSL_SOCKET
163Future<Nothing> PollSocketImpl::connect(

Callers 11

connectFunction · 0.45
connectSocketFunction · 0.45
link_connectMethod · 0.45
send_connectMethod · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45
connectSocketFunction · 0.45
TEST_PFunction · 0.45
mainFunction · 0.45
TEST_FFunction · 0.45
TEST_PFunction · 0.45

Calls 6

getFunction · 0.85
FailureClass · 0.85
connectFunction · 0.50
pollFunction · 0.50
thenMethod · 0.45
getMethod · 0.45

Tested by 7

TEST_FFunction · 0.36
TEST_FFunction · 0.36
connectSocketFunction · 0.36
TEST_PFunction · 0.36
mainFunction · 0.36
TEST_FFunction · 0.36
TEST_PFunction · 0.36