Commit 7c8fcd3b9b8a3aec9ee2389c8e89837d2a742f80

Authored by Georg Hopp
1 parent 9e7b137d

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

... ... @@ -36,6 +36,7 @@ TR_CLASS(TR_CommManager) {
36 36
37 37 TR_CommEndPoint * endpoints;
38 38 nfds_t n_endpoints;
  39 + nfds_t max_handle;
39 40 };
40 41 TR_INSTANCE_INIT(TR_CommManager);
41 42 TR_CLASSVARS_DECL(TR_CommManager) {
... ...
... ... @@ -80,10 +80,10 @@ TR_commManagerPollSelect(void * _this, TR_Event event, int timeout)
80 80 nfds_t i;
81 81 int nevents;
82 82
83   - nevents = poll(this->fds, cmgr->n_endpoints, timeout);
  83 + nevents = poll(this->fds, cmgr->max_handle+1, timeout);
84 84
85 85 if (nevents) {
86   - for (i = 0; i < cmgr->n_endpoints; i++) {
  86 + for (i = 0; i < cmgr->max_handle+1; i++) {
87 87 TR_CommEndPoint endpoint = cmgr->endpoints[i];
88 88
89 89 if ((this->fds[i].revents & POLLIN) == POLLIN) {
... ...
... ... @@ -43,6 +43,10 @@ TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint)
43 43 TR_delete(this->endpoints[endpoint->transport->handle]);
44 44 }
45 45
  46 + this->max_handle = endpoint->transport->handle > this->max_handle
  47 + ? endpoint->transport->handle
  48 + : this->max_handle;
  49 +
46 50 this->endpoints[endpoint->transport->handle] = endpoint;
47 51 TR_CALL(_this, TR_CommManager, addEndpoint, endpoint);
48 52 }
... ... @@ -102,6 +106,10 @@ TR_commManagerClose(void * _this, TR_Event event)
102 106
103 107 TR_socketShutdown(endpoint->transport);
104 108 TR_CALL(_this, TR_CommManager, close, event);
  109 +
  110 + if (endpoint->transport->handle == this->max_handle) {
  111 + while (! this->endpoints[--this->max_handle]);
  112 + }
105 113 TR_delete(this->endpoints[endpoint->transport->handle]);
106 114
107 115 return TR_EVENT_DONE;
... ...
Please register or login to post a comment