nginx-0.0.7-2004-06-18-20:22:16 import

This commit is contained in:
Igor Sysoev 2004-06-18 16:22:16 +00:00
parent bf88014f2f
commit f7290501f2
5 changed files with 60 additions and 32 deletions

View File

@ -187,16 +187,6 @@ static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle)
size = 128 /* ngx_accept_mutex */
+ 128; /* ngx_connection_counter */
#if 0
shared = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
if (shared == MAP_FAILED) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
"mmap(MAP_ANON|MAP_SHARED) failed");
return NGX_ERROR;
}
#endif
if (!(shared = ngx_create_shared_memory(size, cycle->log))) {
return NGX_ERROR;
}
@ -635,6 +625,9 @@ static void *ngx_event_create_conf(ngx_cycle_t *cycle)
static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
{
ngx_event_conf_t *ecf = conf;
#if (HAVE_RTSIG)
ngx_core_conf_t *ccf;
#endif
#if (HAVE_KQUEUE)
@ -656,8 +649,6 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
#elif (HAVE_RTSIG)
ngx_core_conf_t *ccf;
ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS);
ngx_conf_init_unsigned_value(ecf->use, ngx_rtsig_module.ctx_index);
ngx_conf_init_ptr_value(ecf->name, ngx_rtsig_module_ctx.name->data);

View File

@ -6,9 +6,9 @@
static void ngx_execute_proc(ngx_cycle_t *cycle, void *data);
ngx_int_t ngx_current_slot;
ngx_int_t ngx_last_process;
ngx_int_t ngx_process_slot;
ngx_socket_t ngx_channel;
ngx_int_t ngx_last_process;
ngx_process_t ngx_processes[NGX_MAX_PROCESSES];
@ -31,6 +31,18 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle,
return NGX_ERROR;
}
if (ngx_nonblocking(ngx_processes[s].channel[0]) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_nonblocking_n " failed while spawning \"%s\"", name);
return NGX_ERROR;
}
if (ngx_nonblocking(ngx_processes[s].channel[1]) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
ngx_nonblocking_n " failed while spawning \"%s\"", name);
return NGX_ERROR;
}
on = 1;
if (ioctl(ngx_processes[s].channel[0], FIOASYNC, &on) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
@ -45,7 +57,7 @@ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle,
}
ngx_channel = ngx_processes[s].channel[1];
ngx_current_slot = s;
ngx_process_slot = s;
pid = fork();

View File

@ -49,9 +49,9 @@ ngx_pid_t ngx_execute(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx);
void ngx_process_get_status(void);
extern ngx_pid_t ngx_pid;
extern ngx_int_t ngx_current_slot;
extern ngx_int_t ngx_last_process;
extern ngx_socket_t ngx_channel;
extern ngx_int_t ngx_process_slot;
extern ngx_int_t ngx_last_process;
extern ngx_process_t ngx_processes[NGX_MAX_PROCESSES];

View File

@ -334,13 +334,33 @@ void ngx_single_process_cycle(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx)
static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
ngx_int_t type)
{
ngx_int_t i;
ngx_channel_t ch;
struct itimerval itv;
ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "start worker processes");
ch.command = NGX_CMD_OPEN_CHANNEL;
while (n--) {
ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
"worker process", type);
ch.pid = ngx_processes[ngx_process_slot].pid;
ch.slot = ngx_process_slot;
ch.fd = ngx_processes[ngx_process_slot].channel[0];
for (i = 0; i < ngx_last_process - 1; i++) {
ngx_log_debug3(NGX_LOG_DEBUG_CORE, cycle->log, 0,
"pass channel s: %d pid:" PID_T_FMT " fd:%d",
ch.slot, ch.pid, ch.fd);
/* TODO: NGX_AGAIN */
ngx_write_channel(ngx_processes[i].channel[0],
&ch, sizeof(ngx_channel_t), cycle->log);
}
}
/*
@ -360,6 +380,7 @@ static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
}
}
static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo)
{
ngx_int_t i;
@ -529,7 +550,7 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
for (n = 0; n <= ngx_last_process; n++) {
if (n == ngx_current_slot) {
if (n == ngx_process_slot) {
if (close(ngx_processes[n].channel[0]) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"close() failed");
@ -681,6 +702,16 @@ static void ngx_channel_handler(ngx_event_t *ev)
case NGX_CMD_REOPEN:
ngx_reopen = 1;
break;
case NGX_CMD_OPEN_CHANNEL:
ngx_log_debug3(NGX_LOG_DEBUG_CORE, ev->log, 0,
"get channel s:%d pid:" PID_T_FMT " fd:%d",
ch.slot, ch.pid, ch.fd);
ngx_processes[ch.slot].pid = ch.pid;
ngx_processes[ch.slot].channel[0] = ch.fd;
break;
}
}
@ -775,7 +806,7 @@ ngx_int_t ngx_write_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size,
msg.msg_iov = iov;
msg.msg_iovlen = 1;
n = sendmsg(s, &msg, MSG_DONTWAIT);
n = sendmsg(s, &msg, 0);
if (n == -1) {
err = ngx_errno;
@ -799,7 +830,7 @@ ngx_int_t ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size,
ngx_err_t err;
struct iovec iov[1];
struct msghdr msg;
struct cmsghdr *cm;
struct cmsghdr cm;
iov[0].iov_base = (char *) ch;
iov[0].iov_len = size;
@ -817,7 +848,7 @@ ngx_int_t ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size,
msg.msg_accrightslen = sizeof(int);
#endif
n = recvmsg(s, &msg, MSG_DONTWAIT);
n = recvmsg(s, &msg, 0);
if (n == -1) {
err = ngx_errno;
@ -838,28 +869,21 @@ ngx_int_t ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size,
#if (HAVE_MSGHDR_MSG_CONTROL)
if (ch->command == NGX_CMD_OPEN_CHANNEL) {
cm = (struct cmsghdr *) msg.msg_control;
if (cm == NULL) {
ngx_log_error(NGX_LOG_ALERT, log, 0,
"recvmsg() returned no ancillary data");
return NGX_ERROR;
}
if (cm->cmsg_len < sizeof(struct cmsghdr) + sizeof(int)) {
if (cm.cmsg_len < sizeof(struct cmsghdr) + sizeof(int)) {
ngx_log_error(NGX_LOG_ALERT, log, 0,
"recvmsg() returned too small ancillary data");
return NGX_ERROR;
}
if (cm->cmsg_level != SOL_SOCKET || cm->cmsg_type != SCM_RIGHTS) {
if (cm.cmsg_level != SOL_SOCKET || cm.cmsg_type != SCM_RIGHTS) {
ngx_log_error(NGX_LOG_ALERT, log, 0,
"recvmsg() returned invalid ancillary data "
"level %d or type %d", cm->cmsg_level, cm->cmsg_type);
"level %d or type %d", cm.cmsg_level, cm.cmsg_type);
return NGX_ERROR;
}
ch->fd = *((int *) ((char *) cm + sizeof(struct cmsghdr)));
ch->fd = *((int *) ((char *) &cm + sizeof(struct cmsghdr)));
}
if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) {

View File

@ -16,6 +16,7 @@
typedef struct {
ngx_uint_t command;
ngx_pid_t pid;
ngx_int_t slot;
ngx_fd_t fd;
} ngx_channel_t;