diff options
Diffstat (limited to 'src/base/checkFront.c')
| -rw-r--r-- | src/base/checkFront.c | 160 |
1 files changed, 84 insertions, 76 deletions
diff --git a/src/base/checkFront.c b/src/base/checkFront.c index 536de1b..dfe11eb 100644 --- a/src/base/checkFront.c +++ b/src/base/checkFront.c @@ -13,101 +13,109 @@ typedef struct struct_checkfront_t { - char *msg; - my_time_t time; - int id; - int count; - int type; + char *msg; + my_time_t time; + int id; + int count; + int type; } checkfront_t; -static checkfront_t* newCheck(char *s, int type, int id) +static checkfront_t * +newCheck(char *s, int type, int id) { - checkfront_t *new; - - assert( s != NULL ); - new = malloc( sizeof(checkfront_t) ); - memset(new, 0, sizeof(checkfront_t)); - new->msg = strdup(s); - new->time = getMyTime(); - new->id = id; - new->type = type; - new->count = 0; - return new; + checkfront_t *new; + + assert(s != NULL); + new = malloc(sizeof(checkfront_t)); + memset(new, 0, sizeof(checkfront_t)); + new->msg = strdup(s); + new->time = getMyTime(); + new->id = id; + new->type = type; + new->count = 0; + return new; } -static void destroyCheck(checkfront_t *p) +static void +destroyCheck(checkfront_t * p) { - assert( p != NULL ); - free(p->msg); - free(p); + assert(p != NULL); + free(p->msg); + free(p); } -list_t* newCheckFront() +list_t * +newCheckFront() { - return newList(); + return newList(); } -void addMsgInCheckFront(list_t *list, char *msg, int type, int id) +void +addMsgInCheckFront(list_t * list, char *msg, int type, int id) { - if (type == CHECK_FRONT_TYPE_CHECK) - incID(id); - addList(list, newCheck(msg, type, id) ); + if (type == CHECK_FRONT_TYPE_CHECK) + incID(id); + addList(list, newCheck(msg, type, id)); } -void eventMsgInCheckFront(client_t *client) +void +eventMsgInCheckFront(client_t * client) { - my_time_t currentTime; - int i; - - currentTime = getMyTime(); - for (i = 0; i < client->listSendMsg->count; i++) { - checkfront_t *this; - - this = (checkfront_t *)client->listSendMsg->list[i]; - switch (this->type) { - case CHECK_FRONT_TYPE_SIMPLE : - sendClient(client, this->msg); - delListItem(client->listSendMsg, i, destroyCheck); - i--; - break; - case CHECK_FRONT_TYPE_CHECK : - if (this->count == 0 || currentTime - this->time > CHECK_FRONT_SEND_TIME_INTERVAL) { - sendClient(client, this->msg); - this->time = currentTime; - this->count++; - } - if (this->count > CHECK_FRONT_MAX_COUNT_SEND) { - delID(this->id); - delListItem(client->listSendMsg, i, destroyCheck); - i--; - } - break; - default : - assert(! _("Bad type of front!")); - break; - } - } + my_time_t currentTime; + int i; + + currentTime = getMyTime(); + for (i = 0; i < client->listSendMsg->count; i++) { + checkfront_t *this; + + this = (checkfront_t *) client->listSendMsg->list[i]; + switch (this->type) { + case CHECK_FRONT_TYPE_SIMPLE: + sendClient(client, this->msg); + delListItem(client->listSendMsg, i, destroyCheck); + i--; + break; + case CHECK_FRONT_TYPE_CHECK: + if (this->count == 0 + || currentTime - this->time > + CHECK_FRONT_SEND_TIME_INTERVAL) { + sendClient(client, this->msg); + this->time = currentTime; + this->count++; + } + if (this->count > CHECK_FRONT_MAX_COUNT_SEND) { + delID(this->id); + delListItem(client->listSendMsg, i, destroyCheck); + i--; + } + break; + default: + assert(!_("Bad type of front!")); + break; + } + } } -void delMsgInCheckFront(list_t *listCheckFront, int id) +void +delMsgInCheckFront(list_t * listCheckFront, int id) { - int i; - - for (i = 0 ; i < listCheckFront->count ; i++ ) { - checkfront_t *this; - - this = (checkfront_t *)listCheckFront->list[i]; - if (this->id == id) { - delID(this->id); - delListItem(listCheckFront, i, destroyCheck); - return; - } - } + int i; + + for (i = 0; i < listCheckFront->count; i++) { + checkfront_t *this; + + this = (checkfront_t *) listCheckFront->list[i]; + if (this->id == id) { + delID(this->id); + delListItem(listCheckFront, i, destroyCheck); + return; + } + } } -void destroyCheckFront(list_t *p) +void +destroyCheckFront(list_t * p) { - assert( p != NULL ); - destroyListItem(p, destroyCheck); + assert(p != NULL); + destroyListItem(p, destroyCheck); } - |