| 158 | |
| 159 | |
| 160 | Try<Nothing, SocketError> LibeventSSLSocketImpl::shutdown(int how) |
| 161 | { |
| 162 | // Nothing to do if this socket was never initialized. |
| 163 | synchronized (lock) { |
| 164 | if (bev == nullptr) { |
| 165 | // If it was not initialized, then there should also be no |
| 166 | // requests. |
| 167 | CHECK(connect_request.get() == nullptr); |
| 168 | CHECK(recv_request.get() == nullptr); |
| 169 | CHECK(send_request.get() == nullptr); |
| 170 | |
| 171 | // We expect this to fail and generate an 'ENOTCONN' failure as |
| 172 | // no connection should exist at this point. |
| 173 | if (::shutdown(s, how) < 0) { |
| 174 | return SocketError(); |
| 175 | } |
| 176 | |
| 177 | return Nothing(); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // Extend the life-time of 'this' through the execution of the |
| 182 | // lambda in the event loop. Note: The 'self' needs to be explicitly |
| 183 | // captured because we're not using it in the body of the lambda. We |
| 184 | // can use a 'shared_ptr' because run_in_event_loop is guaranteed to |
| 185 | // execute. |
| 186 | auto self = shared(this); |
| 187 | |
| 188 | run_in_event_loop( |
| 189 | [self]() { |
| 190 | CHECK(__in_event_loop__); |
| 191 | CHECK(self); |
| 192 | |
| 193 | CHECK_NOTNULL(self->bev); |
| 194 | |
| 195 | synchronized (self->bev) { |
| 196 | Owned<RecvRequest> request; |
| 197 | |
| 198 | // Swap the 'recv_request' under the object lock. |
| 199 | synchronized (self->lock) { |
| 200 | std::swap(request, self->recv_request); |
| 201 | } |
| 202 | |
| 203 | // If there is still a pending receive request then close it. |
| 204 | if (request.get() != nullptr) { |
| 205 | request->promise |
| 206 | .set(bufferevent_read(self->bev, request->data, request->size)); |
| 207 | } |
| 208 | |
| 209 | // Workaround for SSL shutdown, see http://www.wangafu.net/~nickm/libevent-book/Ref6a_advanced_bufferevents.html // NOLINT |
| 210 | SSL* ssl = bufferevent_openssl_get_ssl(self->bev); |
| 211 | SSL_set_shutdown(ssl, SSL_RECEIVED_SHUTDOWN); |
| 212 | SSL_shutdown(ssl); |
| 213 | } |
| 214 | }, |
| 215 | DISALLOW_SHORT_CIRCUIT); |
| 216 | |
| 217 | return Nothing(); |
nothing calls this directly
no test coverage detected