633 log_ereport(LOG_VERBOSE, "acceptor thread %p: listener: %p exit", acceptor, acceptor->listener); |
634 log_ereport(LOG_VERBOSE, "acceptor thread %p: listener: %p exit", acceptor, acceptor->listener); |
634 break; |
635 break; |
635 } |
636 } |
636 continue; |
637 continue; |
637 } |
638 } |
638 |
639 |
|
640 //if(http_listener_apply_keep_alive_settings(listener, clientfd)) { |
|
641 // close(clientfd); |
|
642 // continue; |
|
643 //} |
|
644 |
639 // check listener |
645 // check listener |
640 HttpListener *ls = listener; |
646 HttpListener *ls = listener; |
641 int acceptor_exit = 0; |
647 int acceptor_exit = 0; |
642 while(ls->next) { |
648 while(ls->next) { |
643 ls = ls->next; |
649 ls = ls->next; |
729 void wssocket_unref(WSSocket *ws) { |
735 void wssocket_unref(WSSocket *ws) { |
730 // does nothing yet, because maybe it is not a good idea to destroy |
736 // does nothing yet, because maybe it is not a good idea to destroy |
731 // a socket |
737 // a socket |
732 ws_atomic_dec32(&ws->ref); |
738 ws_atomic_dec32(&ws->ref); |
733 } |
739 } |
|
740 |
|
741 |
|
742 int http_listener_apply_keep_alive_settings(HttpListener *listener, int fd) { |
|
743 // TODO: all these values should be configurable |
|
744 int optval = 1; |
|
745 if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval))) { |
|
746 log_ereport(LOG_FAILURE, "listener: cannot set SO_KEEPALIVE: %s", strerror(errno)); |
|
747 return 1; |
|
748 } |
|
749 |
|
750 int keepidle = 60; |
|
751 if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepidle, sizeof(keepidle))) { |
|
752 log_ereport(LOG_FAILURE, "listener: cannot set TCP_KEEPIDLE to value %d: %s", keepidle, strerror(errno)); |
|
753 return 1; |
|
754 } |
|
755 |
|
756 int keepintvl = 10; |
|
757 if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &keepintvl, sizeof(keepintvl))) { |
|
758 log_ereport(LOG_FAILURE, "listener: cannot set TCP_KEEPINTVL to value %d: %s", keepintvl, strerror(errno)); |
|
759 return 1; |
|
760 } |
|
761 |
|
762 int keepcnt = 3; |
|
763 if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &keepcnt, sizeof(keepcnt))) { |
|
764 log_ereport(LOG_FAILURE, "listener: cannot set TCP_KEEPCNT to value %d: %s", keepcnt, strerror(errno)); |
|
765 return 1; |
|
766 } |
|
767 |
|
768 return 0; |
|
769 } |