Coding style change

This commit is contained in:
Nils O. Selåsdal
2012-12-05 18:53:58 +01:00
parent d9c8b2b48a
commit 16e1ac52ec
32 changed files with 236 additions and 234 deletions
+21 -21
View File
@@ -29,10 +29,10 @@ static inline uint32_t mux_2_epoll_events(unsigned int events)
{
uint32_t epoll_events = 0;
if(events & MUX_EV_READ)
if (events & MUX_EV_READ)
epoll_events |= EPOLLIN;
if(events & MUX_EV_WRITE)
if (events & MUX_EV_WRITE)
epoll_events |= EPOLLOUT;
return epoll_events;
@@ -44,10 +44,10 @@ static inline unsigned int epoll_2_mux_events(uint32_t events)
//epoll always waits for EPOLLHUP and EPOLLERR , we map
//those to read events which will hopefully do the right thing
if(events & (EPOLLIN | EPOLLHUP | EPOLLERR))
if (events & (EPOLLIN | EPOLLHUP | EPOLLERR))
mux_events |= MUX_EV_READ;
if(events & EPOLLOUT)
if (events & EPOLLOUT)
mux_events |= MUX_EV_WRITE;
return mux_events;
@@ -65,7 +65,7 @@ static int iomux_epoll_update_events(struct IOMux *mux_, struct IOMuxFD *fd)
//in order to try to "pause" reading can lead to missing or false
//read events.
assert(fd->what != 0);
if(fd->what == 0)
if (fd->what == 0)
return EINVAL;
@@ -74,7 +74,7 @@ static int iomux_epoll_update_events(struct IOMux *mux_, struct IOMuxFD *fd)
rc = epoll_ctl(mux->epoll_fd, EPOLL_CTL_MOD, fd->fd, &e_event);
assert(rc == 0);
if(rc != 0)
if (rc != 0)
return errno;
return 0;
@@ -86,7 +86,7 @@ static int iomux_epoll_register_fd(struct IOMux *mux_, struct IOMuxFD *fd)
struct epoll_event e_event = {0, {0}};
int rc;
if(fd->what == 0 || fd->callback == NULL)
if (fd->what == 0 || fd->callback == NULL)
return EINVAL;
e_event.events = mux_2_epoll_events(fd->what);
@@ -94,7 +94,7 @@ static int iomux_epoll_register_fd(struct IOMux *mux_, struct IOMuxFD *fd)
rc = epoll_ctl(mux->epoll_fd, EPOLL_CTL_ADD, fd->fd, &e_event);
assert(rc == 0);
if(rc != 0) {
if (rc != 0) {
return errno;
}
@@ -111,18 +111,18 @@ static int iomux_epoll_unregister_fd(struct IOMux *mux_, struct IOMuxFD *fd)
rc = epoll_ctl(mux->epoll_fd, EPOLL_CTL_DEL, fd->fd, &e_event);
assert(rc == 0);
if(rc != 0)
if (rc != 0)
return errno;
//if the fd is pending, remove it from pending_events
//This ensures that it's safe to unregister a descriptor
//that is currently pending a callback
for(i = 0; i < mux->pending; i++) {
for (i = 0; i < mux->pending; i++) {
struct IOMuxFD *fdi = mux->pending_events[i].data.ptr;
if(fdi == NULL)
if (fdi == NULL)
continue;
if(fd == fdi) {
if (fd == fdi) {
mux->pending_events[i].data.ptr = NULL;
break;
}
@@ -149,17 +149,17 @@ static int iomux_epoll_run(struct IOMux *mux_, struct timeval *timeout)
int timeout_ms;
int event_cnt;
if(mux->num_descriptors == 0 && timeout == NULL)
if (mux->num_descriptors == 0 && timeout == NULL)
return 0;
//epoll takes the timeout in miliseconds
if(timeout)
if (timeout)
timeout_ms = timeval_to_ms(timeout);
else
timeout_ms = -1;
again:
rc = epoll_wait(mux->epoll_fd, mux->pending_events, EPOLL_WAIT_EVENTS, timeout_ms);
if(rc == -1 && errno == EINTR)
if (rc == -1 && errno == EINTR)
goto again;
assert(rc >= 0);
@@ -170,12 +170,12 @@ again:
event_cnt = iomux_timers_run(mux_); //process timers
if(rc == 0) //Just the timeout
if (rc == 0) //Just the timeout
return event_cnt;
for(i = 0; i < rc; i++) {
for (i = 0; i < rc; i++) {
struct IOMuxFD *fd = mux->pending_events[i].data.ptr;
if(fd != NULL) { //calling _unregister from a callback could have removed it
if (fd != NULL) { //calling _unregister from a callback could have removed it
unsigned int events;
events = epoll_2_mux_events(mux->pending_events[i].events);
@@ -195,7 +195,7 @@ again:
static void iomux_epoll_delete(struct IOMux *mux)
{
assert(mux != NULL && mux->instance != NULL);
if(mux != NULL && mux->instance != NULL) {
if (mux != NULL && mux->instance != NULL) {
struct IOMuxEpoll *mux_epoll = mux->instance;
close(mux_epoll->epoll_fd);
free(mux_epoll);
@@ -206,11 +206,11 @@ static void iomux_epoll_delete(struct IOMux *mux)
int iomux_epoll_init(struct IOMux *mux)
{
struct IOMuxEpoll *mux_epoll = calloc(1, sizeof *mux_epoll);
if(mux_epoll == NULL)
if (mux_epoll == NULL)
return ENOMEM;
mux_epoll->epoll_fd = epoll_create(128);
if(mux_epoll->epoll_fd == -1) {
if (mux_epoll->epoll_fd == -1) {
free(mux_epoll);
return errno;
}