summaryrefslogtreecommitdiff
path: root/evport.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-09-15 18:45:57 +0000
committerNick Mathewson <nickm@torproject.org>2007-09-15 18:45:57 +0000
commitbfd27f58da9d5fba6e2ed0c0d4f436fa240dbc47 (patch)
tree046fd59d18f6b849097e330c04800c92c0d57dc0 /evport.c
parentb835ee085f537aa6a45df865930626688e984009 (diff)
downloadlibevent-bfd27f58da9d5fba6e2ed0c0d4f436fa240dbc47.tar.gz
r15086@catbus: nickm | 2007-09-15 14:42:55 -0400
Patch from Trond Norbye: Fix two solaris bugs. svn:r432
Diffstat (limited to 'evport.c')
-rw-r--r--evport.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/evport.c b/evport.c
index 7d6f2d26..8bb3c8cf 100644
--- a/evport.c
+++ b/evport.c
@@ -240,8 +240,10 @@ static int
grow(struct evport_data *epdp, int factor)
{
struct fd_info *tmp;
+ struct fd_info *old = epdp->ed_fds;
int oldsize = epdp->ed_nevents;
int newsize = factor * oldsize;
+ int ii;
assert(factor > 1);
check_evportop(epdp);
@@ -252,6 +254,15 @@ grow(struct evport_data *epdp, int factor)
epdp->ed_fds = tmp;
memset((char*) (epdp->ed_fds + oldsize), 0,
(newsize - oldsize)*sizeof(struct fd_info));
+
+ /* The ev_pending array contains pointers into the released array. */
+ for (ii = 0; ii < EVENTS_PER_GETN; ++ii) {
+ if (epdp->ed_pending[ii] != 0) {
+ int offset = epdp->ed_pending[ii] - old;
+ epdp->ed_pending[ii] = epdp->ed_fds + offset;
+ }
+ }
+
epdp->ed_nevents = newsize;
check_evportop(epdp);
@@ -309,9 +320,16 @@ evport_dispatch(struct event_base *base, void *arg, struct timeval *tv)
/*
* We have to convert a struct timeval to a struct timespec
- * (only difference is nanoseconds vs. microseconds)
+ * (only difference is nanoseconds vs. microseconds). If no time-based
+ * events are active, we should wait for I/O (and tv == NULL).
*/
- struct timespec ts = {tv->tv_sec, tv->tv_usec * 1000};
+ struct timespec ts;
+ struct timespec *ts_p = NULL;
+ if (tv != NULL) {
+ ts.tv_sec = tv->tv_sec;
+ ts.tv_nsec = tv->tv_usec * 1000;
+ ts_p = &ts;
+ }
/*
* Before doing anything else, we need to reassociate the events we hit
@@ -330,7 +348,7 @@ evport_dispatch(struct event_base *base, void *arg, struct timeval *tv)
}
if ((res = port_getn(epdp->ed_port, pevtlist, EVENTS_PER_GETN,
- (unsigned int *) &nevents, &ts)) == -1) {
+ (unsigned int *) &nevents, ts_p)) == -1) {
if (errno == EINTR) {
evsignal_process(base);
return (0);