comparison src/event/ngx_event.c @ 0:4eff17414a43

nginx-0.0.1-2002-08-06-20:39:45 import The first code that uses "ngx_" prefix, the previous one used "gx_" prefix. At that point the code is not yet usable. The first draft ideas are dated back to 23.10.2001.
author Igor Sysoev <igor@sysoev.ru>
date Tue, 06 Aug 2002 16:39:45 +0000
parents
children 34a521b1a148
comparison
equal deleted inserted replaced
-1:000000000000 0:4eff17414a43
1
2 #include <ngx_config.h>
3 #include <ngx_types.h>
4 #include <ngx_log.h>
5 #include <ngx_alloc.h>
6 #include <ngx_connection.h>
7 #include <ngx_event.h>
8 #include <ngx_event_accept.h>
9
10 #include <ngx_select_module.h>
11 #if (HAVE_KQUEUE)
12 #include <ngx_kqueue_module.h>
13 #endif
14
15
16 ngx_connection_t *ngx_connections;
17 ngx_event_t *ngx_read_events, *ngx_write_events;
18
19 #if !(USE_KQUEUE)
20
21 #if 1
22 ngx_event_type_e ngx_event_type = NGX_SELECT_EVENT;
23 #else
24 ngx_event_type_e ngx_event_type = NGX_KQUEUE_EVENT;
25 #endif
26
27 ngx_event_actions_t ngx_event_actions;
28
29 /* ngx_event_type_e order */
30 static void (*ngx_event_init[]) (int max_connections, ngx_log_t *log) = {
31 ngx_select_init,
32 #if (HAVE_POLL)
33 ngx_poll_init,
34 #endif
35 #if (HAVE_KQUEUE)
36 ngx_kqueue_init
37 #endif
38 };
39
40 #endif /* USE_KQUEUE */
41
42
43 void ngx_worker(ngx_listen_t *sock, int n, ngx_pool_t *pool, ngx_log_t *log)
44 {
45 int i, fd;
46
47 /* per group */
48 int max_connections = 512;
49
50 ngx_init_events(max_connections, log);
51
52 ngx_read_events = ngx_alloc(sizeof(ngx_event_t) * max_connections, log);
53 ngx_write_events = ngx_alloc(sizeof(ngx_event_t) * max_connections, log);
54 ngx_connections = ngx_alloc(sizeof(ngx_connection_t)
55 * max_connections, log);
56
57 /* for each listening socket */
58 for (i = 0; i < n; i++) {
59 fd = sock[i].fd;
60
61 ngx_memzero(&ngx_read_events[fd], sizeof(ngx_event_t));
62 ngx_memzero(&ngx_write_events[fd], sizeof(ngx_event_t));
63 ngx_memzero(&ngx_connections[fd], sizeof(ngx_connection_t));
64
65 ngx_connections[fd].fd = fd;
66 ngx_connections[fd].server = sock[i].server;
67 ngx_connections[fd].read = (void *) &ngx_read_events[fd].data;
68 ngx_read_events[fd].data = &ngx_connections[fd];
69 ngx_read_events[fd].log = ngx_connections[fd].log = sock[i].log;
70 ngx_read_events[fd].data = &ngx_connections[fd];
71 ngx_read_events[fd].event_handler = &ngx_event_accept;
72 ngx_read_events[fd].listening = 1;
73
74 ngx_read_events[fd].available = 0;
75
76 #if (HAVE_DEFERRED_ACCEPT)
77 ngx_read_events[fd].accept_filter = sock->accept_filter;
78 #endif
79 ngx_add_event(&ngx_read_events[fd], NGX_READ_EVENT, 0);
80 }
81
82 while (1) {
83 ngx_log_debug(log, "ngx_worker cycle");
84
85 ngx_process_events(log);
86 }
87 }