Commit 7c8fcd3b9b8a3aec9ee2389c8e89837d2a742f80
1 parent
9e7b137d
add max handle to limit the amount of handles to check.
Showing
3 changed files
with
11 additions
and
2 deletions
| ... | ... | @@ -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