src/server/daemon/httplistener.c

changeset 557
e35829a3a6d8
parent 554
e0a6b761ddbc
equal deleted inserted replaced
556:b036ccad4b49 557:e35829a3a6d8
45 #include <pthread.h> 45 #include <pthread.h>
46 46
47 #include <stdio.h> 47 #include <stdio.h>
48 #include <stdlib.h> 48 #include <stdlib.h>
49 49
50 #include <openssl/rand.h> /* RAND_bytes, connection id */
50 51
51 #include <cx/hash_map.h> 52 #include <cx/hash_map.h>
52 53
53 #include "../util/atomic.h" 54 #include "../util/atomic.h"
54 #include "httplistener.h" 55 #include "httplistener.h"
650 acceptor_exit = 1; 651 acceptor_exit = 1;
651 } 652 }
652 653
653 // create Connection object 654 // create Connection object
654 Connection *conn = malloc(sizeof(Connection)); 655 Connection *conn = malloc(sizeof(Connection));
656 uint32_t conn_id;
657 RAND_bytes((unsigned char*)&conn->id, sizeof(conn->id));
658 conn->id <<= 16;
655 conn->address = ca; 659 conn->address = ca;
656 conn->addr_type = addr_type; 660 conn->addr_type = addr_type;
657 conn->fd = clientfd; 661 conn->fd = clientfd;
658 conn->listener = ls; 662 conn->listener = ls;
659 conn->ssl_accepted = 0; 663 conn->ssl_accepted = 0;
660 conn->ssl_error = 0; 664 conn->ssl_error = 0;
665 log_ereport(LOG_DEBUG, "trace reqid: %016llx connection accepted", (unsigned long long int)conn->id);
661 if(socket_ssl) { 666 if(socket_ssl) {
662 // SSL connections are always non-blocking 667 // SSL connections are always non-blocking
663 // set socket non blocking 668 // set socket non blocking
664 int flags; 669 int flags;
665 if((flags = fcntl(conn->fd, F_GETFL, 0)) == -1) { 670 if((flags = fcntl(conn->fd, F_GETFL, 0)) == -1) {
666 flags = 0; 671 flags = 0;
667 } 672 }
668 if(fcntl(conn->fd, F_SETFL, flags | O_NONBLOCK)) { 673 if(fcntl(conn->fd, F_SETFL, flags | O_NONBLOCK)) {
674 log_ereport(LOG_DEBUG, "trace reqid: %016llx connection destroyed | fcntl error", (unsigned long long int)conn->id);
669 log_ereport(LOG_FAILURE, "acceptor: fcntl failed: %s", strerror(errno)); 675 log_ereport(LOG_FAILURE, "acceptor: fcntl failed: %s", strerror(errno));
670 close(clientfd); 676 close(clientfd);
671 free(conn); 677 free(conn);
672 conn = NULL; 678 conn = NULL;
673 } else { 679 } else {
678 conn->ssl = ssl; 684 conn->ssl = ssl;
679 conn->read = connection_ssl_read; 685 conn->read = connection_ssl_read;
680 conn->write = connection_ssl_write; 686 conn->write = connection_ssl_write;
681 conn->close = connection_ssl_close; 687 conn->close = connection_ssl_close;
682 } else { 688 } else {
689 log_ereport(LOG_DEBUG, "trace reqid: %016llx connection destroyed | SSL init error", (unsigned long long int)conn->id);
683 log_ereport(LOG_FAILURE, "acceptor: %p listener: %p SSL_new() failed", acceptor, acceptor->listener); 690 log_ereport(LOG_FAILURE, "acceptor: %p listener: %p SSL_new() failed", acceptor, acceptor->listener);
684 free(conn); 691 free(conn);
685 close(clientfd); 692 close(clientfd);
686 conn = NULL; 693 conn = NULL;
687 } 694 }

mercurial