|
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 |
|
32 #include "event_bsd.h" |
|
33 |
|
34 event_handler_t* evhandler_create(int numthreads) { |
|
35 event_handler_t *ev = malloc(sizeof(event_handler_t)); |
|
36 if(ev == NULL) { |
|
37 return NULL; |
|
38 } |
|
39 |
|
40 ev->ports = calloc(numthreads, sizeof(int)); |
|
41 if(ev->ports == NULL) { |
|
42 free(ev); |
|
43 return NULL; |
|
44 } |
|
45 ev->nports = numthreads; |
|
46 ev->lp = 0; |
|
47 |
|
48 /* create ports event threads */ |
|
49 for(int i=0;i<numthreads;i++) { |
|
50 /* create port */ |
|
51 //ev->ports[i] = port_create(); |
|
52 ev->ports[i] = kqueue(); |
|
53 if(ev->ports[i] == 0) { |
|
54 free(ev->ports); |
|
55 free(ev); |
|
56 return NULL; |
|
57 } |
|
58 |
|
59 /* |
|
60 * start a new handler thread |
|
61 * the thread needs the event port and a pointer to the event handler |
|
62 */ |
|
63 ev_thr_conf_t *conf = malloc(sizeof(ev_thr_conf_t)); |
|
64 if(conf == NULL) { |
|
65 free(ev->ports); |
|
66 free(ev); |
|
67 return NULL; |
|
68 } |
|
69 conf->handler = ev; |
|
70 conf->port = ev->ports[i]; |
|
71 |
|
72 ev_thr_conf_t *thrconf = malloc(sizeof(ev_thr_conf_t)); |
|
73 thrconf->handler = ev; |
|
74 thrconf->port = ev->ports[i]; |
|
75 systhread_start(0, 0, (thrstartfunc)ev_handle_events, thrconf); |
|
76 /* TODO: error handling */ |
|
77 } |
|
78 |
|
79 return ev; |
|
80 } |
|
81 |
|
82 void ev_handle_events(ev_thr_conf_t *conf) { |
|
83 |
|
84 } |
|
85 |
|
86 /* returns a event handler port */ |
|
87 int ev_get_port(event_handler_t *h) { |
|
88 |
|
89 } |
|
90 |
|
91 int ev_pollin(event_handler_t *h, int fd, event_t *event) { |
|
92 |
|
93 } |
|
94 |
|
95 int ev_pollout(event_handler_t *h, int fd, event_t *event) { |
|
96 |
|
97 } |
|
98 |
|
99 int ev_poll(event_handler_t *h, event_t *event) { |
|
100 |
|
101 } |
|
102 |
|
103 int evt_send(event_handler_t *h, event_t *event) { |
|
104 |
|
105 } |