mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-11 13:24:43 -04:00
Limit the maximum number of events on each socket to 65535
This lets us use less RAM for the evmap_io structure, which in turn can let us have fewer cache misses for evmap operations.
This commit is contained in:
parent
99210dd9e0
commit
819f949f4a
13
evmap.c
13
evmap.c
@ -56,8 +56,8 @@
|
|||||||
*/
|
*/
|
||||||
struct evmap_io {
|
struct evmap_io {
|
||||||
struct event_list events;
|
struct event_list events;
|
||||||
unsigned int nread;
|
ev_uint16_t nread;
|
||||||
unsigned int nwrite;
|
ev_uint16_t nwrite;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* An entry for an evmap_signal list: notes all the events that want to know
|
/* An entry for an evmap_signal list: notes all the events that want to know
|
||||||
@ -295,6 +295,11 @@ evmap_io_add(struct event_base *base, evutil_socket_t fd, struct event *ev)
|
|||||||
if (++nwrite == 1)
|
if (++nwrite == 1)
|
||||||
res |= EV_WRITE;
|
res |= EV_WRITE;
|
||||||
}
|
}
|
||||||
|
if (EVUTIL_UNLIKELY(nread > 0xffff || nwrite > 0xffff)) {
|
||||||
|
event_warnx("Too many events reading or writing on fd %d",
|
||||||
|
(int)fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
void *extra = ((char*)ctx) + sizeof(struct evmap_io);
|
void *extra = ((char*)ctx) + sizeof(struct evmap_io);
|
||||||
@ -307,8 +312,8 @@ evmap_io_add(struct event_base *base, evutil_socket_t fd, struct event *ev)
|
|||||||
retval = 1;
|
retval = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->nread = nread;
|
ctx->nread = (ev_uint16_t) nread;
|
||||||
ctx->nwrite = nwrite;
|
ctx->nwrite = (ev_uint16_t) nwrite;
|
||||||
TAILQ_INSERT_TAIL(&ctx->events, ev, ev_io_next);
|
TAILQ_INSERT_TAIL(&ctx->events, ev, ev_io_next);
|
||||||
|
|
||||||
return (retval);
|
return (retval);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user