Browse Source

add max handle to limit the amount of handles to check.

1.0.0
Georg Hopp 12 years ago
parent
commit
7c8fcd3b9b
  1. 1
      include/tr/comm_manager.h
  2. 4
      src/comm_manager_poll.c
  3. 8
      src/i_comm_manager.c

1
include/tr/comm_manager.h

@ -36,6 +36,7 @@ TR_CLASS(TR_CommManager) {
TR_CommEndPoint * endpoints;
nfds_t n_endpoints;
nfds_t max_handle;
};
TR_INSTANCE_INIT(TR_CommManager);
TR_CLASSVARS_DECL(TR_CommManager) {

4
src/comm_manager_poll.c

@ -80,10 +80,10 @@ TR_commManagerPollSelect(void * _this, TR_Event event, int timeout)
nfds_t i;
int nevents;
nevents = poll(this->fds, cmgr->n_endpoints, timeout);
nevents = poll(this->fds, cmgr->max_handle+1, timeout);
if (nevents) {
for (i = 0; i < cmgr->n_endpoints; i++) {
for (i = 0; i < cmgr->max_handle+1; i++) {
TR_CommEndPoint endpoint = cmgr->endpoints[i];
if ((this->fds[i].revents & POLLIN) == POLLIN) {

8
src/i_comm_manager.c

@ -43,6 +43,10 @@ TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint)
TR_delete(this->endpoints[endpoint->transport->handle]);
}
this->max_handle = endpoint->transport->handle > this->max_handle
? endpoint->transport->handle
: this->max_handle;
this->endpoints[endpoint->transport->handle] = endpoint;
TR_CALL(_this, TR_CommManager, addEndpoint, endpoint);
}
@ -102,6 +106,10 @@ TR_commManagerClose(void * _this, TR_Event event)
TR_socketShutdown(endpoint->transport);
TR_CALL(_this, TR_CommManager, close, event);
if (endpoint->transport->handle == this->max_handle) {
while (! this->endpoints[--this->max_handle]);
}
TR_delete(this->endpoints[endpoint->transport->handle]);
return TR_EVENT_DONE;

Loading…
Cancel
Save