Sun, 01 May 2022 10:56:36 +0200
fix memory initialization for WebdavProperty in webdav tests
69 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
30 | #include <stdlib.h> | |
31 | ||
109
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
32 | #include "../util/atomic.h" |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
33 | |
69 | 34 | #include "event_bsd.h" |
35 | ||
170
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
36 | EVHandler* evhandler_create(EventHandlerConfig *cfg) { |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
37 | EVHandler *ev = malloc(sizeof(EVHandler)); |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
38 | ev->current = 0; |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
39 | ev->instances = calloc(cfg->nthreads, sizeof(void*)); |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
40 | ev->numins = cfg->nthreads; |
69 | 41 | |
170
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
42 | for(int i=0;i<cfg->nthreads;i++) { |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
43 | EventHandler *handler = malloc(sizeof(EventHandler)); |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
44 | ev->instances[i] = handler; |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
45 | |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
46 | handler->kqueue = kqueue(); |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
47 | if(handler->kqueue == 0) { |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
48 | // TODO: error |
69 | 49 | return NULL; |
50 | } | |
51 | ||
170
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
52 | SYS_THREAD t = systhread_start( |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
53 | 0, |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
54 | 0, |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
55 | (thrstartfunc)ev_handle_events, |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
56 | handler); |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
57 | systhread_detach(t); |
69 | 58 | } |
59 | ||
60 | return ev; | |
61 | } | |
62 | ||
170
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
63 | |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
64 | void ev_handle_events(EventHandler *ev) { |
109
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
65 | struct timespec timeout; |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
66 | timeout.tv_nsec = 0; |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
67 | timeout.tv_sec = 600; |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
68 | |
170
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
69 | struct kevent events[64]; |
265
59f99038a576
fix wrong kqueue usage: split ws events into multiple kevent filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
70 | struct kevent changes[128]; |
170
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
71 | int numchanges = 0; |
109
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
72 | |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
73 | for(;;) { |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
74 | // wait for events |
264
81f202caea5b
add ev_remove_poll kqueue implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
75 | int nev = kevent(ev->kqueue, changes, numchanges, events, 64, &timeout); |
109
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
76 | if(nev == -1) { |
265
59f99038a576
fix wrong kqueue usage: split ws events into multiple kevent filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
77 | log_ereport(LOG_FAILURE, "kevent: %s", strerror(errno)); |
109
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
78 | continue; |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
79 | } |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
80 | |
170
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
81 | numchanges = 0; |
109
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
82 | for(int i=0;i<nev;i++) { |
170
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
83 | Event *event = (Event*)events[i].udata; |
263
533f9097d712
fix kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
84 | if(!event) { |
266
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
85 | if(events[i].flags == 0) { |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
86 | log_ereport(LOG_WARN, "Unknown kevent (ident=%d)", (int)events[i].ident); |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
87 | } |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
88 | // don't warn in case flags is not 0, because socket EOF events |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
89 | // are triggered even if we apply EV_DELETE in the changelist |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
90 | // the only way to stop this is to apply the changelist without |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
91 | // getting new events, but that comes with a performance penalty |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
92 | |
263
533f9097d712
fix kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
93 | continue; |
533f9097d712
fix kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
94 | } |
533f9097d712
fix kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
95 | |
109
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
96 | if(event->fn) { |
263
533f9097d712
fix kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
97 | int saved_ev = event->events; |
533f9097d712
fix kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
98 | if(!event->fn(ev, event)) { |
533f9097d712
fix kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
99 | // ret 0 => remove event |
265
59f99038a576
fix wrong kqueue usage: split ws events into multiple kevent filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
100 | |
263
533f9097d712
fix kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
101 | if(event->finish) { |
533f9097d712
fix kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
102 | event->finish(ev, event); |
170
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
103 | } |
265
59f99038a576
fix wrong kqueue usage: split ws events into multiple kevent filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
104 | |
59f99038a576
fix wrong kqueue usage: split ws events into multiple kevent filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
105 | event->events = 0; |
263
533f9097d712
fix kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
106 | } |
533f9097d712
fix kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
260
diff
changeset
|
107 | |
265
59f99038a576
fix wrong kqueue usage: split ws events into multiple kevent filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
108 | // if events have changed, we need to add/remove filters |
59f99038a576
fix wrong kqueue usage: split ws events into multiple kevent filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
109 | if(saved_ev != event->events) { |
59f99038a576
fix wrong kqueue usage: split ws events into multiple kevent filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
110 | int e = event->events; |
59f99038a576
fix wrong kqueue usage: split ws events into multiple kevent filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
111 | int e_fd = events[i].ident; |
59f99038a576
fix wrong kqueue usage: split ws events into multiple kevent filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
112 | if((e & EVENT_POLLIN) != (saved_ev & EVENT_POLLIN)) { |
266
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
113 | if((e & EVENT_POLLIN) == EVENT_POLLIN) { |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
114 | // add |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
115 | EV_SET(&changes[numchanges++], e_fd, EVFILT_READ, EV_ADD, 0, 0, event); |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
116 | } else { |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
117 | // delete |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
118 | EV_SET(&changes[numchanges++], e_fd, EVFILT_READ, EV_DELETE, 0, 0, NULL); |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
119 | } |
265
59f99038a576
fix wrong kqueue usage: split ws events into multiple kevent filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
120 | } |
59f99038a576
fix wrong kqueue usage: split ws events into multiple kevent filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
121 | if((e & EVENT_POLLOUT) != (saved_ev & EVENT_POLLOUT)) { |
266
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
122 | if((e & EVENT_POLLOUT) == EVENT_POLLOUT) { |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
123 | // add |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
124 | EV_SET(&changes[numchanges++], e_fd, EVFILT_WRITE, EV_ADD, 0, 0, event); |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
125 | } else { |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
126 | // delete |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
127 | EV_SET(&changes[numchanges++], e_fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL); |
783467806e2d
fix kqueue event deletion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
265
diff
changeset
|
128 | } |
265
59f99038a576
fix wrong kqueue usage: split ws events into multiple kevent filters
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
264
diff
changeset
|
129 | } |
109
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
130 | } |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
131 | } |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
132 | } |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
133 | } |
69 | 134 | } |
135 | ||
170
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
136 | int ev_pollin(EventHandler *h, int fd, Event *event) { |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
137 | event->events = EVENT_POLLIN; |
109
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
138 | struct kevent kev; |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
139 | EV_SET(&kev, fd, EVFILT_READ, EV_ADD, 0, 0, event); |
170
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
140 | return kevent(h->kqueue, &kev, 1, NULL, 0, NULL); |
69 | 141 | } |
142 | ||
170
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
143 | int ev_pollout(EventHandler *h, int fd, Event *event) { |
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
144 | event->events = EVENT_POLLOUT; |
109
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
145 | struct kevent kev; |
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
146 | EV_SET(&kev, fd, EVFILT_WRITE, EV_ADD, 0, 0, event); |
170
711d00eeed25
refactors kqueue event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
133
diff
changeset
|
147 | return kevent(h->kqueue, &kev, 1, NULL, 0, NULL); |
69 | 148 | } |
149 | ||
260
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
150 | int ev_remove_poll(EventHandler *h, int fd) { |
264
81f202caea5b
add ev_remove_poll kqueue implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
151 | struct kevent kev; |
81f202caea5b
add ev_remove_poll kqueue implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
152 | EV_SET(&kev, fd, EVFILT_READ, EV_DELETE, 0, 0, NULL); |
81f202caea5b
add ev_remove_poll kqueue implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
153 | int r1 = kevent(h->kqueue, &kev, 1, NULL, 0, NULL); |
81f202caea5b
add ev_remove_poll kqueue implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
154 | EV_SET(&kev, fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL); |
81f202caea5b
add ev_remove_poll kqueue implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
155 | int r2 = kevent(h->kqueue, &kev, 1, NULL, 0, NULL); |
81f202caea5b
add ev_remove_poll kqueue implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
156 | // in caase r1 or r2 was successful, we return 0 (no error) |
81f202caea5b
add ev_remove_poll kqueue implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
263
diff
changeset
|
157 | return r1 != -1 || r2 != -1 ? 0 : 1; |
260
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
158 | } |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
159 | |
187
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
170
diff
changeset
|
160 | int event_send(EventHandler *h, Event *event) { |
109
8a0a7754f123
experimental BSD support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
161 | return 0; |
69 | 162 | } |
260
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
163 | |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
164 | // TODO: remove this fake aio |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
165 | int ev_aioread(int fd, aiocb_s *cb) { |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
166 | ssize_t result = pread(fd, cb->buf, cb->nbytes, cb->offset); |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
167 | cb->result = result; |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
168 | if(result < 0) { |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
169 | cb->result_errno = errno; |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
170 | } |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
171 | return event_send(cb->evhandler, cb->event); |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
172 | } |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
173 | |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
174 | int ev_aiowrite(int fd, aiocb_s *cb) { |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
175 | ssize_t result = pwrite(fd, cb->buf, cb->nbytes, cb->offset); |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
176 | cb->result = result; |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
177 | if(result < 0) { |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
178 | cb->result_errno = errno; |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
179 | } |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
180 | return event_send(cb->evhandler, cb->event); |
4779a6fb4fbe
fix freebsd build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
181 | } |