[core] fdevent uses uint32_t instead of size_t

personal/stbuehler/ci-build
Glenn Strauss 3 years ago
parent d5fd52ee86
commit 3cd74a16a2
  1. 25
      src/fdevent.c
  2. 10
      src/fdevent_impl.h
  3. 6
      src/fdevent_poll.c
  4. 2
      src/fdevent_select.c

@ -77,7 +77,7 @@ int fdevent_config(server *srv) {
* User override
*/
for (size_t i = 0; event_handlers[i].name; i++) {
for (uint32_t i = 0; event_handlers[i].name; ++i) {
if (0 == strcmp(event_handlers[i].name, srv->srvconf.event_handler)) {
srv->event_handler = event_handlers[i].et;
break;
@ -153,7 +153,7 @@ const char * fdevent_show_event_handlers(void) {
fdevents *fdevent_init(server *srv) {
fdevents *ev;
int type = srv->event_handler;
size_t maxfds;
uint32_t maxfds;
#ifdef SOCK_CLOEXEC
/* Test if SOCK_CLOEXEC is supported by kernel.
@ -194,7 +194,7 @@ fdevents *fdevent_init(server *srv) {
ev->fdarray = calloc(maxfds, sizeof(*ev->fdarray));
if (NULL == ev->fdarray) {
log_error(srv->errh, __FILE__, __LINE__,
"server.max-fds too large? (%zu)", maxfds-1);
"server.max-fds too large? (%u)", maxfds-1);
free(ev);
return NULL;
}
@ -252,12 +252,11 @@ fdevents *fdevent_init(server *srv) {
}
void fdevent_free(fdevents *ev) {
size_t i;
if (!ev) return;
if (ev->free) ev->free(ev);
for (i = 0; i < ev->maxfds; i++) {
for (uint32_t i = 0; i < ev->maxfds; ++i) {
/* (fdevent_sched_run() should already have been run,
* but take reasonable precautions anyway) */
if (ev->fdarray[i])
@ -802,8 +801,8 @@ typedef struct fdevent_cmd_pipe {
typedef struct fdevent_cmd_pipes {
fdevent_cmd_pipe *ptr;
size_t used;
size_t size;
uint32_t used;
uint32_t size;
} fdevent_cmd_pipes;
static fdevent_cmd_pipes cmd_pipes;
@ -848,7 +847,7 @@ static void fdevent_restart_logger_pipe(fdevent_cmd_pipe *fcp, time_t ts) {
void fdevent_restart_logger_pipes(time_t ts) {
for (size_t i = 0; i < cmd_pipes.used; ++i) {
for (uint32_t i = 0; i < cmd_pipes.used; ++i) {
fdevent_cmd_pipe * const fcp = cmd_pipes.ptr+i;
if (fcp->pid > 0) continue;
fdevent_restart_logger_pipe(fcp, ts);
@ -857,7 +856,7 @@ void fdevent_restart_logger_pipes(time_t ts) {
int fdevent_waitpid_logger_pipe_pid(pid_t pid, time_t ts) {
for (size_t i = 0; i < cmd_pipes.used; ++i) {
for (uint32_t i = 0; i < cmd_pipes.used; ++i) {
fdevent_cmd_pipe * const fcp = cmd_pipes.ptr+i;
if (pid != fcp->pid) continue;
fcp->pid = -1;
@ -869,7 +868,7 @@ int fdevent_waitpid_logger_pipe_pid(pid_t pid, time_t ts) {
void fdevent_clr_logger_pipe_pids(void) {
for (size_t i = 0; i < cmd_pipes.used; ++i) {
for (uint32_t i = 0; i < cmd_pipes.used; ++i) {
fdevent_cmd_pipe *fcp = cmd_pipes.ptr+i;
fcp->pid = -1;
}
@ -877,7 +876,7 @@ void fdevent_clr_logger_pipe_pids(void) {
int fdevent_reaped_logger_pipe(pid_t pid) {
for (size_t i = 0; i < cmd_pipes.used; ++i) {
for (uint32_t i = 0; i < cmd_pipes.used; ++i) {
fdevent_cmd_pipe *fcp = cmd_pipes.ptr+i;
if (fcp->pid == pid) {
time_t ts = time(NULL);
@ -897,7 +896,7 @@ int fdevent_reaped_logger_pipe(pid_t pid) {
void fdevent_close_logger_pipes(void) {
for (size_t i = 0; i < cmd_pipes.used; ++i) {
for (uint32_t i = 0; i < cmd_pipes.used; ++i) {
fdevent_cmd_pipe *fcp = cmd_pipes.ptr+i;
close(fcp->fds[0]);
if (fcp->fds[1] != STDERR_FILENO) close(fcp->fds[1]);
@ -910,7 +909,7 @@ void fdevent_close_logger_pipes(void) {
void fdevent_breakagelog_logger_pipe(int fd) {
for (size_t i = 0; i < cmd_pipes.used; ++i) {
for (uint32_t i = 0; i < cmd_pipes.used; ++i) {
fdevent_cmd_pipe *fcp = cmd_pipes.ptr+i;
if (fcp->fds[1] != fd) continue;
fcp->fds[1] = STDERR_FILENO;

@ -69,8 +69,8 @@ typedef enum {
typedef struct {
int *ptr;
size_t used;
size_t size;
uint32_t used;
uint32_t size;
} buffer_int;
#endif
@ -83,7 +83,7 @@ struct fdevents {
int (*poll)(struct fdevents *ev, int timeout_ms);
struct server *srv;
size_t maxfds;
uint32_t maxfds;
#ifdef FDEVENT_USE_LINUX_EPOLL
int epoll_fd;
struct epoll_event *epoll_events;
@ -106,8 +106,8 @@ struct fdevents {
#ifdef FDEVENT_USE_POLL
struct pollfd *pollfds;
size_t size;
size_t used;
uint32_t size;
uint32_t used;
buffer_int unused;
#endif

@ -26,7 +26,7 @@ static void fdevent_poll_free(fdevents *ev) {
static int fdevent_poll_event_del(fdevents *ev, fdnode *fdn) {
int fd = fdn->fd;
int k = fdn->fde_ndx;
if ((size_t)k >= ev->used || ev->pollfds[k].fd != fd) return (errno = EINVAL, -1);
if ((uint32_t)k >= ev->used || ev->pollfds[k].fd != fd) return (errno = EINVAL, -1);
ev->pollfds[k].fd = -1;
/* ev->pollfds[k].events = 0; */
@ -52,7 +52,7 @@ static int fdevent_poll_event_set(fdevents *ev, fdnode *fdn, int events) {
#endif
if (k >= 0) {
if ((size_t)k >= ev->used || ev->pollfds[k].fd != fd) return (errno = EINVAL, -1);
if ((uint32_t)k >= ev->used || ev->pollfds[k].fd != fd) return (errno = EINVAL, -1);
ev->pollfds[k].events = events;
return 0;
}
@ -78,7 +78,7 @@ static int fdevent_poll_event_set(fdevents *ev, fdnode *fdn, int events) {
}
static int fdevent_poll_next_ndx(const fdevents *ev, int ndx) {
for (size_t i = (size_t)(ndx+1); i < ev->used; ++i) {
for (uint32_t i = (uint32_t)(ndx+1); i < ev->used; ++i) {
if (ev->pollfds[i].revents) return i;
}
return -1;

@ -52,7 +52,7 @@ static int fdevent_select_event_set(fdevents *ev, fdnode *fdn, int events) {
return 0;
}
static int fdevent_select_event_get_revent(const fdevents *ev, size_t ndx) {
static int fdevent_select_event_get_revent(const fdevents *ev, int ndx) {
int revents = 0;
if (FD_ISSET(ndx, &ev->select_read)) revents |= FDEVENT_IN;
if (FD_ISSET(ndx, &ev->select_write)) revents |= FDEVENT_OUT;

Loading…
Cancel
Save