Browse Source

generally epoll is working... sadly I removed the is_writing flag in the CommEndPoint which was neccessary... I have to add it again.

1.0.0
Georg Hopp 11 years ago
parent
commit
5210036335
  1. 5
      include/tr/comm_manager.h
  2. 3
      include/tr/comm_manager_epoll.h
  3. 3
      include/tr/comm_manager_poll.h
  4. 4
      include/tr/interface/comm_manager.h
  5. 16
      src/cep_write_buffered.c
  6. 16
      src/comm_end_point.c
  7. 168
      src/comm_manager_epoll.c
  8. 14
      src/comm_manager_poll.c
  9. 2
      src/comm_manager_shutdown.c
  10. 9
      src/conn_entry_point.c
  11. 14
      src/connection.c
  12. 5
      src/datagram_entry_point.c
  13. 9
      src/datagram_service.c
  14. 17
      src/io_handler.c
  15. 2
      src/protocol_handler.c
  16. 13
      testers/test_handler.c
  17. 4
      testers/testclient.sh
  18. 2
      testers/testserver2.c

5
include/tr/comm_manager.h

@ -24,7 +24,6 @@
#define __TR_COMM_MANAGER_H__ #define __TR_COMM_MANAGER_H__
#include <sys/types.h> #include <sys/types.h>
#include <poll.h>
#include "trbase.h" #include "trbase.h"
#include "trevent.h" #include "trevent.h"
@ -35,8 +34,8 @@ TR_CLASS(TR_CommManager) {
TR_EXTENDS(TR_EventHandler); TR_EXTENDS(TR_EventHandler);
TR_CommEndPoint * endpoints; TR_CommEndPoint * endpoints;
nfds_t n_endpoints;
nfds_t max_handle;
size_t n_endpoints;
size_t max_handle;
}; };
TR_INSTANCE_INIT(TR_CommManager); TR_INSTANCE_INIT(TR_CommManager);
TR_CLASSVARS_DECL(TR_CommManager) { TR_CLASSVARS_DECL(TR_CommManager) {

3
include/tr/comm_manager_epoll.h

@ -27,6 +27,7 @@
#include <sys/epoll.h> #include <sys/epoll.h>
#include "trbase.h" #include "trbase.h"
#include "trdata.h"
#include "trevent.h" #include "trevent.h"
TR_CLASS(TR_CommManagerEpoll) { TR_CLASS(TR_CommManagerEpoll) {
@ -34,6 +35,8 @@ TR_CLASS(TR_CommManagerEpoll) {
int handle; int handle;
struct epoll_event * events; struct epoll_event * events;
TR_Queue read_ready;
TR_Queue write_ready;
}; };
TR_INSTANCE_INIT(TR_CommManagerEpoll); TR_INSTANCE_INIT(TR_CommManagerEpoll);
TR_CLASSVARS_DECL(TR_CommManagerEpoll) { TR_CLASSVARS_DECL(TR_CommManagerEpoll) {

3
include/tr/comm_manager_poll.h

@ -32,7 +32,7 @@
TR_CLASS(TR_CommManagerPoll) { TR_CLASS(TR_CommManagerPoll) {
TR_EXTENDS(TR_CommManager); TR_EXTENDS(TR_CommManager);
struct pollfd * fds;
struct pollfd * fds;
}; };
TR_INSTANCE_INIT(TR_CommManagerPoll); TR_INSTANCE_INIT(TR_CommManagerPoll);
TR_CLASSVARS_DECL(TR_CommManagerPoll) { TR_CLASSVARS_DECL(TR_CommManagerPoll) {
@ -42,4 +42,3 @@ TR_CLASSVARS_DECL(TR_CommManagerPoll) {
#endif // __TR_COMM_MANAGER_POLL_H__ #endif // __TR_COMM_MANAGER_POLL_H__
// vim: set ts=4 sw=4: // vim: set ts=4 sw=4:

4
include/tr/interface/comm_manager.h

@ -47,8 +47,8 @@ TR_INTERFACE(TR_CommManager) {
fptr_TR_commManagerDisableWrite disableWrite; fptr_TR_commManagerDisableWrite disableWrite;
fptr_TR_commManagerEnableRead enableRead; fptr_TR_commManagerEnableRead enableRead;
fptr_TR_commManagerClose close; fptr_TR_commManagerClose close;
fptr_TR_commManagerShutdownRead shutdownWrite;
fptr_TR_commManagerShutdownWrite shutdownRead;
fptr_TR_commManagerShutdownWrite shutdownWrite;
fptr_TR_commManagerShutdownRead shutdownRead;
}; };
void TR_commManagerAddEndpoint(void *, TR_CommEndPoint); void TR_commManagerAddEndpoint(void *, TR_CommEndPoint);

16
src/cep_write_buffered.c

@ -28,12 +28,24 @@
int int
TR_cepWriteBuffered(TR_CommEndPoint this) TR_cepWriteBuffered(TR_CommEndPoint this)
{ {
TR_RemoteData data = TR_cepNextWriteData(this);
int send = TR_socketSend(this->transport, data);
TR_RemoteData data;
int send;
// fprintf(stderr, "%s(%p): before get write data: %p / %zd messages\n",
// __func__, this, data, this->write_buffer->nmsg);
data = TR_cepNextWriteData(this);
// fprintf(stderr, "%s(%p): get write data: %p / %zd messages\n",
// __func__, this, data, this->write_buffer->nmsg);
// fflush(stderr);
send = TR_socketSend(this->transport, data);
switch (send) { switch (send) {
case FALSE: // EAGAIN case FALSE: // EAGAIN
TR_queuePutFirst(this->write_buffer, data); TR_queuePutFirst(this->write_buffer, data);
// fprintf(stderr, "%s(%p): put first write data: %p / %zd messages\n",
// __func__, this, data, this->write_buffer->nmsg);
// fflush(stderr);
break; break;
case -1: // FAILURE case -1: // FAILURE

16
src/comm_end_point.c

@ -77,6 +77,21 @@ commEndPointCvInit(TR_class_ptr cls)
TR_EVENT_CREATE(cls, TR_CEP_EVENT_CLOSE); TR_EVENT_CREATE(cls, TR_CEP_EVENT_CLOSE);
} }
const char * TR_cepEventStrings[] = {
"TR_CEP_EVENT_READ_READY",
"TR_CEP_EVENT_READ_BLOCK",
"TR_CEP_EVENT_WRITE_READY",
"TR_CEP_EVENT_UPGRADE",
"TR_CEP_EVENT_NEW_DATA",
"TR_CEP_EVENT_PENDING_DATA",
"TR_CEP_EVENT_END_DATA",
"TR_CEP_EVENT_NEW_MSG",
"TR_CEP_EVENT_SEND_MSG",
"TR_CEP_EVENT_SHUT_READ",
"TR_CEP_EVENT_SHUT_WRITE",
"TR_CEP_EVENT_CLOSE"
};
intptr_t comm_end_point_events[TR_CEP_EVENT_MAX + 1]; intptr_t comm_end_point_events[TR_CEP_EVENT_MAX + 1];
TR_INIT_IFACE(TR_Class, commEndPointCtor, commEndPointDtor, NULL); TR_INIT_IFACE(TR_Class, commEndPointCtor, commEndPointDtor, NULL);
TR_INIT_IFACE(TR_CommEndPoint, NULL, NULL); TR_INIT_IFACE(TR_CommEndPoint, NULL, NULL);
@ -87,6 +102,7 @@ TR_CREATE_CLASS(
TR_IF(TR_Class), TR_IF(TR_Class),
TR_IF(TR_CommEndPoint)) = { TR_IF(TR_CommEndPoint)) = {
{ {
TR_cepEventStrings,
TR_CEP_EVENT_MAX + 1, TR_CEP_EVENT_MAX + 1,
comm_end_point_events comm_end_point_events
} }

168
src/comm_manager_epoll.c

@ -25,6 +25,7 @@
#include <sys/epoll.h> #include <sys/epoll.h>
#include "trbase.h" #include "trbase.h"
#include "trdata.h"
#include "trevent.h" #include "trevent.h"
#include "tr/comm_manager.h" #include "tr/comm_manager.h"
@ -44,16 +45,14 @@ commManagerEpollCtor(void * _this, va_list * params)
{ {
TR_CommManagerEpoll this = _this; TR_CommManagerEpoll this = _this;
TR_CommManager cmgr = _this; TR_CommManager cmgr = _this;
nfds_t i;
TR_PARENTCALL(TR_CommManagerEpoll, _this, TR_Class, ctor, params); TR_PARENTCALL(TR_CommManagerEpoll, _this, TR_Class, ctor, params);
this->handle = epoll_create(cmgr->n_endpoints);
this->events = TR_malloc(sizeof(struct epoll_event) * cmgr->n_endpoints);
for (i = 0; i < cmgr->n_endpoints; i++) {
this->events[i].data.ptr = NULL;
this->events[i].events = EPOLLET | EPOLLONESHOT;
}
this->handle = epoll_create(cmgr->n_endpoints);
this->read_ready = TR_new(TR_Queue);
this->write_ready = TR_new(TR_Queue);
this->read_ready->free_msgs = 0;
this->write_ready->free_msgs = 0;
return 0; return 0;
} }
@ -64,8 +63,10 @@ commManagerEpollDtor(void * _this)
{ {
TR_CommManagerEpoll this = _this; TR_CommManagerEpoll this = _this;
TR_delete(this->read_ready);
TR_delete(this->write_ready);
close(this->handle); close(this->handle);
TR_MEM_FREE(this->events);
TR_PARENTCALL(TR_CommManagerEpoll, _this, TR_Class, dtor); TR_PARENTCALL(TR_CommManagerEpoll, _this, TR_Class, dtor);
} }
@ -75,11 +76,12 @@ TR_commManagerEpollAddEndpoint(void * _this, TR_CommEndPoint endpoint)
{ {
TR_CommManagerEpoll this = _this; TR_CommManagerEpoll this = _this;
int handle = endpoint->transport->handle; int handle = endpoint->transport->handle;
struct epoll_event event;
this->events[handle].data.ptr = endpoint;
this->events[handle].events |= EPOLLIN;
event.data.ptr = endpoint;
event.events = EPOLLIN | EPOLLOUT | EPOLLET;
epoll_ctl(this->handle, EPOLL_CTL_ADD, handle, &(this->events[handle]));
epoll_ctl(this->handle, EPOLL_CTL_ADD, handle, &event);
} }
static static
@ -88,6 +90,11 @@ TR_commManagerEpollSelect(void * _this, TR_Event event, int timeout)
{ {
TR_CommManagerEpoll this = _this; TR_CommManagerEpoll this = _this;
int i, nevents; int i, nevents;
TR_Queue node;
if (0 != (this->read_ready->nmsg & this->write_ready->nmsg)) {
timeout = 0;
}
nevents = epoll_wait(this->handle, events, MAXEVENTS, timeout); nevents = epoll_wait(this->handle, events, MAXEVENTS, timeout);
@ -95,113 +102,132 @@ TR_commManagerEpollSelect(void * _this, TR_Event event, int timeout)
TR_CommEndPoint endpoint = (TR_CommEndPoint)events[i].data.ptr; TR_CommEndPoint endpoint = (TR_CommEndPoint)events[i].data.ptr;
if ((events[i].events & EPOLLIN) == EPOLLIN) { if ((events[i].events & EPOLLIN) == EPOLLIN) {
TR_Event event;
if (TR_INSTANCE_OF(TR_TcpSocket, endpoint->transport) if (TR_INSTANCE_OF(TR_TcpSocket, endpoint->transport)
&& ((TR_TcpSocket)endpoint->transport)->listen) { && ((TR_TcpSocket)endpoint->transport)->listen) {
event = TR_eventSubjectEmit(
(TR_EventSubject)endpoint,
TR_CET_EVENT_ACC_READY,
NULL);
TR_eventHandlerIssueEvent((TR_EventHandler)this,
TR_eventSubjectEmit(
(TR_EventSubject)endpoint,
TR_CET_EVENT_ACC_READY,
NULL));
} else { } else {
event = TR_eventSubjectEmit(
(TR_EventSubject)endpoint,
TR_CEP_EVENT_READ_READY,
NULL);
if (! ((TR_EventSubject)endpoint)->fin) {
TR_queuePut(this->read_ready, endpoint);
}
} }
TR_eventHandlerIssueEvent((TR_EventHandler)this, event);
this->events[i].events &= ~EPOLLIN;
} }
if ((events[i].events & EPOLLOUT) == EPOLLOUT) { if ((events[i].events & EPOLLOUT) == EPOLLOUT) {
TR_Event _event = TR_eventSubjectEmit(
(TR_EventSubject)endpoint,
TR_CEP_EVENT_WRITE_READY,
NULL);
if (TR_cepHasPendingData(endpoint) &&
! ((TR_EventSubject)endpoint)->fin) {
TR_queuePut(this->write_ready, endpoint);
}
}
}
/* now issue reads and write events */
for (node=this->read_ready->first; node; node=node->next) {
TR_CommEndPoint endpoint = (TR_CommEndPoint)node->msg;
if (! TR_socketFinRd(endpoint->transport)) {
TR_eventHandlerIssueEvent(
(TR_EventHandler)this,
TR_eventSubjectEmit(
(TR_EventSubject)endpoint,
TR_CEP_EVENT_READ_READY,
NULL));
}
}
TR_eventHandlerIssueEvent((TR_EventHandler)this, _event);
this->events[i].events &= ~EPOLLOUT;
for (node=this->write_ready->first; node; node=node->next) {
TR_CommEndPoint endpoint = (TR_CommEndPoint)node->msg;
if (! TR_socketFinWr(endpoint->transport)) {
TR_eventHandlerIssueEvent(
(TR_EventHandler)this,
TR_eventSubjectEmit(
(TR_EventSubject)endpoint,
TR_CEP_EVENT_WRITE_READY,
NULL));
} }
} }
} }
static static
void void
TR_commManagerEpollEnableWrite(void * _this, TR_Event event)
TR_commManagerEpollRemoveWrite(void * _this, TR_Event event)
{ {
TR_CommManagerEpoll this = _this; TR_CommManagerEpoll this = _this;
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
if (! TR_socketFinWr(endpoint->transport)) {
int handle = endpoint->transport->handle;
this->events[handle].data.ptr = endpoint;
this->events[handle].events |= EPOLLOUT;
epoll_ctl(this->handle, EPOLL_CTL_MOD, handle, &(this->events[handle]));
}
TR_queueDelete(this->write_ready, endpoint);
} }
static static
void void
TR_commManagerEpollDisableWrite(void * _this, TR_Event event)
TR_commManagerEpollRemoveRead(void * _this, TR_Event event)
{ {
TR_CommManagerEpoll this = _this; TR_CommManagerEpoll this = _this;
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
int handle = endpoint->transport->handle;
this->events[handle].data.ptr = endpoint;
this->events[handle].events &= ~EPOLLOUT;
epoll_ctl(this->handle, EPOLL_CTL_MOD, handle, &(this->events[handle]));
TR_queueDelete(this->read_ready, endpoint);
} }
static static
void void
TR_commManagerEpollEnableRead(void * _this, TR_Event event)
TR_commManagerEpollClose(void * _this, TR_Event event)
{ {
TR_CommManagerEpoll this = _this; TR_CommManagerEpoll this = _this;
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
if (! TR_socketFinRd(endpoint->transport)) {
int handle = endpoint->transport->handle;
this->events[handle].data.ptr = endpoint;
this->events[handle].events |= EPOLLIN;
TR_queueDelete(this->read_ready, endpoint);
TR_queueDelete(this->write_ready, endpoint);
epoll_ctl(this->handle, EPOLL_CTL_MOD, handle, &(this->events[handle]));
}
epoll_ctl(this->handle, EPOLL_CTL_DEL, endpoint->transport->handle, NULL);
} }
static static
void void
TR_commManagerEpollDisableRead(void * _this, TR_Event event)
TR_commManagerEpollShutRead(void * _this, TR_Event event)
{ {
TR_CommManagerEpoll this = _this; TR_CommManagerEpoll this = _this;
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
int handle = endpoint->transport->handle;
struct epoll_event _event;
TR_queueDelete(this->read_ready, endpoint);
this->events[handle].data.ptr = endpoint;
this->events[handle].events &= ~EPOLLIN;
_event.data.ptr = endpoint;
_event.events = EPOLLOUT | EPOLLET;
epoll_ctl(this->handle, EPOLL_CTL_MOD, handle, &(this->events[handle]));
epoll_ctl(
this->handle,
EPOLL_CTL_MOD,
endpoint->transport->handle,
&_event);
} }
static static
void void
TR_commManagerEpollClose(void * _this, TR_Event event)
TR_commManagerEpollShutWrite(void * _this, TR_Event event)
{ {
TR_CommManagerEpoll this = _this; TR_CommManagerEpoll this = _this;
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
int handle = endpoint->transport->handle;
struct epoll_event _event;
TR_queueDelete(this->write_ready, endpoint);
this->events[handle].data.ptr = NULL;
this->events[handle].events = EPOLLET | EPOLLONESHOT;
_event.data.ptr = endpoint;
_event.events = EPOLLIN | EPOLLET;
epoll_ctl(this->handle, EPOLL_CTL_DEL, handle, NULL);
epoll_ctl(
this->handle,
EPOLL_CTL_MOD,
endpoint->transport->handle,
&_event);
} }
static void TR_commManagerEpollNoop(void * _this, TR_Event event) {}
static static
void void
TR_commManagerEpollCvInit(TR_class_ptr cls) { TR_commManagerEpollCvInit(TR_class_ptr cls) {
@ -211,14 +237,14 @@ TR_commManagerEpollCvInit(TR_class_ptr cls) {
TR_INIT_IFACE(TR_Class, commManagerEpollCtor, commManagerEpollDtor, NULL); TR_INIT_IFACE(TR_Class, commManagerEpollCtor, commManagerEpollDtor, NULL);
TR_INIT_IFACE( TR_INIT_IFACE(
TR_CommManager, TR_CommManager,
TR_commManagerEpollAddEndpoint,
TR_commManagerEpollSelect,
TR_commManagerEpollEnableWrite,
TR_commManagerEpollDisableWrite,
TR_commManagerEpollEnableRead,
TR_commManagerEpollClose,
TR_commManagerEpollDisableRead,
TR_commManagerEpollDisableWrite);
TR_commManagerEpollAddEndpoint, // TR_CON_EVENT_NEW_CON
TR_commManagerEpollSelect, // TR_DISPATCHER_EVENT_DATA_WAIT
TR_commManagerEpollRemoveWrite, // TR_CEP_EVENT_PENDING_DATA => WRITE_BLOCK
TR_commManagerEpollNoop, // TR_CEP_EVENT_END_DATA
TR_commManagerEpollRemoveRead, // TR_CEP_EVENT_READ_BLOCK
TR_commManagerEpollClose, // TR_CEP_EVENT_CLOSE
TR_commManagerEpollShutWrite, // TR_CEP_EVENT_SHUT_READ
TR_commManagerEpollShutRead); // TR_CEP_EVENT_SHUT_WRITE
TR_CREATE_CLASS( TR_CREATE_CLASS(
TR_CommManagerEpoll, TR_CommManagerEpoll,
TR_CommManager, TR_CommManager,

14
src/comm_manager_poll.c

@ -42,6 +42,7 @@ commManagerPollCtor(void * _this, va_list * params)
nfds_t i; nfds_t i;
TR_PARENTCALL(TR_CommManagerPoll, _this, TR_Class, ctor, params); TR_PARENTCALL(TR_CommManagerPoll, _this, TR_Class, ctor, params);
this->fds = TR_malloc(sizeof(struct pollfd) * cmgr->n_endpoints); this->fds = TR_malloc(sizeof(struct pollfd) * cmgr->n_endpoints);
for (i = 0; i < cmgr->n_endpoints; i++) { for (i = 0; i < cmgr->n_endpoints; i++) {
this->fds[i].fd = -1; this->fds[i].fd = -1;
@ -59,7 +60,6 @@ commManagerPollDtor(void * _this)
TR_CommManagerPoll this = _this; TR_CommManagerPoll this = _this;
TR_MEM_FREE(this->fds); TR_MEM_FREE(this->fds);
TR_PARENTCALL(TR_CommManagerPoll, _this, TR_Class, dtor);
} }
static static
@ -67,6 +67,7 @@ void
TR_commManagerPollAddEndpoint(void * _this, TR_CommEndPoint endpoint) TR_commManagerPollAddEndpoint(void * _this, TR_CommEndPoint endpoint)
{ {
TR_CommManagerPoll this = _this; TR_CommManagerPoll this = _this;
this->fds[endpoint->transport->handle].fd = endpoint->transport->handle; this->fds[endpoint->transport->handle].fd = endpoint->transport->handle;
this->fds[endpoint->transport->handle].events = POLLIN; this->fds[endpoint->transport->handle].events = POLLIN;
} }
@ -104,21 +105,16 @@ TR_commManagerPollSelect(void * _this, TR_Event event, int timeout)
} }
TR_eventHandlerIssueEvent((TR_EventHandler)this, event); TR_eventHandlerIssueEvent((TR_EventHandler)this, event);
// deactivate read poll mimic edge level behaviour
this->fds[endpoint->transport->handle].events &= ~POLLIN;
} }
if ((this->fds[i].revents & POLLOUT) == POLLOUT) { if ((this->fds[i].revents & POLLOUT) == POLLOUT) {
nevents--;
TR_Event _event = TR_eventSubjectEmit( TR_Event _event = TR_eventSubjectEmit(
(TR_EventSubject)endpoint, (TR_EventSubject)endpoint,
TR_CEP_EVENT_WRITE_READY, TR_CEP_EVENT_WRITE_READY,
NULL); NULL);
TR_eventHandlerIssueEvent((TR_EventHandler)this, _event); TR_eventHandlerIssueEvent((TR_EventHandler)this, _event);
nevents--;
// deactivate write poll mimic edge level behaviour
this->fds[endpoint->transport->handle].events &= ~POLLOUT;
} }
if (nevents <= 0) break; if (nevents <= 0) break;
@ -196,8 +192,8 @@ TR_INIT_IFACE(
TR_commManagerPollDisableWrite, TR_commManagerPollDisableWrite,
TR_commManagerPollEnableRead, TR_commManagerPollEnableRead,
TR_commManagerPollClose, TR_commManagerPollClose,
TR_commManagerPollDisableRead,
TR_commManagerPollDisableWrite);
TR_commManagerPollDisableWrite,
TR_commManagerPollDisableRead);
TR_CREATE_CLASS( TR_CREATE_CLASS(
TR_CommManagerPoll, TR_CommManagerPoll,
TR_CommManager, TR_CommManager,

2
src/comm_manager_shutdown.c

@ -34,7 +34,7 @@ TR_commManagerShutdown(void * _this, TR_Event event)
TR_CommManager this = _this; TR_CommManager this = _this;
nfds_t i; nfds_t i;
for (i=0; i<this->n_endpoints; i++) {
for (i=0; i<=this->max_handle; i++) {
if (this->endpoints[i]) { if (this->endpoints[i]) {
TR_eventHandlerIssueEvent( TR_eventHandlerIssueEvent(
(TR_EventHandler)_this, (TR_EventHandler)_this,

9
src/conn_entry_point.c

@ -60,6 +60,10 @@ connEntryPointCvInit(TR_class_ptr cls)
TR_EVENT_CREATE(cls, TR_CET_EVENT_ACC_READY); TR_EVENT_CREATE(cls, TR_CET_EVENT_ACC_READY);
} }
const char * TR_cetEventStrings[] = {
"TR_CET_EVENT_ACC_READY"
};
intptr_t connEntryPoint_events[TR_CET_EVENT_MAX + 1]; intptr_t connEntryPoint_events[TR_CET_EVENT_MAX + 1];
TR_INIT_IFACE(TR_Class, connEntryPointCtor, connEntryPointDtor, NULL); TR_INIT_IFACE(TR_Class, connEntryPointCtor, connEntryPointDtor, NULL);
TR_INIT_IFACE(TR_CommEndPoint, NULL, NULL); TR_INIT_IFACE(TR_CommEndPoint, NULL, NULL);
@ -70,8 +74,9 @@ TR_CREATE_CLASS(
TR_IF(TR_Class), TR_IF(TR_Class),
TR_IF(TR_CommEndPoint)) = { TR_IF(TR_CommEndPoint)) = {
{{ {{
TR_CET_EVENT_MAX + 1,
connEntryPoint_events
TR_cetEventStrings,
TR_CET_EVENT_MAX + 1,
connEntryPoint_events
}} }}
}; };

14
src/connection.c

@ -123,6 +123,11 @@ connectionCompose(void * _this, TR_ProtoMessage message)
} }
TR_queuePut(((TR_CommEndPoint)_this)->write_buffer, data); TR_queuePut(((TR_CommEndPoint)_this)->write_buffer, data);
// fprintf(stderr, "%s(%p): put write data: %p / %zd messages\n",
// __func__, (TR_CommEndPoint)_this, data,
// ((TR_CommEndPoint)_this)->write_buffer->nmsg);
// fflush(stderr);
return TRUE; return TRUE;
} }
@ -133,6 +138,10 @@ connectionCvInit(TR_class_ptr cls)
TR_EVENT_CREATE(cls, TR_CON_EVENT_NEW_CON); TR_EVENT_CREATE(cls, TR_CON_EVENT_NEW_CON);
} }
const char * TR_connectionEventStrings[] = {
"TR_CON_EVENT_NEW_CON"
};
intptr_t connection_events[TR_CON_EVENT_MAX + 1]; intptr_t connection_events[TR_CON_EVENT_MAX + 1];
TR_INIT_IFACE(TR_Class, connectionCtor, connectionDtor, NULL); TR_INIT_IFACE(TR_Class, connectionCtor, connectionDtor, NULL);
TR_INIT_IFACE( TR_INIT_IFACE(
@ -146,8 +155,9 @@ TR_CREATE_CLASS(
TR_IF(TR_Class), TR_IF(TR_Class),
TR_IF(TR_CommEndPoint)) = { TR_IF(TR_CommEndPoint)) = {
{{ {{
TR_CON_EVENT_MAX + 1,
connection_events
TR_connectionEventStrings,
TR_CON_EVENT_MAX + 1,
connection_events
}} }}
}; };

5
src/datagram_entry_point.c

@ -56,8 +56,9 @@ TR_CREATE_CLASS(
NULL, NULL,
TR_IF(TR_Class)) = { TR_IF(TR_Class)) = {
{{ {{
TR_CEP_EVENT_MAX + 1,
datagramEntryPoint_events
NULL,
TR_CEP_EVENT_MAX + 1,
datagramEntryPoint_events
}} }}
}; };

9
src/datagram_service.c

@ -110,6 +110,10 @@ datagramServiceCompose(void * _this, TR_ProtoMessage message)
} }
TR_queuePut(((TR_CommEndPoint)_this)->write_buffer, data); TR_queuePut(((TR_CommEndPoint)_this)->write_buffer, data);
// fprintf(stderr, "%s(%p): put write data: %p / %zd messages\n",
// __func__, (TR_CommEndPoint)_this, data,
// ((TR_CommEndPoint)_this)->write_buffer->nmsg);
// fflush(stderr);
return TRUE; return TRUE;
} }
@ -126,8 +130,9 @@ TR_CREATE_CLASS(
TR_IF(TR_Class), TR_IF(TR_Class),
TR_IF(TR_CommEndPoint)) = { TR_IF(TR_CommEndPoint)) = {
{{ {{
TR_CEP_EVENT_MAX + 1,
datagramService_events
NULL,
TR_CEP_EVENT_MAX + 1,
datagramService_events
}} }}
}; };

17
src/io_handler.c

@ -44,8 +44,7 @@ static
TR_EventDone TR_EventDone
ioHandlerRead(void * _this, TR_Event event) ioHandlerRead(void * _this, TR_Event event)
{ {
TR_Event revent;
TR_EventDone done = TR_EVENT_DONE;
TR_Event revent;
switch (TR_cepBufferRead((TR_CommEndPoint)event->subject)) { switch (TR_cepBufferRead((TR_CommEndPoint)event->subject)) {
case FALSE: // EAGAIN case FALSE: // EAGAIN
@ -75,26 +74,26 @@ ioHandlerRead(void * _this, TR_Event event)
event->subject, event->subject,
TR_CEP_EVENT_NEW_DATA, TR_CEP_EVENT_NEW_DATA,
NULL); NULL);
done = TR_EVENT_PENDING;
break; break;
} }
TR_eventHandlerIssueEvent((TR_EventHandler)_this, revent); TR_eventHandlerIssueEvent((TR_EventHandler)_this, revent);
return done;
return TR_EVENT_DONE;
} }
static static
TR_EventDone TR_EventDone
ioHandlerWrite(void * _this, TR_Event event) ioHandlerWrite(void * _this, TR_Event event)
{ {
TR_Event revent, close_event = NULL;
TR_Event revent = NULL,
close_event = NULL;
switch (TR_cepWriteBuffered((TR_CommEndPoint)event->subject)) { switch (TR_cepWriteBuffered((TR_CommEndPoint)event->subject)) {
case FALSE: // EAGAIN case FALSE: // EAGAIN
revent = TR_eventSubjectEmit( revent = TR_eventSubjectEmit(
event->subject, event->subject,
TR_CEP_EVENT_PENDING_DATA,
TR_CEP_EVENT_PENDING_DATA, // is WRITE_BLOCK
NULL); NULL);
break; break;
@ -129,9 +128,7 @@ ioHandlerWrite(void * _this, TR_Event event)
} }
TR_eventHandlerIssueEvent((TR_EventHandler)_this, revent); TR_eventHandlerIssueEvent((TR_EventHandler)_this, revent);
if (close_event) {
TR_eventHandlerIssueEvent((TR_EventHandler)_this, close_event);
}
TR_eventHandlerIssueEvent((TR_EventHandler)_this, close_event);
return TR_EVENT_DONE; return TR_EVENT_DONE;
} }

