src/server/daemon/event_solaris.c

branch
aio
changeset 172
5580517faafc
parent 159
9ba9f8befa80
child 187
4384bfbb7e26
equal deleted inserted replaced
170:711d00eeed25 172:5580517faafc
27 */ 27 */
28 28
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <atomic.h> 31 #include <atomic.h>
32
33 #include "../util/io.h"
32 34
33 #include "event_solaris.h" 35 #include "event_solaris.h"
34 36
35 EVHandler* evhandler_create(EventHandlerConfig *cfg) { 37 EVHandler* evhandler_create(EventHandlerConfig *cfg) {
36 EVHandler *ev = malloc(sizeof(EVHandler)); 38 EVHandler *ev = malloc(sizeof(EVHandler));
75 continue; 77 continue;
76 } 78 }
77 79
78 for(int i=0;i<nev;i++) { 80 for(int i=0;i<nev;i++) {
79 Event *event = events[i].portev_user; 81 Event *event = events[i].portev_user;
80 if(event->fn) { 82 if(events[i].portev_source == PORT_SOURCE_AIO) {
81 if(event->fn(ev, event)) { 83 aiocb_t *aiocb = (aiocb_t*)events[i].portev_object;
82 /* 84 if(event) {
83 * on solaris we have to reassociate the fd after 85 aiocb_s *aio = (aiocb_s*)event->object;
84 * each event 86 aio->result = aiocb->aio_resultp.aio_return;
85 * we do this if the event function returns 1 87 aio->result_errno = aiocb->aio_resultp.aio_errno;
86 */ 88 if(event->fn) {
87 if(port_associate( 89 if(!event->fn(ev, event) && event->finish) {
88 ev->port, 90 event->finish(ev, event);
89 PORT_SOURCE_FD, 91 }
90 (uintptr_t)event->object, 92 }
91 ev_convert2sys_events(event->events),
92 event))
93 {
94 perror("port_associate");
95 }
96 } else if(event->finish) {
97 event->finish(ev, event);
98 } 93 }
99 } 94 free(aiocb);
95 } else {
96 if(event->fn) {
97 if(event->fn(ev, event)) {
98 /*
99 * on solaris we have to reassociate the fd after
100 * each event
101 * we do this if the event function returns 1
102 */
103 if(port_associate(
104 ev->port,
105 PORT_SOURCE_FD,
106 (uintptr_t)event->object,
107 ev_convert2sys_events(event->events),
108 event))
109 {
110 perror("port_associate");
111 }
112 } else if(event->finish) {
113 event->finish(ev, event);
114 }
115 }
116 }
100 } 117 }
101 } 118 }
102 } 119 }
103 120
104 int ev_convert2sys_events(int events) { 121 int ev_convert2sys_events(int events) {
133 (uintptr_t)fd, 150 (uintptr_t)fd,
134 POLLOUT, 151 POLLOUT,
135 event); 152 event);
136 } 153 }
137 154
138 int evt_send(EventHandler *h, Event *event) { 155 int ev_remove_poll(EventHandler *h, int fd) {
156 return port_dissociate(h->port, PORT_SOURCE_FD, (uintptr_t)fd);
157 }
158
159 int ev_send(EventHandler *h, Event *event) {
139 event->object = 0; 160 event->object = 0;
140 event->events = 0; 161 event->events = 0;
141 return port_send(h->port, 0, event); 162 return port_send(h->port, 0, event);
142 } 163 }
164
165 static int ev_aio(int fd, aiocb_s *cb, WSBool read) {
166 EventHandler *ev = cb->evhandler;
167 if(!ev) {
168 return -1;
169 }
170
171 aiocb_t *aiocb = malloc(sizeof(aiocb_t));
172 if(!aiocb) {
173 return -1;
174 }
175 ZERO(aiocb, sizeof(aiocb_t));
176
177 aiocb->aio_fildes = fd;
178 aiocb->aio_buf = cb->buf;
179 aiocb->aio_nbytes = cb->nbytes;
180 aiocb->aio_offset = cb->offset;
181
182 port_notify_t *portnotify = malloc(sizeof(port_notify_t));
183 if(!portnotify) {
184 free(aiocb);
185 return -1;
186 }
187 portnotify->portnfy_port = ev->port;
188 portnotify->portnfy_user = cb->event;
189 aiocb->aio_sigevent.sigev_notify = SIGEV_PORT;
190 aiocb->aio_sigevent.sigev_value.sival_ptr = portnotify;
191
192 if(read) {
193 return aio_read(aiocb);
194 } else {
195 return aio_write(aiocb);
196 }
197 }
198
199 int ev_aioread(int fd, aiocb_s *cb) {
200 return ev_aio(fd, cb, TRUE);
201 }
202
203 int ev_aiowrite(int fd, aiocb_s *cb) {
204 return ev_aio(fd, cb, FALSE);
205 }
206
207
208 int event_pollin(EventHandler *ev, SYS_NETFD fd, Event *event) {
209 return ((IOStream*)fd)->poll(fd, ev, IO_POLL_IN, event);
210 }
211
212 int event_pollout(EventHandler *ev, SYS_NETFD fd, Event *event) {
213 return ((IOStream*)fd)->poll(fd, ev, IO_POLL_OUT, event);
214 }
215
216 int event_removepoll(EventHandler *ev, SYS_NETFD fd) {
217 return ((IOStream*)fd)->poll(fd, ev, IO_POLL_NONE, NULL);
218 }

mercurial