comparison src/event/ngx_event.c @ 3:34a521b1a148

nginx-0.0.1-2002-08-20-18:48:28 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 20 Aug 2002 14:48:28 +0000
parents 4eff17414a43
children c5f071d376e5
comparison
equal deleted inserted replaced
2:ffffe1499bce 3:34a521b1a148
1 1
2 #include <ngx_config.h> 2 #include <ngx_config.h>
3 #include <ngx_types.h> 3 #include <ngx_types.h>
4 #include <ngx_log.h> 4 #include <ngx_log.h>
5 #include <ngx_alloc.h> 5 #include <ngx_alloc.h>
6 #include <ngx_listen.h>
6 #include <ngx_connection.h> 7 #include <ngx_connection.h>
7 #include <ngx_event.h> 8 #include <ngx_event.h>
8 #include <ngx_event_accept.h> 9 #include <ngx_event_accept.h>
9 10
10 #include <ngx_select_module.h> 11 #include <ngx_select_module.h>
16 ngx_connection_t *ngx_connections; 17 ngx_connection_t *ngx_connections;
17 ngx_event_t *ngx_read_events, *ngx_write_events; 18 ngx_event_t *ngx_read_events, *ngx_write_events;
18 19
19 #if !(USE_KQUEUE) 20 #if !(USE_KQUEUE)
20 21
21 #if 1 22 #if 0
22 ngx_event_type_e ngx_event_type = NGX_SELECT_EVENT; 23 ngx_event_type_e ngx_event_type = NGX_SELECT_EVENT;
23 #else 24 #else
24 ngx_event_type_e ngx_event_type = NGX_KQUEUE_EVENT; 25 ngx_event_type_e ngx_event_type = NGX_KQUEUE_EVENT;
25 #endif 26 #endif
26 27
38 }; 39 };
39 40
40 #endif /* USE_KQUEUE */ 41 #endif /* USE_KQUEUE */
41 42
42 43
43 void ngx_worker(ngx_listen_t *sock, int n, ngx_pool_t *pool, ngx_log_t *log) 44 void ngx_pre_thread(ngx_array_t *ls, ngx_pool_t *pool, ngx_log_t *log)
44 { 45 {
45 int i, fd; 46 int i, fd;
47 ngx_listen_t *s;
46 48
47 /* per group */ 49 /* per group */
48 int max_connections = 512; 50 int max_connections = 512;
49 51
50 ngx_init_events(max_connections, log); 52 ngx_init_events(max_connections, log);
53 ngx_write_events = ngx_alloc(sizeof(ngx_event_t) * max_connections, log); 55 ngx_write_events = ngx_alloc(sizeof(ngx_event_t) * max_connections, log);
54 ngx_connections = ngx_alloc(sizeof(ngx_connection_t) 56 ngx_connections = ngx_alloc(sizeof(ngx_connection_t)
55 * max_connections, log); 57 * max_connections, log);
56 58
57 /* for each listening socket */ 59 /* for each listening socket */
58 for (i = 0; i < n; i++) { 60 s = (ngx_listen_t *) ls->elts;
59 fd = sock[i].fd; 61 for (i = 0; i < ls->nelts; i++) {
62
63 fd = s[i].fd;
60 64
61 ngx_memzero(&ngx_read_events[fd], sizeof(ngx_event_t)); 65 ngx_memzero(&ngx_read_events[fd], sizeof(ngx_event_t));
62 ngx_memzero(&ngx_write_events[fd], sizeof(ngx_event_t)); 66 ngx_memzero(&ngx_write_events[fd], sizeof(ngx_event_t));
63 ngx_memzero(&ngx_connections[fd], sizeof(ngx_connection_t)); 67 ngx_memzero(&ngx_connections[fd], sizeof(ngx_connection_t));
64 68
65 ngx_connections[fd].fd = fd; 69 ngx_connections[fd].fd = fd;
66 ngx_connections[fd].server = sock[i].server; 70 ngx_connections[fd].server = s[i].server;
67 ngx_connections[fd].read = (void *) &ngx_read_events[fd].data; 71 ngx_connections[fd].read = (void *) &ngx_read_events[fd].data;
72 ngx_connections[fd].handler = s[i].handler;
68 ngx_read_events[fd].data = &ngx_connections[fd]; 73 ngx_read_events[fd].data = &ngx_connections[fd];
69 ngx_read_events[fd].log = ngx_connections[fd].log = sock[i].log; 74 ngx_read_events[fd].log = ngx_connections[fd].log = s[i].log;
70 ngx_read_events[fd].data = &ngx_connections[fd]; 75 ngx_read_events[fd].data = &ngx_connections[fd];
71 ngx_read_events[fd].event_handler = &ngx_event_accept; 76 ngx_read_events[fd].event_handler = &ngx_event_accept;
72 ngx_read_events[fd].listening = 1; 77 ngx_read_events[fd].listening = 1;
73 78
74 ngx_read_events[fd].available = 0; 79 ngx_read_events[fd].available = 0;
75 80
76 #if (HAVE_DEFERRED_ACCEPT) 81 #if (HAVE_DEFERRED_ACCEPT)
77 ngx_read_events[fd].accept_filter = sock->accept_filter; 82 ngx_read_events[fd].accept_filter = s[i].accept_filter;
78 #endif 83 #endif
79 ngx_add_event(&ngx_read_events[fd], NGX_READ_EVENT, 0); 84 ngx_add_event(&ngx_read_events[fd], NGX_READ_EVENT, 0);
80 } 85 }
86 }
81 87
88 void ngx_worker(ngx_log_t *log)
89 {
82 while (1) { 90 while (1) {
83 ngx_log_debug(log, "ngx_worker cycle"); 91 ngx_log_debug(log, "ngx_worker cycle");
84 92
85 ngx_process_events(log); 93 ngx_process_events(log);
86 } 94 }