src/server/daemon/event_solaris.c

Thu, 15 Aug 2024 21:46:57 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 15 Aug 2024 21:46:57 +0200
changeset 547
280bf87c8689
parent 541
1e1fca11aaff
child 552
4ed0e46aa9dc
permissions
-rw-r--r--

add functions to stop event handlers

29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
44
3da1f7b6847f added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 43
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <atomic.h>
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
33 #include "../util/io.h"
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
34
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "event_solaris.h"
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
531
9b15b1f72bef change nsapi_function_return behavior: move saf return to the end of the event cycle
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
37 #include "httprequest.h"
9b15b1f72bef change nsapi_function_return behavior: move saf return to the end of the event cycle
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
38
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
39 EVHandler* evhandler_create(EventHandlerConfig *cfg) {
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
40 EVHandler *ev = malloc(sizeof(EVHandler));
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
41 ev->current = 0;
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
42 ev->instances = calloc(cfg->nthreads, sizeof(void*));
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
43 ev->numins = cfg->nthreads;
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
45 for(int i=0;i<cfg->nthreads;i++) {
541
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
46 EventHandlerSolaris *handler = malloc(sizeof(EventHandlerSolaris));
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
47 memset(handler, 0, sizeof(EventHandlerSolaris));
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
48 ev->instances[i] = (EventHandler*)handler;
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
49
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
50 handler->port = port_create();
443
ef3c8a0e1fee improve daemon startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
51 if(handler->port < 0) {
ef3c8a0e1fee improve daemon startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
52 log_ereport(LOG_FAILURE, "evhandler_create: port_create: %s", strerror(errno));
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 return NULL;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
56 SYS_THREAD t = systhread_start(
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
57 0,
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
58 0,
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
59 (thrstartfunc)ev_handle_events,
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
60 handler);
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
61 systhread_detach(t);
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 return ev;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66
547
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
67 static volatile int ev_close = 0;
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
68
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
69 void ev_instance_close(EventHandler *h) {
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
70 EventHandlerSolaris *ev = (EventHandlerSolaris*)h;
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
71 close(ev->port);
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
72 ev_close = 1;
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
73 }
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
74
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
75 // unique event addr that indicates shutdown
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
76 static Event shutdown_event;
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
77 void ev_instance_shutdown(EventHandler *h) {
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
78 event_send(h, &shutdown_event);
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
79 }
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
80
529
cd606400f0ba change execution order of event handler and event finish functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 443
diff changeset
81
541
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
82 void ev_handle_events(EventHandlerSolaris *ev) {
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
83 EventHandler *h = (EventHandler*)ev;
529
cd606400f0ba change execution order of event handler and event finish functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 443
diff changeset
84 port_event_t events[EV_MAX_EVENTS];
cd606400f0ba change execution order of event handler and event finish functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 443
diff changeset
85 Event *finished[EV_MAX_EVENTS];
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 struct timespec timeout;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 timeout.tv_nsec = 0;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 timeout.tv_sec = 600;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 for(;;) {
79
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
91 // wait for events
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 uint_t nev = 1;
529
cd606400f0ba change execution order of event handler and event finish functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 443
diff changeset
93 int ret = port_getn(ev->port, events, EV_MAX_EVENTS, &nev, &timeout);
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 if(ret == -1) {
547
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
95 if(errno != EINTR && errno != ETIME) {
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
96 if(!ev_close) {
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
97 log_ereport(LOG_CATASTROPHE, "port_getn failed: %s", strerror(errno));
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
98 }
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
99 break;
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
100 }
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 continue;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103
529
cd606400f0ba change execution order of event handler and event finish functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 443
diff changeset
104 int numfinished = 0;
531
9b15b1f72bef change nsapi_function_return behavior: move saf return to the end of the event cycle
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
105 ev->numret = 0;
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 for(int i=0;i<nev;i++) {
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
107 Event *event = events[i].portev_user;
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
108 if(events[i].portev_source == PORT_SOURCE_AIO) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
109 aiocb_t *aiocb = (aiocb_t*)events[i].portev_object;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
110 if(event) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
111 aiocb_s *aio = (aiocb_s*)event->object;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
112 aio->result = aiocb->aio_resultp.aio_return;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
113 aio->result_errno = aiocb->aio_resultp.aio_errno;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
114 if(event->fn) {
541
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
115 if(!event->fn(h, event) && event->finish) {
529
cd606400f0ba change execution order of event handler and event finish functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 443
diff changeset
116 finished[numfinished++] = event;
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
117 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
118 }
43
8ac56edb4e94 fixed solaris build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
119 }
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
120 free(aiocb);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
121 } else {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
122 if(event->fn) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
123 if(event->fn(ev, event)) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
124 /*
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
125 * on solaris we have to reassociate the fd after
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
126 * each event
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
127 * we do this if the event function returns 1
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
128 */
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
129 if(port_associate(
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
130 ev->port,
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
131 PORT_SOURCE_FD,
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
132 (uintptr_t)event->object,
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
133 ev_convert2sys_events(event->events),
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
134 event))
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
135 {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
136 perror("port_associate");
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
137 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
138 } else if(event->finish) {
541
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
139 event->finish(h, event);
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
140 }
547
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
141 } else if(event == &shutdown_event) {
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
142 ev_instance_close(h);
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
143 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
144 }
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 }
529
cd606400f0ba change execution order of event handler and event finish functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 443
diff changeset
146 // call event finish handlers
cd606400f0ba change execution order of event handler and event finish functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 443
diff changeset
147 for(int i=0;i<numfinished;i++) {
cd606400f0ba change execution order of event handler and event finish functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 443
diff changeset
148 Event *event = finished[i];
537
ad44e72fbf50 add extra nullptr check in the event loop to handle the case when the finish ptr is set to NULL after it was already scheduled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
149 // check again if the finish callback is set
ad44e72fbf50 add extra nullptr check in the event loop to handle the case when the finish ptr is set to NULL after it was already scheduled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
150 if(finished[i]->finish) {
ad44e72fbf50 add extra nullptr check in the event loop to handle the case when the finish ptr is set to NULL after it was already scheduled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
151 finished[i]->finish(ev, event);
ad44e72fbf50 add extra nullptr check in the event loop to handle the case when the finish ptr is set to NULL after it was already scheduled
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 531
diff changeset
152 }
529
cd606400f0ba change execution order of event handler and event finish functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 443
diff changeset
153 }
531
9b15b1f72bef change nsapi_function_return behavior: move saf return to the end of the event cycle
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
154 // execute return calls
541
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
155 for(int i=0;i<ev->base.numret;i++) {
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
156 EVReturn ret = ev->base.fnreturn[i];
531
9b15b1f72bef change nsapi_function_return behavior: move saf return to the end of the event cycle
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
157 nsapi_saf_return(ret.sn, ret.rq, ret.ret);
9b15b1f72bef change nsapi_function_return behavior: move saf return to the end of the event cycle
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 529
diff changeset
158 }
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 }
547
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
160
280bf87c8689 add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 541
diff changeset
161 free(ev);
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
164 int ev_convert2sys_events(int events) {
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
165 int e = 0;
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
166 if((events & EVENT_POLLIN) == EVENT_POLLIN) {
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
167 e |= POLLIN;
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
168 }
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
169 if((events & EVENT_POLLOUT) == EVENT_POLLOUT) {
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
170 e |= POLLOUT;
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
171 }
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
172 return e;
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
175
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
176 int ev_pollin(EventHandler *h, int fd, Event *event) {
541
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
177 EventHandlerSolaris *ev = (EventHandlerSolaris*)h;
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 event->object = (intptr_t)fd;
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
179 event->events = EVENT_POLLIN;
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 return port_associate(
541
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
181 ev->port,
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 PORT_SOURCE_FD,
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 (uintptr_t)fd,
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 POLLIN,
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 event);
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
188 int ev_pollout(EventHandler *h, int fd, Event *event) {
541
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
189 EventHandlerSolaris *ev = (EventHandlerSolaris*)h;
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 event->object = (intptr_t)fd;
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
191 event->events = EVENT_POLLOUT;
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 return port_associate(
541
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
193 ev->port,
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 PORT_SOURCE_FD,
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 (uintptr_t)fd,
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 POLLOUT,
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 event);
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
200 int ev_remove_poll(EventHandler *h, int fd) {
541
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
201 EventHandlerSolaris *ev = (EventHandlerSolaris*)h;
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
202 return port_dissociate(ev->port, PORT_SOURCE_FD, (uintptr_t)fd);
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
203 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
204
187
4384bfbb7e26 adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 172
diff changeset
205 int event_send(EventHandler *h, Event *event) {
541
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
206 EventHandlerSolaris *ev = (EventHandlerSolaris*)h;
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
207 event->object = 0;
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
208 event->events = 0;
541
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
209 return port_send(ev->port, 0, event);
43
8ac56edb4e94 fixed solaris build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
210 }
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
211
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
212 static int ev_aio(int fd, aiocb_s *cb, WSBool read) {
541
1e1fca11aaff refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 537
diff changeset
213 EventHandlerSolaris *ev = cb->evhandler;
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
214 if(!ev) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
215 return -1;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
216 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
217
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
218 aiocb_t *aiocb = malloc(sizeof(aiocb_t));
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
219 if(!aiocb) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
220 return -1;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
221 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
222 ZERO(aiocb, sizeof(aiocb_t));
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
223
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
224 aiocb->aio_fildes = fd;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
225 aiocb->aio_buf = cb->buf;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
226 aiocb->aio_nbytes = cb->nbytes;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
227 aiocb->aio_offset = cb->offset;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
228
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
229 port_notify_t *portnotify = malloc(sizeof(port_notify_t));
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
230 if(!portnotify) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
231 free(aiocb);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
232 return -1;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
233 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
234 portnotify->portnfy_port = ev->port;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
235 portnotify->portnfy_user = cb->event;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
236 aiocb->aio_sigevent.sigev_notify = SIGEV_PORT;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
237 aiocb->aio_sigevent.sigev_value.sival_ptr = portnotify;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
238
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
239 if(read) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
240 return aio_read(aiocb);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
241 } else {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
242 return aio_write(aiocb);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
243 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
244 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
245
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
246 int ev_aioread(int fd, aiocb_s *cb) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
247 return ev_aio(fd, cb, TRUE);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
248 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
249
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
250 int ev_aiowrite(int fd, aiocb_s *cb) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
251 return ev_aio(fd, cb, FALSE);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
252 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
253
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
254
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
255 int event_pollin(EventHandler *ev, SYS_NETFD fd, Event *event) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
256 return ((IOStream*)fd)->poll(fd, ev, IO_POLL_IN, event);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
257 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
258
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
259 int event_pollout(EventHandler *ev, SYS_NETFD fd, Event *event) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
260 return ((IOStream*)fd)->poll(fd, ev, IO_POLL_OUT, event);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
261 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
262
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
263 int event_removepoll(EventHandler *ev, SYS_NETFD fd) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
264 return ((IOStream*)fd)->poll(fd, ev, IO_POLL_NONE, NULL);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
265 }

mercurial