|
|
|
@ -21,14 +21,17 @@ |
|
|
|
*/ |
|
|
|
|
|
|
|
#include <unistd.h> |
|
|
|
#include <poll.h> |
|
|
|
|
|
|
|
#include "trbase.h" |
|
|
|
#include "trevent.h" |
|
|
|
|
|
|
|
#include "tr/comm_end_point.h" |
|
|
|
#include "tr/connection.h" |
|
|
|
#include "tr/comm_manager.h" |
|
|
|
#include "tr/comm_manager_poll.h" |
|
|
|
#include "tr/interface/comm_manager.h" |
|
|
|
#include "tr/comm_end_point.h" |
|
|
|
#include "tr/connection.h" |
|
|
|
#include "tr/connect_entry_point.h" |
|
|
|
|
|
|
|
static |
|
|
|
int |
|
|
|
@ -41,7 +44,9 @@ commManagerPollCtor(void * _this, va_list * params) |
|
|
|
TR_PARENTCALL(_this, TR_Class, ctor, params); |
|
|
|
this->fds = TR_malloc(sizeof(struct pollfd) * cmgr->n_endpoints); |
|
|
|
for (i = 0; i < cmgr->n_endpoints; i++) { |
|
|
|
this->fds[i] = {-1, 0, 0}; |
|
|
|
this->fds[i].fd = -1; |
|
|
|
this->fds[i].events = 0; |
|
|
|
this->fds[i].revents = 0; |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
@ -59,7 +64,7 @@ commManagerPollDtor(void * _this) |
|
|
|
|
|
|
|
static |
|
|
|
void |
|
|
|
TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint) |
|
|
|
TR_commManagerPollAddEndpoint(void * _this, TR_CommEndPoint endpoint) |
|
|
|
{ |
|
|
|
TR_CommManagerPoll this = _this; |
|
|
|
this->fds[endpoint->transport->handle].fd = endpoint->transport->handle; |
|
|
|
@ -68,7 +73,7 @@ TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint) |
|
|
|
|
|
|
|
static |
|
|
|
void |
|
|
|
TR_commManagerSelect(void * _this, TR_Event event, int timeout) |
|
|
|
TR_commManagerPollSelect(void * _this, TR_Event event, int timeout) |
|
|
|
{ |
|
|
|
TR_CommManagerPoll this = _this; |
|
|
|
TR_CommManager cmgr = _this; |
|
|
|
@ -77,33 +82,33 @@ TR_commManagerSelect(void * _this, TR_Event event, int timeout) |
|
|
|
|
|
|
|
nevents = poll(this->fds, cmgr->n_endpoints, timeout); |
|
|
|
|
|
|
|
for (i = 0; i < cmgr->n_endpoints, i++) { |
|
|
|
TR_CommEndPoint endpoint = this->endpoints[i]; |
|
|
|
for (i = 0; i < cmgr->n_endpoints; i++) { |
|
|
|
TR_CommEndPoint endpoint = cmgr->endpoints[i]; |
|
|
|
|
|
|
|
if (this->fds[i].revents & POLLIN == POLLIN) { |
|
|
|
if ((this->fds[i].revents & POLLIN) == POLLIN) { |
|
|
|
nevents--; |
|
|
|
if (TR_INSTANCE_OF(TR_TcpSocket, endpoints->transport) |
|
|
|
if (TR_INSTANCE_OF(TR_TcpSocket, endpoint->transport) |
|
|
|
&& ((TR_TcpSocket)endpoint->transport)->listen) { |
|
|
|
TR_eventHandlerIssueEvent( |
|
|
|
(TR_EventHandler)this, |
|
|
|
(TR_Connection)endpoint, |
|
|
|
TR_CON_EVENT_ACC_READY, |
|
|
|
(TR_EventSubject)endpoint, |
|
|
|
TR_CET_EVENT_ACC_READY, |
|
|
|
NULL); |
|
|
|
} else { |
|
|
|
TR_eventHandlerIssueEvent( |
|
|
|
(TR_EventHandler)this, |
|
|
|
endpoint, |
|
|
|
TR_CET_EVENT_READ_READY, |
|
|
|
(TR_EventSubject)endpoint, |
|
|
|
TR_CEP_EVENT_READ_READY, |
|
|
|
NULL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (this->fds[i].revents & POLLOUT == POLLOUT) { |
|
|
|
if ((this->fds[i].revents & POLLOUT) == POLLOUT) { |
|
|
|
nevents--; |
|
|
|
TR_eventHandlerIssueEvent( |
|
|
|
(TR_EventHandler)this, |
|
|
|
endpoint, |
|
|
|
TR_CET_EVENT_WRITE_READY, |
|
|
|
(TR_EventSubject)endpoint, |
|
|
|
TR_CEP_EVENT_WRITE_READY, |
|
|
|
NULL); |
|
|
|
} |
|
|
|
|
|
|
|
@ -113,56 +118,50 @@ TR_commManagerSelect(void * _this, TR_Event event, int timeout) |
|
|
|
|
|
|
|
static |
|
|
|
void |
|
|
|
TR_commManagerEnableWrite(void * _this, TR_Event event) |
|
|
|
TR_commManagerPollEnableWrite(void * _this, TR_Event event) |
|
|
|
{ |
|
|
|
TR_CommManagerPoll this = _this; |
|
|
|
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
|
|
|
|
|
|
|
if (! TR_socketFinWr(endpoint->transport)) { |
|
|
|
this->fds[endpoint->transport->handle].event |= POLLOUT; |
|
|
|
this->fds[endpoint->transport->handle].events |= POLLOUT; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static |
|
|
|
int |
|
|
|
TR_commManagerDisableWrite(void * _this, TR_Event event) |
|
|
|
void |
|
|
|
TR_commManagerPollDisableWrite(void * _this, TR_Event event) |
|
|
|
{ |
|
|
|
TR_CommManagerPoll this = _this; |
|
|
|
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
|
|
|
|
|
|
|
this->fds[endpoint->transport->handle].event &= ~POLLOUT; |
|
|
|
this->fds[endpoint->transport->handle].events &= ~POLLOUT; |
|
|
|
} |
|
|
|
|
|
|
|
static |
|
|
|
int |
|
|
|
TR_commManagerClose(void * _this, TR_Event event) |
|
|
|
void |
|
|
|
TR_commManagerPollClose(void * _this, TR_Event event) |
|
|
|
{ |
|
|
|
TR_CommManagerPoll this = _this; |
|
|
|
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
|
|
|
|
|
|
|
this->fds[endpoint->transport->handle].event = 0; |
|
|
|
this->fds[endpoint->transport->handle].fs = -1; |
|
|
|
this->fds[endpoint->transport->handle].events = 0; |
|
|
|
this->fds[endpoint->transport->handle].fd = -1; |
|
|
|
} |
|
|
|
|
|
|
|
static |
|
|
|
int |
|
|
|
TR_commManagerDisableRead(void * _this, TR_Event event) |
|
|
|
void |
|
|
|
TR_commManagerPollDisableRead(void * _this, TR_Event event) |
|
|
|
{ |
|
|
|
TR_CommManagerPoll this = _this; |
|
|
|
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
|
|
|
|
|
|
|
this->fds[endpoint->transport->handle].event &= ~POLLIN; |
|
|
|
} |
|
|
|
|
|
|
|
static |
|
|
|
int |
|
|
|
TR_commManagerShutdownRead(void * _this, TR_Event event) |
|
|
|
{ |
|
|
|
this->fds[endpoint->transport->handle].events &= ~POLLIN; |
|
|
|
} |
|
|
|
|
|
|
|
static |
|
|
|
void |
|
|
|
commManagerPollCvInit(TR_class_ptr cls) { |
|
|
|
TR_commManagerPollCvInit(TR_class_ptr cls) { |
|
|
|
TR_INHERIT_CLASSVARS(TR_CommManagerPoll, TR_CommManager); |
|
|
|
} |
|
|
|
|
|
|
|
@ -179,7 +178,7 @@ TR_INIT_IFACE( |
|
|
|
TR_CREATE_CLASS( |
|
|
|
TR_CommManagerPoll, |
|
|
|
TR_CommManager, |
|
|
|
TR_CommManagerPollCvInit, |
|
|
|
TR_commManagerPollCvInit, |
|
|
|
TR_IF(TR_Class)); |
|
|
|
|
|
|
|
// vim: set ts=4 sw=4: |