2
Copyright (c) 2009-2010 Jay Sorg
4
Permission is hereby granted, free of charge, to any person obtaining a
5
copy of this software and associated documentation files (the "Software"),
6
to deal in the Software without restriction, including without limitation
7
the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
and/or sell copies of the Software, and to permit persons to whom the
9
Software is furnished to do so, subject to the following conditions:
11
The above copyright notice and this permission notice shall be included
12
in all copies or substantial portions of the Software.
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
DEALINGS IN THE SOFTWARE.
32
#define LLOG(_level, _args) \
33
do { if (_level < LOG_LEVEL) { printf _args ; } } while (0)
34
#define LLOGLN(_level, _args) \
35
do { if (_level < LOG_LEVEL) { printf _args ; printf("\n"); } } while (0)
43
wait_obj_new(const char * name)
45
struct wait_obj * obj;
47
obj = (struct wait_obj *) malloc(sizeof(struct wait_obj));
51
if (pipe(obj->pipe_fd) < 0)
53
LLOGLN(0, ("init_wait_obj: pipe failed"));
61
wait_obj_free(struct wait_obj * obj)
65
if (obj->pipe_fd[0] != -1)
67
close(obj->pipe_fd[0]);
70
if (obj->pipe_fd[1] != -1)
72
close(obj->pipe_fd[1]);
81
wait_obj_is_set(struct wait_obj * obj)
88
FD_SET(obj->pipe_fd[0], &rfds);
89
memset(&time, 0, sizeof(time));
90
num_set = select(obj->pipe_fd[0] + 1, &rfds, 0, 0, &time);
91
return (num_set == 1);
95
wait_obj_set(struct wait_obj * obj)
99
if (wait_obj_is_set(obj))
103
len = write(obj->pipe_fd[1], "sig", 4);
106
LLOGLN(0, ("set_wait_obj: error"));
113
wait_obj_clear(struct wait_obj * obj)
117
while (wait_obj_is_set(obj))
119
len = read(obj->pipe_fd[0], &len, 4);
122
LLOGLN(0, ("chan_man_clear_ev: error"));
130
wait_obj_select(struct wait_obj ** listobj, int numobj, int * listr, int numr,
138
struct timeval * ptime;
144
time.tv_sec = timeout / 1000;
145
time.tv_usec = (timeout * 1000) % 1000000;
152
for (index = 0; index < numobj; index++)
154
sock = listobj[index]->pipe_fd[0];
164
for (index = 0; index < numr; index++)
174
rv = select(max + 1, &fds, 0, 0, ptime);