MCPcopy Create free account
hub / github.com/dermesser/libsocket / shutdown

Method shutdown

C++/streamclient.cpp:279–315  ·  view source on GitHub ↗

* @brief Shut a socket down * * Shuts a socket down using `shutdown(2)`. * * @param method `LIBSOCKET_READ/LIBSOCKET_WRITE` or an `OR`ed combination. */

Source from the content-addressed store, hash-verified

277 * @param method `LIBSOCKET_READ/LIBSOCKET_WRITE` or an `OR`ed combination.
278 */
279void stream_client_socket::shutdown(int method) {
280 int u_method = 0; // unix flags
281
282 // Already shut down using this method...
283 if ((method & (LIBSOCKET_READ | LIBSOCKET_WRITE)) && (shut_rd == true) &&
284 (shut_wr == true))
285 return;
286 if ((method & LIBSOCKET_READ) && (shut_rd == true)) return;
287 if ((method & LIBSOCKET_WRITE) && (shut_wr == true)) return;
288
289#if LIBSOCKET_LINUX || BD_ANDROID
290 using BERKELEY::SHUT_RD;
291 using BERKELEY::SHUT_RDWR;
292 using BERKELEY::SHUT_WR;
293#endif
294
295 if (method == (LIBSOCKET_READ | LIBSOCKET_WRITE))
296 u_method = SHUT_RDWR;
297 else if (method == LIBSOCKET_READ)
298 u_method = SHUT_RD;
299 else if (method == LIBSOCKET_WRITE)
300 u_method = SHUT_WR;
301 else // With no valid combination
302 return;
303
304 if (0 >
305 BERKELEY::shutdown(sfd, u_method)) // It's equal whether we use this or
306 // its brother from libunixsocket
307 {
308 throw socket_exception(
309 __FILE__, __LINE__,
310 "stream_client_socket::shutdown() - Could not shutdown socket");
311 }
312
313 if (method & LIBSOCKET_READ) shut_rd = true;
314 if (method & LIBSOCKET_WRITE) shut_wr = true;
315}
316} // namespace libsocket

Callers 3

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 1

socket_exceptionClass · 0.85

Tested by

no test coverage detected