src/server/daemon/httplistener.c

changeset 541
1e1fca11aaff
parent 502
11ac3761c0e3
child 554
e0a6b761ddbc
equal deleted inserted replaced
540:d9c3c23c635b 541:1e1fca11aaff
32 #include <stdlib.h> 32 #include <stdlib.h>
33 33
34 #include <sys/shm.h> 34 #include <sys/shm.h>
35 #include <sys/ipc.h> 35 #include <sys/ipc.h>
36 #include <sys/file.h> 36 #include <sys/file.h>
37 #include <netinet/tcp.h>
37 #include <stdio.h> 38 #include <stdio.h>
38 #include <stdlib.h> 39 #include <stdlib.h>
39 #include <fcntl.h> 40 #include <fcntl.h>
40 #include <unistd.h> 41 #include <unistd.h>
41 #include <strings.h> 42 #include <strings.h>
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 }

mercurial