Selaa lähdekoodia

Bring in fixes from libevent trunk.

master
Richard Nyberg 18 vuotta sitten
vanhempi
commit
ba4efecb6d
2 muutettua tiedostoa jossa 40 lisäystä ja 15 poistoa
  1. +6
    -1
      libevent/event.c
  2. +34
    -14
      libevent/poll.c

+ 6
- 1
libevent/event.c Näytä tiedosto

@@ -459,6 +459,7 @@ event_once(int fd, short events,
{
struct event_once *eonce;
struct timeval etv;
int res;

/* We cannot support signals that just fire once */
if (events & EV_SIGNAL)
@@ -487,7 +488,11 @@ event_once(int fd, short events,
return (-1);
}

event_add(&eonce->ev, tv);
res = event_add(&eonce->ev, tv);
if (res != 0) {
free(eonce);
return (res);
}

return (0);
}


+ 34
- 14
libevent/poll.c Näytä tiedosto

@@ -234,29 +234,48 @@ poll_add(void *arg, struct event *ev)

poll_check_ok(pop);
if (pop->nfds + 1 >= pop->event_count) {
struct pollfd *tmp_event_set;
struct event **tmp_event_r_back;
struct event **tmp_event_w_back;
int tmp_event_count;

if (pop->event_count < 32)
pop->event_count = 32;
tmp_event_count = 32;
else
pop->event_count *= 2;
tmp_event_count = pop->event_count * 2;

/* We need more file descriptors */
pop->event_set = realloc(pop->event_set,
pop->event_count * sizeof(struct pollfd));
if (pop->event_set == NULL) {
tmp_event_set = realloc(pop->event_set,
tmp_event_count * sizeof(struct pollfd));
if (tmp_event_set == NULL) {
event_warn("realloc");
return (-1);
}
pop->event_r_back = realloc(pop->event_r_back,
pop->event_count * sizeof(struct event *));
pop->event_w_back = realloc(pop->event_w_back,
pop->event_count * sizeof(struct event *));
if (pop->event_r_back == NULL ||
pop->event_w_back == NULL) {
pop->event_set = tmp_event_set;
tmp_event_r_back = realloc(pop->event_r_back,
tmp_event_count * sizeof(struct event *));
if (tmp_event_r_back == NULL) {
/* event_set overallocated; that's okay. */
event_warn("realloc");
return (-1);
}
pop->event_r_back = tmp_event_r_back;

tmp_event_w_back = realloc(pop->event_w_back,
tmp_event_count * sizeof(struct event *));
if (tmp_event_w_back == NULL) {
/* event_set and event_r_back overallocated; that's
* okay. */
event_warn("realloc");
return (-1);
}
pop->event_w_back = tmp_event_w_back;

pop->event_count = tmp_event_count;
}
if (ev->ev_fd >= pop->fd_count) {
int *tmp_idxplus1_by_fd;
int new_count;
if (pop->fd_count < 32)
new_count = 32;
@@ -264,12 +283,13 @@ poll_add(void *arg, struct event *ev)
new_count = pop->fd_count * 2;
while (new_count <= ev->ev_fd)
new_count *= 2;
pop->idxplus1_by_fd =
realloc(pop->idxplus1_by_fd, new_count*sizeof(int));
if (pop->idxplus1_by_fd == NULL) {
tmp_idxplus1_by_fd =
realloc(pop->idxplus1_by_fd, new_count * sizeof(int));
if (tmp_idxplus1_by_fd == NULL) {
event_warn("realloc");
return (-1);
}
pop->idxplus1_by_fd = tmp_idxplus1_by_fd;
memset(pop->idxplus1_by_fd + pop->fd_count,
0, sizeof(int)*(new_count - pop->fd_count));
pop->fd_count = new_count;


Loading…
Peruuta
Tallenna