-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy pathngx_linux_init.c
68 lines (51 loc) · 1.49 KB
/
ngx_linux_init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (C) Igor Sysoev
* Copyright (C) Nginx, Inc.
*/
#include <ngx_config.h>
#include <ngx_core.h>
u_char ngx_linux_kern_ostype[50];
u_char ngx_linux_kern_osrelease[50];
// nginx在linux里实际使用的操作系统接口调用
// 与标准posix io的区别是发送使用了sendfile
static ngx_os_io_t ngx_linux_io = {
ngx_unix_recv,
ngx_readv_chain,
ngx_udp_unix_recv,
ngx_unix_send,
ngx_udp_unix_send,
ngx_udp_unix_sendmsg_chain,
#if (NGX_HAVE_SENDFILE)
ngx_linux_sendfile_chain,
NGX_IO_SENDFILE
#else
ngx_writev_chain,
0
#endif
};
// 初始化ngx_os_io结构体,设置为linux的收发函数
// 在ngx_posix_init.c:ngx_os_init里调用
ngx_int_t
ngx_os_specific_init(ngx_log_t *log)
{
struct utsname u;
if (uname(&u) == -1) {
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "uname() failed");
return NGX_ERROR;
}
(void) ngx_cpystrn(ngx_linux_kern_ostype, (u_char *) u.sysname,
sizeof(ngx_linux_kern_ostype));
(void) ngx_cpystrn(ngx_linux_kern_osrelease, (u_char *) u.release,
sizeof(ngx_linux_kern_osrelease));
// rtsig功能在1.10里已经删除
// 重要的操作,设置为linux的接口函数
ngx_os_io = ngx_linux_io;
return NGX_OK;
}
// 仅打印notice日志,暂无意义
void
ngx_os_specific_status(ngx_log_t *log)
{
ngx_log_error(NGX_LOG_NOTICE, log, 0, "OS: %s %s",
ngx_linux_kern_ostype, ngx_linux_kern_osrelease);
}