mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-11 13:24:43 -04:00
Merge remote-tracking branch 'origin/patches-2.0'
This commit is contained in:
commit
71349d080b
22
select.c
22
select.c
@ -51,17 +51,22 @@
|
|||||||
#include "log-internal.h"
|
#include "log-internal.h"
|
||||||
#include "evmap-internal.h"
|
#include "evmap-internal.h"
|
||||||
|
|
||||||
#ifndef howmany
|
|
||||||
#define howmany(x, y) (((x)+((y)-1))/(y))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _EVENT_HAVE_FD_MASK
|
#ifndef _EVENT_HAVE_FD_MASK
|
||||||
/* This type is mandatory, but Android doesn't define it. */
|
/* This type is mandatory, but Android doesn't define it. */
|
||||||
#undef NFDBITS
|
|
||||||
#define NFDBITS (sizeof(long)*8)
|
|
||||||
typedef unsigned long fd_mask;
|
typedef unsigned long fd_mask;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NFDBITS
|
||||||
|
#define NFDBITS (sizeof(fd_mask)*8)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Divide positive x by y, rounding up. */
|
||||||
|
#define DIV_ROUNDUP(x, y) (((x)+((y)-1))/(y))
|
||||||
|
|
||||||
|
/* How many bytes to allocate for N fds? */
|
||||||
|
#define SELECT_ALLOC_SIZE(n) \
|
||||||
|
(DIV_ROUNDUP(n, NFDBITS) * sizeof(fd_mask))
|
||||||
|
|
||||||
struct selectop {
|
struct selectop {
|
||||||
int event_fds; /* Highest fd in fd set */
|
int event_fds; /* Highest fd in fd set */
|
||||||
int event_fdsz;
|
int event_fdsz;
|
||||||
@ -101,7 +106,7 @@ select_init(struct event_base *base)
|
|||||||
if (!(sop = mm_calloc(1, sizeof(struct selectop))))
|
if (!(sop = mm_calloc(1, sizeof(struct selectop))))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
if (select_resize(sop, howmany(32 + 1, NFDBITS)*sizeof(fd_mask))) {
|
if (select_resize(sop, SELECT_ALLOC_SIZE(32 + 1))) {
|
||||||
select_free_selectop(sop);
|
select_free_selectop(sop);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@ -254,8 +259,7 @@ select_add(struct event_base *base, int fd, short old, short events, void *p)
|
|||||||
/* In theory we should worry about overflow here. In
|
/* In theory we should worry about overflow here. In
|
||||||
* reality, though, the highest fd on a unixy system will
|
* reality, though, the highest fd on a unixy system will
|
||||||
* not overflow here. XXXX */
|
* not overflow here. XXXX */
|
||||||
while (fdsz <
|
while (fdsz < (int) SELECT_ALLOC_SIZE(fd + 1))
|
||||||
(int) (howmany(fd + 1, NFDBITS) * sizeof(fd_mask)))
|
|
||||||
fdsz *= 2;
|
fdsz *= 2;
|
||||||
|
|
||||||
if (fdsz != sop->event_fdsz) {
|
if (fdsz != sop->event_fdsz) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user