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