Mercurial > hg > nginx
comparison src/core/nginx.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 | d220029ac7f3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4eff17414a43 |
---|---|
1 | |
2 #include <nginx.h> | |
3 | |
4 #include <ngx_config.h> | |
5 #include <ngx_string.h> | |
6 #include <ngx_log.h> | |
7 #include <ngx_alloc.h> | |
8 #include <ngx_server.h> | |
9 #include <ngx_connection.h> | |
10 #include <ngx_listen.h> | |
11 | |
12 /* | |
13 #include <ngx_http.h> | |
14 */ | |
15 | |
16 | |
17 #if !(WIN32) | |
18 static int ngx_options(int argc, char *const *argv); | |
19 #endif | |
20 | |
21 char *ngx_root = "/home/is/work/xml/xml/html"; | |
22 | |
23 int ngx_http_init_connection(void *data); | |
24 | |
25 | |
26 int ngx_max_conn = 512; | |
27 struct sockaddr_in ngx_addr = {0, AF_INET, 0, 0, 0}; | |
28 | |
29 | |
30 ngx_pool_t ngx_pool; | |
31 ngx_log_t ngx_log; | |
32 ngx_server_t ngx_server; | |
33 | |
34 | |
35 int main(int argc, char *const *argv) | |
36 { | |
37 char addr_text[22]; | |
38 ngx_socket_t fd; | |
39 ngx_listen_t ls; | |
40 #if (WIN32) | |
41 WSADATA wsd; | |
42 #endif | |
43 | |
44 | |
45 ngx_log.log_level = NGX_LOG_DEBUG; | |
46 ngx_pool.log = &ngx_log; | |
47 ngx_addr.sin_port = htons(8000); | |
48 ngx_addr.sin_family = AF_INET; | |
49 | |
50 #if !(WIN32) | |
51 if (ngx_options(argc, argv) == -1) | |
52 ngx_log_error(NGX_LOG_EMERG, (&ngx_log), 0, "invalid argument"); | |
53 #endif | |
54 | |
55 ngx_log_debug((&ngx_log), "%d, %s:%d" _ ngx_max_conn _ | |
56 inet_ntoa(ngx_addr.sin_addr) _ ntohs(ngx_addr.sin_port)); | |
57 | |
58 #if (WIN32) | |
59 if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) | |
60 ngx_log_error(NGX_LOG_EMERG, (&ngx_log), ngx_socket_errno, | |
61 "WSAStartup failed"); | |
62 #endif | |
63 | |
64 ngx_snprintf(ngx_cpystrn(addr_text, inet_ntoa(ngx_addr.sin_addr), 16), | |
65 7, ":%d", ntohs(ngx_addr.sin_port)); | |
66 fd = ngx_listen((struct sockaddr *) &ngx_addr, -1, &ngx_log, addr_text); | |
67 | |
68 ngx_server.buff_size = 1024; | |
69 ngx_server.handler = ngx_http_init_connection; | |
70 | |
71 /* daemon */ | |
72 | |
73 ls.fd = fd; | |
74 ls.server = &ngx_server; | |
75 ls.log = &ngx_log; | |
76 | |
77 /* fork */ | |
78 | |
79 ngx_worker(&ls, 1, &ngx_pool, &ngx_log); | |
80 } | |
81 | |
82 #if !(WIN32) | |
83 extern char *optarg; | |
84 | |
85 static int ngx_options(int argc, char *const *argv) | |
86 { | |
87 char ch, *pos; | |
88 int port; | |
89 | |
90 while ((ch = getopt(argc, argv, "l:c:")) != -1) { | |
91 switch (ch) { | |
92 case 'l': | |
93 if (pos = strchr(optarg, ':')) { | |
94 *(pos) = '\0'; | |
95 if ((port = atoi(pos + 1)) <= 0) | |
96 return -1; | |
97 ngx_addr.sin_port = htons(port); | |
98 } | |
99 | |
100 if ((ngx_addr.sin_addr.s_addr = inet_addr(optarg)) == INADDR_NONE) | |
101 return -1; | |
102 break; | |
103 | |
104 case 'c': | |
105 if ((ngx_max_conn = atoi(optarg)) <= 0) | |
106 return -1; | |
107 break; | |
108 | |
109 case '?': | |
110 default: | |
111 return -1; | |
112 } | |
113 | |
114 } | |
115 | |
116 return 0; | |
117 } | |
118 #endif |