summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuo Jinghua <sunmoon1997@gmail.com>2009-10-31 20:15:09 +0800
committerLuo Jinghua <sunmoon1997@gmail.com>2009-10-31 20:15:09 +0800
commit74e3ae685ed561d328f89b3a33f53fc9df81d289 (patch)
treeb07551dd9400a6400d733317c2e2477dcddbdd75
parent36d3e546e459efe2694e8f382e884e721d94c794 (diff)
milkway: mw-poll really works now
-rw-r--r--milkway/mw-poll-select.c13
-rw-r--r--milkway/mw-poll-sys.c17
-rw-r--r--milkway/mw-poll-win32.c9
-rw-r--r--milkway/mw-poll.c2
-rw-r--r--milkway/mw-poll.h2
-rw-r--r--milkway/test/poll-test.c24
6 files changed, 33 insertions, 34 deletions
diff --git a/milkway/mw-poll-select.c b/milkway/mw-poll-select.c
index b724977..fceb754 100644
--- a/milkway/mw-poll-select.c
+++ b/milkway/mw-poll-select.c
@@ -76,13 +76,16 @@ mw_poll_select_poll(mw_poll_t *super,
mw_uint_t nfds,
int timeout)
{
- mw_poll_select_t *self = (mw_poll_select_t*)super;
+ /* mw_poll_select_t *self = (mw_poll_select_t*)super; */
struct timeval tv;
SELECT_MASK rset, wset, xset;
mw_pollfd_t *f;
int ready;
int maxfd = 0;
+ if (!nfds)
+ return MW_FALSE;
+
FD_ZERO (&rset);
FD_ZERO (&wset);
FD_ZERO (&xset);
@@ -118,16 +121,14 @@ mw_poll_select_poll(mw_poll_t *super,
}
}
- return MW_FALSE;
+ return ready;
}
static void
mw_poll_select_finalize(mw_object_t *super)
{
- mw_poll_select_t *self = (mw_poll_select_t*)super;
-
-
- MW_SUPER_TYPE_BASE(super, MW_POLL_SELECT_TYPE)->finalize(super);
+ /* mw_poll_select_t *self = (mw_poll_select_t*)super; */
+ MW_SUPER_FINALIZE(super, MW_POLL_SELECT_TYPE)(super);
}
static void
diff --git a/milkway/mw-poll-sys.c b/milkway/mw-poll-sys.c
index 9cc350e..84b8a62 100644
--- a/milkway/mw-poll-sys.c
+++ b/milkway/mw-poll-sys.c
@@ -107,7 +107,7 @@ poll_event_from_system_event(unsigned short e)
return r;
}
-static mw_bool_t
+static int
mw_poll_sys_poll(mw_poll_t *super,
mw_pollfd_t *fds,
mw_uint_t nfds,
@@ -116,9 +116,10 @@ mw_poll_sys_poll(mw_poll_t *super,
mw_poll_sys_t *self = (mw_poll_sys_t*)super;
mw_uint_t i;
int ret;
+ struct pollfd *fd;
- if (nfds)
- return MW_FALSE;
+ if (!nfds)
+ return 0;
mw_array_set_size(self->array, nfds);
for (i = 0; i < nfds; i++) {
@@ -128,16 +129,16 @@ mw_poll_sys_poll(mw_poll_t *super,
fd->revents = 0;
}
- ret = poll (&mw_array_index(self->array, struct pollfd, 0),
- nfds, timeout);
- if (!ret || ret == 0)
- return MW_FALSE;
+ fd = &mw_array_index(self->array, struct pollfd, 0);
+ ret = poll (fd, nfds, timeout);
+ if (ret <= 0)
+ return ret;
for (i = 0; i < nfds; i++) {
struct pollfd *fd = &mw_array_index(self->array, struct pollfd, i);
fds[i].revents = poll_event_from_system_event(fd->revents);
}
- return MW_TRUE;
+ return ret;
}
static void
diff --git a/milkway/mw-poll-win32.c b/milkway/mw-poll-win32.c
index 730cd00..81d2ef2 100644
--- a/milkway/mw-poll-win32.c
+++ b/milkway/mw-poll-win32.c
@@ -45,7 +45,7 @@ mw_poll_win32_new(void)
return (mw_poll_t*)mw_poll_win32_init(self, MW_POLL_WIN32_TYPE);
}
-static mw_bool_t
+static int
mw_poll_win32_poll(mw_poll_t *super,
mw_pollfd_t *fds;
mw_uint_t nfds;
@@ -53,16 +53,13 @@ mw_poll_win32_poll(mw_poll_t *super,
{
mw_poll_win32_t *self = (mw_poll_win32_t*)super;
- return MW_FALSE;
+ return 0;
}
static void
mw_poll_win32_finalize(mw_object_t *super)
{
- mw_poll_win32_t *self = (mw_poll_win32_t*)super;
-
-
- MW_SUPER_TYPE_BASE(super, MW_POLL_WIN32_TYPE)->finalize(super);
+ MW_SUPER_FINALIZE(super, MW_POLL_WIN32_TYPE);
}
static void
diff --git a/milkway/mw-poll.c b/milkway/mw-poll.c
index bba8dc7..edd8322 100644
--- a/milkway/mw-poll.c
+++ b/milkway/mw-poll.c
@@ -33,8 +33,6 @@ static void
mw_poll_finalize(mw_object_t *super)
{
mw_poll_t *self = (mw_poll_t*)super;
-
- mw_object_unref(self->fds);
MW_SUPER_FINALIZE(self, MW_POLL_TYPE)(super);
}
diff --git a/milkway/mw-poll.h b/milkway/mw-poll.h
index 5d84269..2365ed0 100644
--- a/milkway/mw-poll.h
+++ b/milkway/mw-poll.h
@@ -69,7 +69,7 @@ mw_poll_get_type(void);
mw_public mw_poll_t*
mw_poll_init(mw_poll_t *self);
-static mw_inline mw_bool_t
+static mw_inline int
mw_poll_poll(mw_poll_t *self,
mw_pollfd_t *fds,
mw_uint_t nfds,
diff --git a/milkway/test/poll-test.c b/milkway/test/poll-test.c
index d11af35..92bea57 100644
--- a/milkway/test/poll-test.c
+++ b/milkway/test/poll-test.c
@@ -30,23 +30,25 @@ static void
test_poll(void)
{
mw_poll_t *p;
- mw_pollfd_t fd;
+ mw_pollfd_t fd[2];
+ mw_int_t ret;
p = mw_poll_imp_new(NULL);
mw_unless(p != NULL);
- fd.fd = 0;
- fd.events = MW_IO_IN;
- mw_unless(mw_poll_add_fd(p, &fd, 0));
- mw_unless(mw_poll_add_fd(p, &fd, 0) == MW_FALSE);
+ printf ("poll imp: %s\n", MW_TYPE(p)->name);
- fd.fd = 1;
- fd.events = MW_IO_OUT;
- mw_unless(mw_poll_add_fd(p, &fd, 0));
-
- mw_unless(mw_poll_remove_fd(p, 0, 0));
- mw_unless(mw_poll_remove_fd(p, 1, 0));
+ fd[0].fd = 1;
+ fd[0].events = MW_IO_IN;
+ fd[1].fd = 0;
+ fd[1].events = MW_IO_OUT;
+ ret = mw_poll_poll (p, fd, 1, 2000);
+ if (ret > 0)
+ mw_unless(fd[0].revents != 0);
+ mw_poll_poll (p, fd, 2, 1000);
+ if (ret > 0)
+ mw_unless(fd[0].revents != 0 || fd[1].revents != 0);
mw_object_unref(p);
}