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
+23 -23
View File
@@ -28,7 +28,7 @@ static int iomux_select_grow(struct IOMuxSelect *mux)
{
void *tmp = realloc(mux->descriptors, (mux->num_descriptors + IOMUX_GROW_CHUNK) * sizeof *mux->descriptors);
assert(tmp != NULL);
if(tmp == NULL)
if (tmp == NULL)
return ENOMEM;
mux->alloc_descriptors += IOMUX_GROW_CHUNK;
@@ -39,7 +39,7 @@ static int iomux_select_grow(struct IOMuxSelect *mux)
static void iomux_select_remove(struct IOMuxSelect *mux, size_t idx)
{
if(mux->num_descriptors > 1) {
if (mux->num_descriptors > 1) {
//move last element into the empty slot
size_t last_idx = mux->num_descriptors - 1;
mux->descriptors[idx] = mux->descriptors[last_idx];
@@ -54,8 +54,8 @@ static void iomux_select_rebuild(struct IOMuxSelect *mux)
size_t i;
mux->max_fd = -1;
for(i = 0; i < mux->num_descriptors; ) {
if(mux->descriptors[i] == NULL) {
for (i = 0; i < mux->num_descriptors; ) {
if (mux->descriptors[i] == NULL) {
iomux_select_remove(mux, i);
//a deleted fd slot needs to be rechecked, no i++ here
} else {
@@ -70,12 +70,12 @@ static int iomux_select_update_events(struct IOMux *mux_, struct IOMuxFD *fd)
{
struct IOMuxSelect *mux = mux_->instance;
if(fd->what & MUX_EV_READ)
if (fd->what & MUX_EV_READ)
FD_SET(fd->fd, &mux->master_read_set);
else
FD_CLR(fd->fd, &mux->master_read_set);
if(fd->what & MUX_EV_WRITE)
if (fd->what & MUX_EV_WRITE)
FD_SET(fd->fd, &mux->master_write_set);
else
FD_CLR(fd->fd, &mux->master_write_set);
@@ -86,11 +86,11 @@ static int iomux_select_update_events(struct IOMux *mux_, struct IOMuxFD *fd)
static int iomux_select_register_fd(struct IOMux *mux_, struct IOMuxFD *fd)
{
struct IOMuxSelect *mux = mux_->instance;
if(fd->what == 0 || fd->callback == NULL)
if (fd->what == 0 || fd->callback == NULL)
return EINVAL;
if(mux->num_descriptors == mux->alloc_descriptors) {
if(iomux_select_grow(mux) != 0)
if (mux->num_descriptors == mux->alloc_descriptors) {
if (iomux_select_grow(mux) != 0)
return ENOMEM;
}
@@ -110,8 +110,8 @@ static int iomux_select_unregister_fd(struct IOMux *mux_, struct IOMuxFD *fd)
int rc = ENOENT;
size_t i;
for(i = 0; i < mux->num_descriptors; i++) {
if(fd == mux->descriptors[i]) {
for (i = 0; i < mux->num_descriptors; i++) {
if (fd == mux->descriptors[i]) {
unsigned int what = fd->what; //make sure we don't alter 'what' as seen from the user
fd->what &= ~MUX_EV_MASK;
iomux_select_update_events(mux_, fd);
@@ -136,46 +136,46 @@ static int iomux_select_run(struct IOMux *mux_, struct timeval *timeout)
fd_set read_set;
fd_set write_set;
if(mux->deleted_cnt) {
if (mux->deleted_cnt) {
iomux_select_rebuild(mux);
mux->deleted_cnt = 0;
}
if(mux->max_fd == -1 && timeout == NULL)
if (mux->max_fd == -1 && timeout == NULL)
return 0;
again:
read_set = mux->master_read_set;
write_set = mux->master_write_set;
rc = select(mux->max_fd + 1, &read_set, &write_set, NULL, timeout); //we can use timeout directly
if(rc == -1 && errno == EINTR)
if (rc == -1 && errno == EINTR)
goto again;
assert(rc >= 0);
if(rc < 0)
if (rc < 0)
return -1;
event_cnt = iomux_timers_run(mux_); //fire the timers
if(rc == 0) //Just the timeout
if (rc == 0) //Just the timeout
return event_cnt;
for(i = 0; rc >= 0 && i < mux->num_descriptors; i++) {
for (i = 0; rc >= 0 && i < mux->num_descriptors; i++) {
unsigned int events = 0;
if(mux->descriptors[i] == NULL) { //callback might have deleted it
if (mux->descriptors[i] == NULL) { //callback might have deleted it
continue;
}
if(FD_ISSET(mux->descriptors[i]->fd, &read_set)) {
if (FD_ISSET(mux->descriptors[i]->fd, &read_set)) {
events |= MUX_EV_READ;
}
if(FD_ISSET(mux->descriptors[i]->fd, &write_set)) {
if (FD_ISSET(mux->descriptors[i]->fd, &write_set)) {
events |= MUX_EV_WRITE;
}
if(events) {
if (events) {
assert(mux->descriptors[i]->callback != NULL);
mux->descriptors[i]->callback(mux_, mux->descriptors[i], events);
rc--;
@@ -188,7 +188,7 @@ again:
static void iomux_select_delete(struct IOMux *mux)
{
if(mux != NULL && mux->instance != NULL) {
if (mux != NULL && mux->instance != NULL) {
struct IOMuxSelect *mux_select = mux->instance;
free(mux_select->descriptors);
mux_select->descriptors = NULL;
@@ -200,7 +200,7 @@ static void iomux_select_delete(struct IOMux *mux)
int iomux_select_init(struct IOMux *mux)
{
struct IOMuxSelect *mux_select = calloc(1, sizeof *mux_select);
if(mux_select == NULL)
if (mux_select == NULL)
return ENOMEM;
mux_select->max_fd = -1;