75 */ |
75 */ |
76 static CxMap *listener_socket_map; |
76 static CxMap *listener_socket_map; |
77 |
77 |
78 static pthread_mutex_t listener_mutex = PTHREAD_MUTEX_INITIALIZER; |
78 static pthread_mutex_t listener_mutex = PTHREAD_MUTEX_INITIALIZER; |
79 |
79 |
|
80 static void wssocket_free(WSSocket *s) { |
|
81 close(s->socket); |
|
82 free(s); |
|
83 } |
80 |
84 |
81 int http_listener_global_init(void) { |
85 int http_listener_global_init(void) { |
82 listener_socket_map = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 4); |
86 listener_socket_map = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 4); |
83 if(!listener_socket_map) { |
87 if(!listener_socket_map) { |
84 return 1; |
88 return 1; |
85 } |
89 } |
|
90 listener_socket_map->simple_destructor = (cx_destructor_func)wssocket_free; |
86 |
91 |
87 return 0; |
92 return 0; |
|
93 } |
|
94 |
|
95 void http_listener_global_shutdown(void) { |
|
96 cxMapDestroy(listener_socket_map); |
88 } |
97 } |
89 |
98 |
90 int start_all_listener() { |
99 int start_all_listener() { |
91 ServerConfiguration *conf = cfgmgr_get_server_config(); |
100 ServerConfiguration *conf = cfgmgr_get_server_config(); |
92 CxList *ls = conf->listeners; |
101 CxList *ls = conf->listeners; |
426 log_ereport(LOG_DEBUG, "destroy http listener: %s config: %p", listener->name.ptr, listener->cfg); |
435 log_ereport(LOG_DEBUG, "destroy http listener: %s config: %p", listener->name.ptr, listener->cfg); |
427 |
436 |
428 if(listener->shutdown) { |
437 if(listener->shutdown) { |
429 pthread_mutex_destroy(&listener->shutdown_mutex); |
438 pthread_mutex_destroy(&listener->shutdown_mutex); |
430 pthread_cond_destroy(&listener->shutdown_cond); |
439 pthread_cond_destroy(&listener->shutdown_cond); |
|
440 |
|
441 free(listener->acceptors); |
|
442 free(listener->acceptors6); |
431 } |
443 } |
432 } |
444 } |
433 |
445 |
434 int http_listener_start(HttpListener *listener) { |
446 int http_listener_start(HttpListener *listener) { |
435 if(listener->running) { |
447 if(listener->running) { |
554 struct timespec ts; |
566 struct timespec ts; |
555 clock_gettime(CLOCK_REALTIME, &ts); |
567 clock_gettime(CLOCK_REALTIME, &ts); |
556 ts.tv_sec += 60; |
568 ts.tv_sec += 60; |
557 pthread_cond_timedwait(&listener->shutdown_cond, &listener->shutdown_mutex, &ts); |
569 pthread_cond_timedwait(&listener->shutdown_cond, &listener->shutdown_mutex, &ts); |
558 |
570 |
|
571 |
559 pthread_mutex_unlock(&listener->shutdown_mutex); |
572 pthread_mutex_unlock(&listener->shutdown_mutex); |
560 } |
573 } |
561 |
574 |
562 |
575 |
563 Acceptor* acceptor_new(HttpListener *listener) { |
576 Acceptor* acceptor_new(HttpListener *listener) { |