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.4 by root, Fri Nov 23 05:13:49 2007 UTC vs.
Revision 1.6 by root, Mon Nov 26 08:06:15 2007 UTC

1/* 1/*
2 * libev solaris event port backend
3 *
2 * Copyright 2007 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved.
3 * 6 *
4 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions are
6 * are met: 9 * met:
7 * 10 *
8 * 1. Redistributions of source code must retain the above copyright 11 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 * * Redistributions in binary form must reproduce the above
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 * copyright notice, this list of conditions and the following
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 * disclaimer in the documentation and/or other materials provided
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 * with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 30 */
25 31
26#include <sys/types.h> 32#include <sys/types.h>
27#include <sys/time.h> 33#include <sys/time.h>
28#include <poll.h> 34#include <poll.h>
37 * once more silently being discarded. 43 * once more silently being discarded.
38 */ 44 */
39 if (!nev) 45 if (!nev)
40 { 46 {
41 if (oev) 47 if (oev)
42 port_dissociate (port_fd, PORT_SOURCE_FD, fd); 48 port_dissociate (backend_fd, PORT_SOURCE_FD, fd);
43 } 49 }
44 else if (0 > 50 else if (0 >
45 port_associate ( 51 port_associate (
46 port_fd, PORT_SOURCE_FD, fd, 52 backend_fd, PORT_SOURCE_FD, fd,
47 (nev & EV_READ ? POLLIN : 0) 53 (nev & EV_READ ? POLLIN : 0)
48 | (nev & EV_WRITE ? POLLOUT : 0), 54 | (nev & EV_WRITE ? POLLOUT : 0),
49 0 55 0
50 ) 56 )
51 ) 57 )
64 struct timespec ts; 70 struct timespec ts;
65 uint_t nget = 1; 71 uint_t nget = 1;
66 72
67 ts.tv_sec = (time_t)timeout; 73 ts.tv_sec = (time_t)timeout;
68 ts.tv_nsec = (long)(timeout - (ev_tstamp)ts.tv_sec) * 1e9; 74 ts.tv_nsec = (long)(timeout - (ev_tstamp)ts.tv_sec) * 1e9;
69 res = port_getn (port_fd, port_events, port_eventmax, &nget, &ts); 75 res = port_getn (backend_fd, port_events, port_eventmax, &nget, &ts);
70 76
71 if (res < 0) 77 if (res < 0)
72 { 78 {
73 if (errno != EINTR && errno != ETIME) 79 if (errno != EINTR && errno != ETIME)
74 syserr ("(libev) port_getn"); 80 syserr ("(libev) port_getn");
104 110
105static int 111static int
106port_init (EV_P_ int flags) 112port_init (EV_P_ int flags)
107{ 113{
108 /* Initalize the kernel queue */ 114 /* Initalize the kernel queue */
109 if ((port_fd = port_create ()) < 0) 115 if ((backend_fd = port_create ()) < 0)
110 return 0; 116 return 0;
111 117
112 fcntl (port_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */ 118 fcntl (backend_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */
113 119
114 backend_fudge = 1e-3; /* needed to compensate for port_getn returning early */ 120 backend_fudge = 1e-3; /* needed to compensate for port_getn returning early */
115 backend_modify = port_modify; 121 backend_modify = port_modify;
116 backend_poll = port_poll; 122 backend_poll = port_poll;
117 123
122} 128}
123 129
124static void 130static void
125port_destroy (EV_P) 131port_destroy (EV_P)
126{ 132{
127 close (port_fd); 133 close (backend_fd);
128 134
129 ev_free (port_events); 135 ev_free (port_events);
130} 136}
131 137
132static void 138static void
133port_fork (EV_P) 139port_fork (EV_P)
134{ 140{
135 close (port_fd); 141 close (backend_fd);
136 142
137 while ((port_fd = port_create ()) < 0) 143 while ((backend_fd = port_create ()) < 0)
138 syserr ("(libev) port"); 144 syserr ("(libev) port");
139 145
140 fcntl (port_fd, F_SETFD, FD_CLOEXEC); 146 fcntl (backend_fd, F_SETFD, FD_CLOEXEC);
141 147
142 /* re-register interest in fds */ 148 /* re-register interest in fds */
143 fd_rearm_all (EV_A); 149 fd_rearm_all (EV_A);
144} 150}
145 151

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines