MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / close_hostnode_ll

Function close_hostnode_ll

net/net.c:415–471  ·  view source on GitHub ↗

This must be called while holding the host_node_ptr->lock. * * This will call shutdown() on the fd, which will cause the reader & writer * threads (if any) to error out of any blocking io and exit. * * If there are no reader or writer threads left then this will properly * close the socket and sbuf. */

Source from the content-addressed store, hash-verified

413 * close the socket and sbuf.
414 */
415static void close_hostnode_ll(host_node_type *host_node_ptr)
416{
417 if (!host_node_ptr->closed) {
418 host_node_ptr->closed = 1;
419
420 /* this has to be done before notifying the sql transactions
421 that connection dropped, otherwise they will race and
422 send stuff before the host is reconnected; transaction is
423 send to garbcan without notifying sql, or master, and they
424 will never be applied */
425 host_node_ptr->got_hello = 0;
426
427 shutdown_hostnode_socket(host_node_ptr);
428
429 /* wake up the writer thread if it's asleep */
430 Pthread_cond_signal(&(host_node_ptr->write_wakeup));
431
432 /* call the hostdown routine if provided */
433 if (host_node_ptr->netinfo_ptr->hostdown_rtn) {
434 (host_node_ptr->netinfo_ptr->hostdown_rtn)(
435 host_node_ptr->netinfo_ptr, host_node_ptr->host_interned);
436 host_node_printf(LOGMSG_DEBUG, host_node_ptr, "back from hostdown_rtn\n");
437 }
438 }
439
440 if (gbl_libevent) {
441 return;
442 }
443
444 /* If we have an fd or sbuf, and no reader or writer thread, then
445 * close the socket properly */
446 if (host_node_ptr->have_reader_thread == 0 &&
447 host_node_ptr->have_writer_thread == 0 &&
448 host_node_ptr->really_closed == 0
449 ){
450 SBUF2 *sb = host_node_ptr->sb;
451 if (sb) {
452 if (sslio_has_ssl(sb))
453 sslio_close(sb, 1);
454 sbuf2close(host_node_ptr->sb);
455 host_node_ptr->sb = NULL;
456 if (gbl_verbose_net)
457 host_node_printf(LOGMSG_DEBUG, host_node_ptr, "closing sbuf\n");
458 }
459 if (host_node_ptr->fd >= 0) {
460 if (gbl_verbose_net)
461 host_node_printf(LOGMSG_DEBUG, host_node_ptr, "close fd %d\n",
462 host_node_ptr->fd);
463 if (close(host_node_ptr->fd) != 0)
464 host_node_errf(LOGMSG_ERROR, host_node_ptr, "%s close fd %d errno %d %s\n",
465 __func__, host_node_ptr->fd, errno,
466 strerror(errno));
467 host_node_ptr->fd = -1;
468 }
469 host_node_ptr->really_closed = 1;
470 }
471}
472

Callers 6

close_hostnodeFunction · 0.85
rem_from_netinfo_llFunction · 0.85
writer_threadFunction · 0.85
reader_threadFunction · 0.85
connect_threadFunction · 0.85
accept_handle_new_hostFunction · 0.85

Calls 3

shutdown_hostnode_socketFunction · 0.85
host_node_printfFunction · 0.85
host_node_errfFunction · 0.85

Tested by

no test coverage detected