1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/* Milkway
*
* Copyright (C) 2008- Luo Jinghua <sunmoon1997@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef MW_POLL_H
#define MW_POLL_H
#include <milkway/mw-object.h>
#include <milkway/mw-error.h>
#include <milkway/mw-hash.h>
typedef struct mw_poll_type mw_poll_type_t;
typedef struct mw_poll mw_poll_t;
typedef struct mw_pollfd mw_pollfd_t;
#define MW_POLL_TYPE mw_poll_get_type()
struct mw_poll_type {
mw_object_type_t base;
mw_bool_t
(*poll) (mw_poll_t *self,
mw_pollfd_t *fds,
mw_uint_t nfds,
int timeout_);
};
struct mw_poll {
mw_object_t base;
mw_hash_t *fds;
};
typedef enum
{
MW_IO_IN = 1 << 0,
MW_IO_OUT = 1 << 1,
MW_IO_PRI = 1 << 2,
MW_IO_ERR = 1 << 3,
MW_IO_HUP = 1 << 4,
MW_IO_NVAL = 1 << 5
} mw_poll_event_t;
#ifdef MW_OS_WINDOWS
#define MW_WIN32_MSG_HANDLE 20091031
#endif
struct mw_pollfd {
mw_intptr_t fd;
unsigned short events;
unsigned short revents;
};
mw_public mw_poll_type_t*
mw_poll_get_type(void);
mw_public mw_poll_t*
mw_poll_init(mw_poll_t *self);
static mw_inline int
mw_poll_poll(mw_poll_t *self,
mw_pollfd_t *fds,
mw_uint_t nfds,
int timeout_)
{
mw_poll_type_t *type = (mw_poll_type_t *)MW_TYPE(self);
return type->poll(self, fds, nfds, timeout_);
}
#endif
|