Klaus Demo nginx / 4c8eb42
read channel until EAGAIN Igor Sysoev 14 years ago
1 changed file(s) with 66 addition(s) and 62 deletion(s). Raw diff Collapse all Expand all
10531053
10541054 ngx_log_debug0(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel handler");
10551055
1056 n = ngx_read_channel(c->fd, &ch, sizeof(ngx_channel_t), ev->log);
1057
1058 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel: %i", n);
1059
1060 if (n == NGX_ERROR) {
1061
1062 if (ngx_event_flags & NGX_USE_EPOLL_EVENT) {
1063 ngx_del_conn(c, 0);
1064 }
1065
1066 ngx_close_connection(c);
1067 return;
1068 }
1069
1070 if (ngx_event_flags & NGX_USE_EVENTPORT_EVENT) {
1071 if (ngx_add_event(ev, NGX_READ_EVENT, 0) == NGX_ERROR) {
1056 for ( ;; ) {
1057
1058 n = ngx_read_channel(c->fd, &ch, sizeof(ngx_channel_t), ev->log);
1059
1060 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel: %i", n);
1061
1062 if (n == NGX_ERROR) {
1063
1064 if (ngx_event_flags & NGX_USE_EPOLL_EVENT) {
1065 ngx_del_conn(c, 0);
1066 }
1067
1068 ngx_close_connection(c);
10721069 return;
10731070 }
1074 }
1075
1076 if (n == NGX_AGAIN) {
1077 return;
1078 }
1079
1080 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0,
1081 "channel command: %d", ch.command);
1082
1083 switch (ch.command) {
1084
1085 case NGX_CMD_QUIT:
1086 ngx_quit = 1;
1087 break;
1088
1089 case NGX_CMD_TERMINATE:
1090 ngx_terminate = 1;
1091 break;
1092
1093 case NGX_CMD_REOPEN:
1094 ngx_reopen = 1;
1095 break;
1096
1097 case NGX_CMD_OPEN_CHANNEL:
1098
1099 ngx_log_debug3(NGX_LOG_DEBUG_CORE, ev->log, 0,
1100 "get channel s:%i pid:%P fd:%d", ch.slot, ch.pid, ch.fd);
1101
1102 ngx_processes[ch.slot].pid = ch.pid;
1103 ngx_processes[ch.slot].channel[0] = ch.fd;
1104 break;
1105
1106 case NGX_CMD_CLOSE_CHANNEL:
1107
1108 ngx_log_debug4(NGX_LOG_DEBUG_CORE, ev->log, 0,
1109 "close channel s:%i pid:%P our:%P fd:%d",
1110 ch.slot, ch.pid, ngx_processes[ch.slot].pid,
1111 ngx_processes[ch.slot].channel[0]);
1112
1113 if (close(ngx_processes[ch.slot].channel[0]) == -1) {
1114 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
1115 "close() channel failed");
1116 }
1117
1118 ngx_processes[ch.slot].channel[0] = -1;
1119 break;
1071
1072 if (ngx_event_flags & NGX_USE_EVENTPORT_EVENT) {
1073 if (ngx_add_event(ev, NGX_READ_EVENT, 0) == NGX_ERROR) {
1074 return;
1075 }
1076 }
1077
1078 if (n == NGX_AGAIN) {
1079 return;
1080 }
1081
1082 ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0,
1083 "channel command: %d", ch.command);
1084
1085 switch (ch.command) {
1086
1087 case NGX_CMD_QUIT:
1088 ngx_quit = 1;
1089 break;
1090
1091 case NGX_CMD_TERMINATE:
1092 ngx_terminate = 1;
1093 break;
1094
1095 case NGX_CMD_REOPEN:
1096 ngx_reopen = 1;
1097 break;
1098
1099 case NGX_CMD_OPEN_CHANNEL:
1100
1101 ngx_log_debug3(NGX_LOG_DEBUG_CORE, ev->log, 0,
1102 "get channel s:%i pid:%P fd:%d",
1103 ch.slot, ch.pid, ch.fd);
1104
1105 ngx_processes[ch.slot].pid = ch.pid;
1106 ngx_processes[ch.slot].channel[0] = ch.fd;
1107 break;
1108
1109 case NGX_CMD_CLOSE_CHANNEL:
1110
1111 ngx_log_debug4(NGX_LOG_DEBUG_CORE, ev->log, 0,
1112 "close channel s:%i pid:%P our:%P fd:%d",
1113 ch.slot, ch.pid, ngx_processes[ch.slot].pid,
1114 ngx_processes[ch.slot].channel[0]);
1115
1116 if (close(ngx_processes[ch.slot].channel[0]) == -1) {
1117 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
1118 "close() channel failed");
1119 }
1120
1121 ngx_processes[ch.slot].channel[0] = -1;
1122 break;
1123 }
11201124 }
11211125 }
11221126