This is a huge waste of memory. Why not have an array per event which contains the connections that are awaiting the specific event?
For example, if your connections need to pass through 3 different events: (login protocol), (map-loading), (character information), you can have something as follows:
Code:
typedef struct {
long last_event; /* The last time, in milliseconds, an event was received from this connection. */
SOCKET s;
} event_con;
event_con login[20];
event_con map_loading[20];
event_con char_info[20];
Upon a new connection, you place them in the first event's array that is expected from them (in this case, the login protocol) and you specify their login time in the 'last_event' member in the 'event_con' struct. Then, you can revise them all on one single thread, with something as follows:
Code:
int i;
long crt_time = (long) time(NULL); /*Use the ctime header*/
for (i = 0; i < 20; i++) {
if ((login[i].last_event - crt_time) >= 5000) { /*Supposing the time limit is 5 secs*/
/*Do what you want here. Consider this a 'flag raised'.*/
}
if ((map_loading[i].last_event - crt_time) >= 5000) { /*Supposing the time limit is 5 secs*/
/*Do what you want here. Consider this a 'flag raised'.*/
}
if ((char_info[i].last_event - crt_time) >= 5000) { /*Supposing the time limit is 5 secs*/
/*Do what you want here. Consider this a 'flag raised'.*/
}
}
Something among those lines should increase your application's efficiency by far.