OLD | NEW |
| (Empty) |
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or
g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
2 <html xmlns="http://www.w3.org/1999/xhtml"> | |
3 <head> | |
4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> | |
5 <title> UDT Reference</title> | |
6 <link rel="stylesheet" href="udtdoc.css" type="text/css" /> | |
7 <style type="text/css"> | |
8 <!-- | |
9 .style1 {color: #FFFFFF} | |
10 --> | |
11 </style> | |
12 </head> | |
13 | |
14 <body> | |
15 <div class="ref_head"> UDT Reference: Functions</div> | |
16 | |
17 <h4 class="func_name"><strong>epoll</strong></h4> | |
18 <p>The <b>epoll</b> method can be used to effectively poll the IO events for a l
arge number of sockets. It includes the following APIs.</p> | |
19 | |
20 <div class="code"> | |
21 #ifndef WIN32<br /> | |
22 typedef int SYSSOCKET;<br /> | |
23 #else<br /> | |
24 typedef SOCKET SYSSOCKET;<br /> | |
25 #endif<br /> | |
26 | |
27 int epoll_create();<br /> | |
28 int epoll_add_usock(const int <span class="style1">eid</span>, const UDTSOCKET
<span class="style1">usock</span>, const int* <span class="style1">events</span
> = NULL);<br /> | |
29 int epoll_add_ssock(const int <span class="style1">eid</span>, const UDTSOCKET
<span class="style1">ssock</span>, const int* <span class="style1">events</span
> = NULL);<br /> | |
30 int epoll_remove_usock(const int <span class="style1">eid</span>, const UDTSOC
KET <span class="style1">usock</span>, const int* <span class="style1">events</s
pan> = NULL);<br /> | |
31 int epoll_remove_ssock(const int <span class="style1">eid</span>, const UDTSOC
KET <span class="style1">ssock</span>, const int* <span class="style1">events</s
pan> = NULL);<br /> | |
32 int epoll_wait(const int <span class="style1">eid</span>, std::set<UDTSOCKE
T>* <span class="style1">readfds</span>, std::set<UDTSOCKET>* <span cla
ss="style1">writefds</span>, int64_t msTimeOut, std::set<SYSSOCKET>* <span
class="style1">lrfds</span> = NULL, std::set<SYSSOCKET>* <span class="sty
le1">wrfds</span> = NULL);<br /> | |
33 int epoll_release(const int <span class="style1">eid</span>); | |
34 </div> | |
35 | |
36 <h5>Parameters</h5> | |
37 <dl> | |
38 <dt><em>eid</em></dt> | |
39 <dd>[in] The epoll ID allocated by epoll_create and used by subsequent epoll f
unctions. </dd> | |
40 <dt><em>usock</em></dt> | |
41 <dd>[in] the UDT socket ID to be added to or removed from the epoll.</dd> | |
42 <dt><em>ssock</em></dt> | |
43 <dd>[in] the system socket ID to be added to or removed from the epoll.</dd> | |
44 <dt><em>events</em></dt> | |
45 <dd>[in] events to be watched (ignored for UDT sockets).</dd> | |
46 <dt><em>readfds</em></dt> | |
47 <dd>[out] Optional pointer to a set of UDT sockets that are ready to read.</dd
> | |
48 <dt><em>writefds</em></dt> | |
49 <dd>[out] Optional pointer to a set of UDT sockets that are ready to write, or
are broken.</dd> | |
50 <dt><em>msTimeOut</em></dt> | |
51 <dd>[in] The time that this epoll should wait for the status change in the inp
ut groups, in milliseconds.</dd> | |
52 <dt><em>lrfds</em></dt> | |
53 <dd>[out] Optional pointer to a set of system sockets that are ready to read.<
/dd> | |
54 <dt><em>lwfds</em></dt> | |
55 <dd>[out] Optional pointer to a set of system sockets that are ready to write,
or are broken.</dd> | |
56 </dl> | |
57 | |
58 <h5>Return Value</h5> | |
59 <p>If successful, <strong>epoll_create</strong> returns a new epoll ID, <strong>
epoll_wait</strong> returns the total number of UDT sockets and system sockets r
eady for IO, and the other three functions return 0. On error, all functions ret
urn negative error values. The error can be one of the following. </p> | |
60 | |
61 | |
62 <table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#CCC
CCC"> | |
63 <tr> | |
64 <td width="17%" class="table_headline"><strong>Error Name</strong></td> | |
65 <td width="17%" class="table_headline"><strong>Error Code</strong></td> | |
66 <td width="83%" class="table_headline"><strong>Comment</strong></td> | |
67 </tr> | |
68 <tr> | |
69 <td>EINVPOLLID</td> | |
70 <td>5013</td> | |
71 <td>poll ID is invalid. </td> | |
72 </tr> | |
73 </table> | |
74 | |
75 <h5>Description</h5> | |
76 <p>The <strong>epoll</strong> functions provides a highly scalable and efficient
way to wait for UDT sockets IO events. It should be used instead of <a href="se
lect.htm">select</a> and <a href="selectex.htm">selectEx</a> when the applicatio
n needs to wait for a very large number of sockets. In addition, epoll also offe
rs to wait on system sockets at the same time, which can be convenient when an a
pplication uses both UDT and TCP/UDP. </p> | |
77 <p>Applications should use <strong>epoll_create</strong> to create an epoll ID a
nd use <strong>epoll_add_usock/ssock</strong> and <strong>epoll_remove_usock/sso
ck</strong> to add/remove sockets. If a socket is already in the epoll set, it w
ill be ignored if being added again. Invalid or closed sockets will also be igno
red with no errors returned. Multiple epoll entities can be created and there is
no upper limits as long as system resource allows. There is also no hard limit
on the number of UDT sockets and system descriptors to be watched.</p> | |
78 <p>For system sockets on Linux, developers may choose to watch individual events
from EPOLLIN (read), EPOLLOUT (write), and EPOLLERR (exceptions). When using <s
trong>epoll_remove_ssock</strong>, if the socket is waiting on multiple events,
only those specified in <em>events</em> are removed. The events can be a combina
tion (with "|" operation) of any of the following values. </p> | |
79 <p>enum EPOLLOpt<br /> | |
80 {<br /> | |
81 UDT_EPOLL_IN = 0x1,<br /> | |
82 UDT_EPOLL_OUT = 0x4,<br /> | |
83 UDT_EPOLL_ERR = 0x8<br /> | |
84 };</p> | |
85 <p>For all other situations, the parameter <em>events</em> is ignored and all ev
ents will be watched. </p> | |
86 <p>Note that exceptions are categorized as write events, so when the application
choose to write to this socket, it will detect the exception. </p> | |
87 <dl> | |
88 <h5>See Also</h5> | |
89 <p><strong><a href="select.htm">select</a></strong>, <a href="selectex.htm"><s
trong>selectEx</strong> </a></p> | |
90 <dt> </dt> | |
91 </dl> | |
92 | |
93 </body> | |
94 </html> | |
OLD | NEW |