-
Notifications
You must be signed in to change notification settings - Fork 2
/
ngx_send.php
58 lines (44 loc) · 1.22 KB
/
ngx_send.php
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
<?php
/**
* Created by PhpStorm.
* User: zenus
* Date: 16-1-26
* Time: 上午7:14
*/
function ngx_unix_send(ngx_connection_t $c, $buf, $size)
{
// ssize_t n;
// ngx_err_t err;
// ngx_event_t *wev;
$wev = $c->write;
for ( ;; ) {
$n = socket_send($c->fd, $buf, $size, 0);
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, $c->log, 0,
"send: fd:%d %d of %d", $c->fd, $n, $size);
if ($n > 0) {
if ($n < $size) {
$wev->ready = 0;
}
$c->sent += $n;
return $n;
}
$err = socket_last_error();
if ($n == 0) {
ngx_log_error(NGX_LOG_ALERT, $c->log, $err, "send() returned zero");
$wev->ready = 0;
return $n;
}
if ($err == NGX_EAGAIN || $err == NGX_EINTR) {
$wev->ready = 0;
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, $c->log, $err,
"send() not ready");
if ($err == NGX_EAGAIN) {
return NGX_AGAIN;
}
} else {
$wev->error = 1;
ngx_connection_error($c, $err, "send() failed");
return NGX_ERROR;
}
}
}