41 ev->current = 0; |
41 ev->current = 0; |
42 ev->instances = calloc(cfg->nthreads, sizeof(void*)); |
42 ev->instances = calloc(cfg->nthreads, sizeof(void*)); |
43 ev->numins = cfg->nthreads; |
43 ev->numins = cfg->nthreads; |
44 |
44 |
45 for(int i=0;i<cfg->nthreads;i++) { |
45 for(int i=0;i<cfg->nthreads;i++) { |
46 EventHandler *handler = malloc(sizeof(EventHandler)); |
46 EventHandlerSolaris *handler = malloc(sizeof(EventHandlerSolaris)); |
47 ev->instances[i] = handler; |
47 memset(handler, 0, sizeof(EventHandlerSolaris)); |
|
48 ev->instances[i] = (EventHandler*)handler; |
48 |
49 |
49 handler->port = port_create(); |
50 handler->port = port_create(); |
50 if(handler->port < 0) { |
51 if(handler->port < 0) { |
51 log_ereport(LOG_FAILURE, "evhandler_create: port_create: %s", strerror(errno)); |
52 log_ereport(LOG_FAILURE, "evhandler_create: port_create: %s", strerror(errno)); |
52 return NULL; |
53 return NULL; |
90 if(event) { |
92 if(event) { |
91 aiocb_s *aio = (aiocb_s*)event->object; |
93 aiocb_s *aio = (aiocb_s*)event->object; |
92 aio->result = aiocb->aio_resultp.aio_return; |
94 aio->result = aiocb->aio_resultp.aio_return; |
93 aio->result_errno = aiocb->aio_resultp.aio_errno; |
95 aio->result_errno = aiocb->aio_resultp.aio_errno; |
94 if(event->fn) { |
96 if(event->fn) { |
95 if(!event->fn(ev, event) && event->finish) { |
97 if(!event->fn(h, event) && event->finish) { |
96 finished[numfinished++] = event; |
98 finished[numfinished++] = event; |
97 } |
99 } |
98 } |
100 } |
99 } |
101 } |
100 free(aiocb); |
102 free(aiocb); |
128 if(finished[i]->finish) { |
130 if(finished[i]->finish) { |
129 finished[i]->finish(ev, event); |
131 finished[i]->finish(ev, event); |
130 } |
132 } |
131 } |
133 } |
132 // execute return calls |
134 // execute return calls |
133 for(int i=0;i<ev->numret;i++) { |
135 for(int i=0;i<ev->base.numret;i++) { |
134 EVReturn ret = ev->fnreturn[i]; |
136 EVReturn ret = ev->base.fnreturn[i]; |
135 nsapi_saf_return(ret.sn, ret.rq, ret.ret); |
137 nsapi_saf_return(ret.sn, ret.rq, ret.ret); |
136 } |
138 } |
137 } |
139 } |
138 } |
140 } |
139 |
141 |
148 return e; |
150 return e; |
149 } |
151 } |
150 |
152 |
151 |
153 |
152 int ev_pollin(EventHandler *h, int fd, Event *event) { |
154 int ev_pollin(EventHandler *h, int fd, Event *event) { |
|
155 EventHandlerSolaris *ev = (EventHandlerSolaris*)h; |
153 event->object = (intptr_t)fd; |
156 event->object = (intptr_t)fd; |
154 event->events = EVENT_POLLIN; |
157 event->events = EVENT_POLLIN; |
155 return port_associate( |
158 return port_associate( |
156 h->port, |
159 ev->port, |
157 PORT_SOURCE_FD, |
160 PORT_SOURCE_FD, |
158 (uintptr_t)fd, |
161 (uintptr_t)fd, |
159 POLLIN, |
162 POLLIN, |
160 event); |
163 event); |
161 } |
164 } |
162 |
165 |
163 int ev_pollout(EventHandler *h, int fd, Event *event) { |
166 int ev_pollout(EventHandler *h, int fd, Event *event) { |
|
167 EventHandlerSolaris *ev = (EventHandlerSolaris*)h; |
164 event->object = (intptr_t)fd; |
168 event->object = (intptr_t)fd; |
165 event->events = EVENT_POLLOUT; |
169 event->events = EVENT_POLLOUT; |
166 return port_associate( |
170 return port_associate( |
167 h->port, |
171 ev->port, |
168 PORT_SOURCE_FD, |
172 PORT_SOURCE_FD, |
169 (uintptr_t)fd, |
173 (uintptr_t)fd, |
170 POLLOUT, |
174 POLLOUT, |
171 event); |
175 event); |
172 } |
176 } |
173 |
177 |
174 int ev_remove_poll(EventHandler *h, int fd) { |
178 int ev_remove_poll(EventHandler *h, int fd) { |
175 return port_dissociate(h->port, PORT_SOURCE_FD, (uintptr_t)fd); |
179 EventHandlerSolaris *ev = (EventHandlerSolaris*)h; |
|
180 return port_dissociate(ev->port, PORT_SOURCE_FD, (uintptr_t)fd); |
176 } |
181 } |
177 |
182 |
178 int event_send(EventHandler *h, Event *event) { |
183 int event_send(EventHandler *h, Event *event) { |
|
184 EventHandlerSolaris *ev = (EventHandlerSolaris*)h; |
179 event->object = 0; |
185 event->object = 0; |
180 event->events = 0; |
186 event->events = 0; |
181 return port_send(h->port, 0, event); |
187 return port_send(ev->port, 0, event); |
182 } |
188 } |
183 |
189 |
184 static int ev_aio(int fd, aiocb_s *cb, WSBool read) { |
190 static int ev_aio(int fd, aiocb_s *cb, WSBool read) { |
185 EventHandler *ev = cb->evhandler; |
191 EventHandlerSolaris *ev = cb->evhandler; |
186 if(!ev) { |
192 if(!ev) { |
187 return -1; |
193 return -1; |
188 } |
194 } |
189 |
195 |
190 aiocb_t *aiocb = malloc(sizeof(aiocb_t)); |
196 aiocb_t *aiocb = malloc(sizeof(aiocb_t)); |
233 } |
239 } |
234 |
240 |
235 int event_removepoll(EventHandler *ev, SYS_NETFD fd) { |
241 int event_removepoll(EventHandler *ev, SYS_NETFD fd) { |
236 return ((IOStream*)fd)->poll(fd, ev, IO_POLL_NONE, NULL); |
242 return ((IOStream*)fd)->poll(fd, ev, IO_POLL_NONE, NULL); |
237 } |
243 } |
238 |
|
239 void ev_saf_return(EventHandler *h, Session *sn, Request *rq, int ret) { |
|
240 h->fnreturn[h->numret++] = (EVReturn){ sn, rq, ret }; |
|
241 } |
|