ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev_port.c
(Generate patch)

Comparing libev/ev_port.c (file contents):
Revision 1.1 by root, Fri Nov 16 01:33:54 2007 UTC vs.
Revision 1.5 by root, Fri Nov 23 19:13:33 2007 UTC

8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 * 13 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
39 * once more silently being discarded. 37 * once more silently being discarded.
40 */ 38 */
41 if (!nev) 39 if (!nev)
42 { 40 {
43 if (oev) 41 if (oev)
44 port_dissociate (port_fd, PORT_SOURCE_FD, fd); 42 port_dissociate (backend_fd, PORT_SOURCE_FD, fd);
45 } 43 }
46 else if (0 > 44 else if (0 >
47 port_associate ( 45 port_associate (
48 port_fd, PORT_SOURCE_FD, fd, 46 backend_fd, PORT_SOURCE_FD, fd,
49 (nev & EV_READ ? POLLIN : 0) 47 (nev & EV_READ ? POLLIN : 0)
50 | (nev & EV_WRITE ? POLLOUT : 0), 48 | (nev & EV_WRITE ? POLLOUT : 0),
51 0 49 0
52 ) 50 )
53 ) 51 )
66 struct timespec ts; 64 struct timespec ts;
67 uint_t nget = 1; 65 uint_t nget = 1;
68 66
69 ts.tv_sec = (time_t)timeout; 67 ts.tv_sec = (time_t)timeout;
70 ts.tv_nsec = (long)(timeout - (ev_tstamp)ts.tv_sec) * 1e9; 68 ts.tv_nsec = (long)(timeout - (ev_tstamp)ts.tv_sec) * 1e9;
71 res = port_getn (port_fd, port_events, port_eventmax, &nget, &ts); 69 res = port_getn (backend_fd, port_events, port_eventmax, &nget, &ts);
72 70
73 if (res < 0) 71 if (res < 0)
74 { 72 {
75 if (errno != EINTR && errno != ETIME) 73 if (errno != EINTR && errno != ETIME)
76 syserr ("(libev) port_getn"); 74 syserr ("(libev) port_getn");
106 104
107static int 105static int
108port_init (EV_P_ int flags) 106port_init (EV_P_ int flags)
109{ 107{
110 /* Initalize the kernel queue */ 108 /* Initalize the kernel queue */
111 if ((port_fd = port_create ()) < 0) 109 if ((backend_fd = port_create ()) < 0)
112 return 0; 110 return 0;
113 111
114 fcntl (port_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */ 112 fcntl (backend_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */
115 113
116 method_fudge = 1e-3; /* needed to compensate for port_getn returning early */ 114 backend_fudge = 1e-3; /* needed to compensate for port_getn returning early */
117 method_modify = port_modify; 115 backend_modify = port_modify;
118 method_poll = port_poll; 116 backend_poll = port_poll;
119 117
120 port_eventmax = 64; /* intiial number of events receivable per poll */ 118 port_eventmax = 64; /* intiial number of events receivable per poll */
121 port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax); 119 port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax);
122 120
123 return EVMETHOD_PORT; 121 return EVBACKEND_PORT;
124} 122}
125 123
126static void 124static void
127port_destroy (EV_P) 125port_destroy (EV_P)
128{ 126{
129 close (port_fd); 127 close (backend_fd);
130 128
131 ev_free (port_events); 129 ev_free (port_events);
132} 130}
133 131
134static void 132static void
135port_fork (EV_P) 133port_fork (EV_P)
136{ 134{
137 close (port_fd); 135 close (backend_fd);
138 136
139 while ((port_fd = port_create ()) < 0) 137 while ((backend_fd = port_create ()) < 0)
140 syserr ("(libev) port"); 138 syserr ("(libev) port");
141 139
142 fcntl (port_fd, F_SETFD, FD_CLOEXEC); 140 fcntl (backend_fd, F_SETFD, FD_CLOEXEC);
143 141
144 /* re-register interest in fds */ 142 /* re-register interest in fds */
145 fd_rearm_all (EV_A); 143 fd_rearm_all (EV_A);
146} 144}
147 145

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines