src/server/daemon/event_solaris.c

Sun, 29 Dec 2019 21:43:14 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 29 Dec 2019 21:43:14 +0100
branch
webdav
changeset 214
4d7ac67a1c14
parent 193
aa8393527b1e
child 443
ef3c8a0e1fee
permissions
-rw-r--r--

add tests for webdav_propfind_init and fix wrong backend call

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
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
37 EVHandler* evhandler_create(EventHandlerConfig *cfg) {
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
38 EVHandler *ev = malloc(sizeof(EVHandler));
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
39 ev->current = 0;
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
40 ev->instances = calloc(cfg->nthreads, sizeof(void*));
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
41 ev->numins = cfg->nthreads;
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
43 for(int i=0;i<cfg->nthreads;i++) {
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
44 EventHandler *handler = malloc(sizeof(EventHandler));
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
45 ev->instances[i] = handler;
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
46
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
47 handler->port = port_create();
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
48 if(handler->port == 0) {
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
49 // TODO: error
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 return NULL;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
53 SYS_THREAD t = systhread_start(
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
54 0,
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
55 0,
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
56 (thrstartfunc)ev_handle_events,
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
57 handler);
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
58 systhread_detach(t);
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 return ev;
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
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
64 void ev_handle_events(EventHandler *ev) {
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
65 port_event_t events[64];
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 struct timespec timeout;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 timeout.tv_nsec = 0;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 timeout.tv_sec = 600;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 for(;;) {
79
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
71 // wait for events
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 uint_t nev = 1;
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
73 int ret = port_getn(ev->port, events, 64, &nev, &timeout);
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 if(ret == -1) {
79
f48cea237ec3 fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
75 // TODO: check for error
35
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
76 perror("port_getn");
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 continue;
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 for(int i=0;i<nev;i++) {
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
81 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
82 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
83 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
84 if(event) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
85 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
86 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
87 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
88 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
89 if(!event->fn(ev, event) && event->finish) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
90 event->finish(ev, event);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
91 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
92 }
43
8ac56edb4e94 fixed solaris build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
93 }
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
94 free(aiocb);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
95 } else {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
96 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
97 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
98 /*
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
99 * 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
100 * each event
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
101 * 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
102 */
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
103 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
104 ev->port,
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
105 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
106 (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
107 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
108 event))
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
109 {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
110 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
111 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
112 } else if(event->finish) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
113 event->finish(ev, event);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
114 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
115 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
116 }
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
121 int ev_convert2sys_events(int events) {
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
122 int e = 0;
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
123 if((events & EVENT_POLLIN) == EVENT_POLLIN) {
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
124 e |= POLLIN;
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
125 }
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
126 if((events & EVENT_POLLOUT) == EVENT_POLLOUT) {
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
127 e |= POLLOUT;
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
128 }
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
129 return e;
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
132
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
133 int ev_pollin(EventHandler *h, int fd, Event *event) {
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 event->object = (intptr_t)fd;
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
135 event->events = EVENT_POLLIN;
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 return port_associate(
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
137 h->port,
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 PORT_SOURCE_FD,
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 (uintptr_t)fd,
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 POLLIN,
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 event);
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
144 int ev_pollout(EventHandler *h, int fd, Event *event) {
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 event->object = (intptr_t)fd;
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
146 event->events = EVENT_POLLOUT;
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 return port_associate(
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
148 h->port,
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 PORT_SOURCE_FD,
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 (uintptr_t)fd,
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 POLLOUT,
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 event);
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 }
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
155 int ev_remove_poll(EventHandler *h, int fd) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
156 return port_dissociate(h->port, PORT_SOURCE_FD, (uintptr_t)fd);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
157 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
158
187
4384bfbb7e26 adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 172
diff changeset
159 int event_send(EventHandler *h, Event *event) {
159
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
160 event->object = 0;
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
161 event->events = 0;
9ba9f8befa80 makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
162 return port_send(h->port, 0, event);
43
8ac56edb4e94 fixed solaris build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
163 }
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
164
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
165 static int ev_aio(int fd, aiocb_s *cb, WSBool read) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
166 EventHandler *ev = cb->evhandler;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
167 if(!ev) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
168 return -1;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
169 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
170
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
171 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
172 if(!aiocb) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
173 return -1;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
174 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
175 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
176
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
177 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
178 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
179 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
180 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
181
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
182 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
183 if(!portnotify) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
184 free(aiocb);
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
185 return -1;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
186 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
187 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
188 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
189 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
190 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
191
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
192 if(read) {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
193 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
194 } else {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
195 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
196 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
197 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
198
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
199 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
200 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
201 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
202
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
203 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
204 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
205 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
206
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
207
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
208 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
209 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
210 }
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 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
213 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
214 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
215
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 159
diff changeset
216 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
217 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
218 }

mercurial