[go: up one dir, main page]

Menu

[897c37]: / runtime / poll.c  Maximize  Restore  History

Download this file

85 lines (68 with data), 2.4 kB

 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
69
70
71
72
73
74
75
76
77
78
79
80
81
struct pollfd allfds[IPC_CONNECTION_MAX*2+1];
nextfd = 0;
for ( .. )
{
allfds[nextfd].fd = XXX[i].sock;
allfds[nextfd].events = POLLIN | POLLRDHUP;
if (ip->output_end - ip->output_start > 0)
{
allfds[nextfd].events = allfds[nextfd].events | POLLOUT;
}
nextfd++;
}
res = poll(allfds, nextfd, 20);
if (res > 0)
{
//printf("Found %d events\n", res);
if (allfds[0].revents & (POLLERR | POLLNVAL))
{
printf("listen error()\n");
}
if (allfds[0].revents & POLLIN)
{
//printf("call ipc_accept()\n");
ipc_accept();
}
for (int i = 1; i < nextfd; i++)
{
if (allfds[i].revents & POLLOUT)
{
// handle write
//printf("call ipc_write[%d]\n", i);
ipc_write(conn[i]);
}
if (allfds[i].revents & POLLIN)
{
// handle read
//printf("call ipc_read[%d]\n", i);
ipc_read(conn[i]);
}
if ((conn[i]->state == ipc_conn_state_conndrop)
|| (allfds[i].revents & (POLLRDHUP | POLLERR | POLLHUP)))
{
if (conn[i]->retries > 0 && conn[i]->ipc_send_buf_used)
{
// retry a few times?
if (debug) fprintf(stderr,"ipc_service_process_active: retry socket (sock=%d) on new socket\n", conn[i]->sock);
conn[i]->retries--;
last_response.causeCode = 0;
conn[i]->state = ipc_conn_state_start;
continue;
}
// handle problem by closing it and tossing it
if (debug) fprintf(stderr,"closing connection (sock=%d) revent=%x\n", conn[i]->sock, allfds[i].revents);
ipc_close_conn(conn[i]);
// set a result
result = IPC_MsgType_Connection_Error;
last_response.causeCode = IPC_CauseCode_CPU_Busy;
last_response.remote_dest = conn[i]->remote_dest;
continue;
}
}
}
else if (res < 0)
{
if ( errno == EINTR || errno == EAGAIN )
return 0; // Ignore these errors
// barf
}