2
src/protocol_handler.c

@ -91,8 +91,6 @@ protocolHandlerCompose(void * _this, TR_Event event)
NULL); NULL);
TR_eventHandlerIssueEvent((TR_EventHandler)_this, _event); TR_eventHandlerIssueEvent((TR_EventHandler)_this, _event);
} else {
//printf("%s: compose failed\n", __func__);
} }
TR_delete(message); TR_delete(message);

13
testers/test_handler.c

@ -25,6 +25,7 @@ testHandlerNewMessage(TR_EventHandler this, TR_Event event)
// TR_SizedData data = (TR_SizedData)msg->data; // TR_SizedData data = (TR_SizedData)msg->data;
// char buf[data->size + 1]; // char buf[data->size + 1];
// int i; // int i;
TR_Event _event;
((TestHandler)this)->handled++; ((TestHandler)this)->handled++;
@ -36,12 +37,12 @@ testHandlerNewMessage(TR_EventHandler this, TR_Event event)
// } // }
// printf("echo message: %s(%zd)\n", buf, data->size); // printf("echo message: %s(%zd)\n", buf, data->size);
TR_eventHandlerIssueEvent(
(TR_EventHandler)this,
TR_eventSubjectEmit(
event->subject,
TR_CEP_EVENT_SEND_MSG,
event->data));
_event = TR_eventSubjectEmit(
event->subject,
TR_CEP_EVENT_SEND_MSG,
event->data);
TR_eventHandlerIssueEvent((TR_EventHandler)this, _event);
return TR_EVENT_DONE; return TR_EVENT_DONE;
} }

4
testers/testclient.sh

@ -2,9 +2,9 @@
pids="" pids=""
i=0 i=0
while [ $i -lt 100 ]
while [ $i -lt 120 ]
do do
dd if=/dev/zero bs=8192 count=25000 | nc 192.168.2.13 5678 &
dd if=/dev/zero bs=8192 count=2500 | nc 192.168.2.13 5678 &
pids="${pids} $!" pids="${pids} $!"
i=$((i + 1)) i=$((i + 1))
done done

2
testers/testserver2.c

@ -9,7 +9,7 @@
#include "test_handler.h" #include "test_handler.h"
TR_INSTANCE(TR_LoggerSyslog, mylogger, {TR_LOGGER_DEBUG});
TR_INSTANCE(TR_LoggerSyslog, mylogger, {TR_LOGGER_INFO});
int int
main (int argc, char * argv[]) main (int argc, char * argv[])

Loading…
Cancel
Save