comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 377:41437e4fd9b4

nginx-0.0.7-2004-07-05-19:08:23 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 05 Jul 2004 15:08:23 +0000
parents 744ccb59062d
children 73688d5d7fc3
comparison
equal deleted inserted replaced
376:d0451e402e27 377:41437e4fd9b4
606 } 606 }
607 607
608 608
609 void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p) 609 void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p)
610 { 610 {
611 ngx_socket_t fd;
611 ngx_connection_t *c; 612 ngx_connection_t *c;
612 613
613 c = p->upstream->peer.connection; 614 c = p->upstream->peer.connection;
614 p->upstream->peer.connection = NULL; 615 p->upstream->peer.connection = NULL;
615 616
648 if (c->write->active || c->read->disabled) { 649 if (c->write->active || c->read->disabled) {
649 ngx_del_event(c->write, NGX_WRITE_EVENT, NGX_CLOSE_EVENT); 650 ngx_del_event(c->write, NGX_WRITE_EVENT, NGX_CLOSE_EVENT);
650 } 651 }
651 } 652 }
652 653
653 if (ngx_close_socket(c->fd) == -1) { 654 /*
655 * we have to clean the connection information before the closing
656 * because another thread may reopen the same file descriptor
657 * before we clean the connection
658 */
659
660 if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_OK) {
661
662 if (c->read->prev) {
663 ngx_delete_posted_event(c->read);
664 }
665
666 if (c->write->prev) {
667 ngx_delete_posted_event(c->write);
668 }
669
670 c->read->closed = 1;
671 c->write->closed = 1;
672
673 ngx_mutex_unlock(ngx_posted_events_mutex);
674 }
675
676 fd = c->fd;
677 c->fd = (ngx_socket_t) -1;
678 c->data = NULL;
679
680 if (ngx_close_socket(fd) == -1) {
654 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_socket_errno, 681 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_socket_errno,
655 ngx_close_socket_n " failed"); 682 ngx_close_socket_n " failed");
656 } 683 }
657
658 c->fd = (ngx_socket_t) -1;
659 } 684 }
660 685
661 686
662 size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len) 687 size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len)
663 { 688 {