Commit 77070cb16ed26705bd24d3d2588efb3db757a072

Authored by Georg Hopp
1 parent 67dee273

check firt if we have events at all

Showing 1 changed file with 25 additions and 23 deletions
... ... @@ -82,37 +82,39 @@ TR_commManagerPollSelect(void * _this, TR_Event event, int timeout)
82 82
83 83 nevents = poll(this->fds, cmgr->n_endpoints, timeout);
84 84
85   - for (i = 0; i < cmgr->n_endpoints; i++) {
86   - TR_CommEndPoint endpoint = cmgr->endpoints[i];
  85 + if (nevents) {
  86 + for (i = 0; i < cmgr->n_endpoints; i++) {
  87 + TR_CommEndPoint endpoint = cmgr->endpoints[i];
  88 +
  89 + if ((this->fds[i].revents & POLLIN) == POLLIN) {
  90 + nevents--;
  91 + if (TR_INSTANCE_OF(TR_TcpSocket, endpoint->transport)
  92 + && ((TR_TcpSocket)endpoint->transport)->listen) {
  93 + TR_eventHandlerIssueEvent(
  94 + (TR_EventHandler)this,
  95 + (TR_EventSubject)endpoint,
  96 + TR_CET_EVENT_ACC_READY,
  97 + NULL);
  98 + } else {
  99 + TR_eventHandlerIssueEvent(
  100 + (TR_EventHandler)this,
  101 + (TR_EventSubject)endpoint,
  102 + TR_CEP_EVENT_READ_READY,
  103 + NULL);
  104 + }
  105 + }
87 106
88   - if ((this->fds[i].revents & POLLIN) == POLLIN) {
89   - nevents--;
90   - if (TR_INSTANCE_OF(TR_TcpSocket, endpoint->transport)
91   - && ((TR_TcpSocket)endpoint->transport)->listen) {
92   - TR_eventHandlerIssueEvent(
93   - (TR_EventHandler)this,
94   - (TR_EventSubject)endpoint,
95   - TR_CET_EVENT_ACC_READY,
96   - NULL);
97   - } else {
  107 + if ((this->fds[i].revents & POLLOUT) == POLLOUT) {
  108 + nevents--;
98 109 TR_eventHandlerIssueEvent(
99 110 (TR_EventHandler)this,
100 111 (TR_EventSubject)endpoint,
101   - TR_CEP_EVENT_READ_READY,
  112 + TR_CEP_EVENT_WRITE_READY,
102 113 NULL);
103 114 }
104   - }
105 115
106   - if ((this->fds[i].revents & POLLOUT) == POLLOUT) {
107   - nevents--;
108   - TR_eventHandlerIssueEvent(
109   - (TR_EventHandler)this,
110   - (TR_EventSubject)endpoint,
111   - TR_CEP_EVENT_WRITE_READY,
112   - NULL);
  116 + if (nevents <= 0) break;
113 117 }
114   -
115   - if (nevents <= 0) break;
116 118 }
117 119 }
118 120
... ...
Please register or login to post a comment