| 136 | |
| 137 | |
| 138 | Future<Nothing> PollSocketImpl::connect( |
| 139 | const Address& address) |
| 140 | { |
| 141 | // Need to hold a copy of `this` so that the underlying socket |
| 142 | // doesn't end up getting reused before we return. |
| 143 | auto self = shared(this); |
| 144 | |
| 145 | return windows::connect(self->get(), address) |
| 146 | .then([self]() -> Future<Nothing> { |
| 147 | // After the async connect (`ConnectEx`) is called, the socket is in a |
| 148 | // "default" state, which means it doesn't have the previously set |
| 149 | // properties or options set. We need to set `SO_UPDATE_CONNECT_CONTEXT` |
| 150 | // so that it regains its properties. For more information, see |
| 151 | // https://msdn.microsoft.com/en-us/library/windows/desktop/ms737606(v=vs.85).aspx // NOLINT(whitespace/line_length) |
| 152 | int res = ::setsockopt( |
| 153 | self->get(), SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, nullptr, 0); |
| 154 | |
| 155 | if (res != 0) { |
| 156 | WindowsError error; |
| 157 | return Failure("Failed to set connected socket: " + error.message); |
| 158 | } |
| 159 | |
| 160 | return Nothing(); |
| 161 | }); |
| 162 | } |
| 163 | |
| 164 | |
| 165 | Future<size_t> PollSocketImpl::recv(char* data, size_t size) |