-
Notifications
You must be signed in to change notification settings - Fork 2
/
ngx_recv.php
60 lines (45 loc) · 1.19 KB
/
ngx_recv.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
59
60
<?php
/**
* Created by PhpStorm.
* User: zenus
* Date: 16-1-25
* Time: 下午8:48
*/
function ngx_unix_recv(ngx_connection_t $c, $buf, $size)
{
// ssize_t n;
// ngx_err_t err;
// ngx_event_t *rev;
$rev = $c->read;
do {
$n = socket_recv($c->fd, $buf, $size, 0);
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, $c->log, 0,
"recv: fd:%d %d of %d", $c->fd, $n, $size);
if ($n == 0) {
$rev->ready = 0;
$rev->eof = 1;
return $n;
} else if ($n > 0) {
if ( $n < $size
&& !(ngx_event_flags() & NGX_USE_GREEDY_EVENT))
{
$rev->ready = 0;
}
return $n;
}
$err = socket_last_error();
if ($err == NGX_EAGAIN || $err == NGX_EINTR) {
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, $c->log, $err,
"recv() not ready");
$n = NGX_AGAIN;
} else {
$n = ngx_connection_error($c, $err, "recv() failed");
break;
}
} while ($err == NGX_EINTR);
$rev->ready = 0;
if ($n == NGX_ERROR) {
$rev->error = 1;
}
return $n;
}