Showing
6 changed files
with
233 additions
and
0 deletions
| @@ -66,6 +66,8 @@ TR_CLASSVARS_DECL(TR_CommEndPoint) { | @@ -66,6 +66,8 @@ TR_CLASSVARS_DECL(TR_CommEndPoint) { | ||
| 66 | 66 | ||
| 67 | void TR_cepAppendReadData(TR_CommEndPoint, TR_RemoteData); | 67 | void TR_cepAppendReadData(TR_CommEndPoint, TR_RemoteData); |
| 68 | void TR_cepAppendWriteData(TR_CommEndPoint, TR_RemoteData); | 68 | void TR_cepAppendWriteData(TR_CommEndPoint, TR_RemoteData); |
| 69 | +int TR_cepBufferRead(TR_CommEndPoint); | ||
| 70 | +int TR_cepWriteBuffered(TR_CommEndPoint); | ||
| 69 | 71 | ||
| 70 | #endif // __TR_COMM_END_POINT_H__ | 72 | #endif // __TR_COMM_END_POINT_H__ |
| 71 | 73 |
include/tr/io_handler.h
0 → 100644
| 1 | +/** | ||
| 2 | + * \file | ||
| 3 | + * | ||
| 4 | + * \author Georg Hopp | ||
| 5 | + * | ||
| 6 | + * \copyright | ||
| 7 | + * Copyright © 2014 Georg Hopp | ||
| 8 | + * | ||
| 9 | + * This program is free software: you can redistribute it and/or modify | ||
| 10 | + * it under the terms of the GNU General Public License as published by | ||
| 11 | + * the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + * (at your option) any later version. | ||
| 13 | + * | ||
| 14 | + * This program is distributed in the hope that it will be useful, | ||
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + * GNU General Public License for more details. | ||
| 18 | + * | ||
| 19 | + * You should have received a copy of the GNU General Public License | ||
| 20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | + */ | ||
| 22 | + | ||
| 23 | +#ifndef __TR_IO_HANDLER_H__ | ||
| 24 | +#define __TR_IO_HANDLER_H__ | ||
| 25 | + | ||
| 26 | +#include <sys/types.h> | ||
| 27 | + | ||
| 28 | +#include "trbase.h" | ||
| 29 | +#include "trevent.h" | ||
| 30 | + | ||
| 31 | +TR_CLASS(TR_IoHandler) { | ||
| 32 | + TR_EXTENDS(TR_EventHandler); | ||
| 33 | +}; | ||
| 34 | +TR_INSTANCE_INIT(TR_IoHandler); | ||
| 35 | +TR_CLASSVARS_DECL(TR_IoHandler) { | ||
| 36 | + TR_CV_EXTENDS(TR_EventHandler); | ||
| 37 | +}; | ||
| 38 | + | ||
| 39 | +#endif // __TR_IO_HANDLER_H__ | ||
| 40 | + | ||
| 41 | +// vim: set ts=4 sw=4: | ||
| 42 | + |
| @@ -6,6 +6,8 @@ AM_CFLAGS += -I../include/ | @@ -6,6 +6,8 @@ AM_CFLAGS += -I../include/ | ||
| 6 | TRCOMM = cep_append_read_data.c \ | 6 | TRCOMM = cep_append_read_data.c \ |
| 7 | cep_append_write_data.c \ | 7 | cep_append_write_data.c \ |
| 8 | cet_accept.c \ | 8 | cet_accept.c \ |
| 9 | + cep_buffer_read.c \ | ||
| 10 | + cep_write_buffered.c \ | ||
| 9 | comm_end_point.c \ | 11 | comm_end_point.c \ |
| 10 | comm_manager.c \ | 12 | comm_manager.c \ |
| 11 | comm_manager_poll.c \ | 13 | comm_manager_poll.c \ |
src/cep_buffer_read.c
0 → 100644
| 1 | +/** | ||
| 2 | + * \file | ||
| 3 | + * | ||
| 4 | + * \author Georg Hopp | ||
| 5 | + * | ||
| 6 | + * \copyright | ||
| 7 | + * Copyright © 2014 Georg Hopp | ||
| 8 | + * | ||
| 9 | + * This program is free software: you can redistribute it and/or modify | ||
| 10 | + * it under the terms of the GNU General Public License as published by | ||
| 11 | + * the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + * (at your option) any later version. | ||
| 13 | + * | ||
| 14 | + * This program is distributed in the hope that it will be useful, | ||
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + * GNU General Public License for more details. | ||
| 18 | + * | ||
| 19 | + * You should have received a copy of the GNU General Public License | ||
| 20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | + */ | ||
| 22 | + | ||
| 23 | +#include "trbase.h" | ||
| 24 | +#include "trio.h" | ||
| 25 | + | ||
| 26 | +#include "tr/comm_end_point.h" | ||
| 27 | + | ||
| 28 | +int | ||
| 29 | +cepBufferedRead(TR_CommEndPoint this) | ||
| 30 | +{ | ||
| 31 | + TR_RemoteData data = TR_socketRecv(this->transport); | ||
| 32 | + | ||
| 33 | + if (! data) return FALSE; | ||
| 34 | + | ||
| 35 | + while (data) { | ||
| 36 | + TR_cepAppendReadData(data); | ||
| 37 | + data = TR_socketRecv(this->transport); | ||
| 38 | + } | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +// vim: set ts=4 sw=4: |
src/cep_write_buffered.c
0 → 100644
| 1 | +/** | ||
| 2 | + * \file | ||
| 3 | + * | ||
| 4 | + * \author Georg Hopp | ||
| 5 | + * | ||
| 6 | + * \copyright | ||
| 7 | + * Copyright © 2014 Georg Hopp | ||
| 8 | + * | ||
| 9 | + * This program is free software: you can redistribute it and/or modify | ||
| 10 | + * it under the terms of the GNU General Public License as published by | ||
| 11 | + * the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + * (at your option) any later version. | ||
| 13 | + * | ||
| 14 | + * This program is distributed in the hope that it will be useful, | ||
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + * GNU General Public License for more details. | ||
| 18 | + * | ||
| 19 | + * You should have received a copy of the GNU General Public License | ||
| 20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | + */ | ||
| 22 | + | ||
| 23 | +#include "trbase.h" | ||
| 24 | +#include "trio.h" | ||
| 25 | + | ||
| 26 | +#include "tr/comm_end_point.h" | ||
| 27 | + | ||
| 28 | +int | ||
| 29 | +cepBufferedRead(TR_CommEndPoint this) | ||
| 30 | +{ | ||
| 31 | + TR_RemoteData data = TR_cepNextWriteData(this); | ||
| 32 | + int send = 0; | ||
| 33 | + | ||
| 34 | + while (data) { | ||
| 35 | + int current_send = TR_socketSend(this->transport, data); | ||
| 36 | + | ||
| 37 | + // TODO if nothing was send put it back into the queue.. | ||
| 38 | + // and stop loop. (This was a close.) | ||
| 39 | + | ||
| 40 | + data = TR_socketRecv(this->transport); | ||
| 41 | + } | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +// vim: set ts=4 sw=4: |
src/io_handler.c
0 → 100644
| 1 | +/** | ||
| 2 | + * \file | ||
| 3 | + * | ||
| 4 | + * \author Georg Hopp | ||
| 5 | + * | ||
| 6 | + * \copyright | ||
| 7 | + * Copyright © 2014 Georg Hopp | ||
| 8 | + * | ||
| 9 | + * This program is free software: you can redistribute it and/or modify | ||
| 10 | + * it under the terms of the GNU General Public License as published by | ||
| 11 | + * the Free Software Foundation, either version 3 of the License, or | ||
| 12 | + * (at your option) any later version. | ||
| 13 | + * | ||
| 14 | + * This program is distributed in the hope that it will be useful, | ||
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | + * GNU General Public License for more details. | ||
| 18 | + * | ||
| 19 | + * You should have received a copy of the GNU General Public License | ||
| 20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | + */ | ||
| 22 | + | ||
| 23 | +#include <unistd.h> | ||
| 24 | + | ||
| 25 | +#include "trbase.h" | ||
| 26 | +#include "trevent.h" | ||
| 27 | + | ||
| 28 | +#include "tr/protocol.h" | ||
| 29 | +#include "tr/connection.h" | ||
| 30 | +#include "tr/protocol_handler.h" | ||
| 31 | +#include "tr/proto_message.h" | ||
| 32 | +#include "tr/comm_end_point.h" | ||
| 33 | +#include "tr/interface/comm_end_point.h" | ||
| 34 | + | ||
| 35 | +static | ||
| 36 | +int | ||
| 37 | +ioHandlerCtor(void * _this, va_list * params) | ||
| 38 | +{ | ||
| 39 | + TR_PARENTCALL(_this, TR_Class, ctor, params); | ||
| 40 | + | ||
| 41 | + return 0; | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +static void ioHandlerDtor(void * _this) {} | ||
| 45 | + | ||
| 46 | +static | ||
| 47 | +int | ||
| 48 | +ioHandlerRead(void * _this, TR_Event event) | ||
| 49 | +{ | ||
| 50 | + /** | ||
| 51 | + * TODO No upgrade for now. Add it later on. | ||
| 52 | + */ | ||
| 53 | + TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; | ||
| 54 | + TR_ProtoMessage message = TR_cepNextMessage(endpoint); | ||
| 55 | + | ||
| 56 | + return TRUE; | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +static | ||
| 60 | +int | ||
| 61 | +ioHandlerWrite(void * _this, TR_Event event) | ||
| 62 | +{ | ||
| 63 | + TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; | ||
| 64 | + TR_ProtoMessage message = (TR_ProtoMessage)event->data; | ||
| 65 | + | ||
| 66 | + if (message->close) { | ||
| 67 | + // also check that we are a response. Well this is how it is done | ||
| 68 | + // in the python code... | ||
| 69 | + TR_cepSetClose(endpoint); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + return TRUE; | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +static | ||
| 76 | +void | ||
| 77 | +protocolHandlerCvInit(TR_class_ptr cls) | ||
| 78 | +{ | ||
| 79 | + TR_EVENT_HANDLER_SET_METHOD( | ||
| 80 | + cls, | ||
| 81 | + TR_Connection, | ||
| 82 | + TR_CEP_EVENT_READ_READY, | ||
| 83 | + ioHandlerRead); | ||
| 84 | + | ||
| 85 | + TR_EVENT_HANDLER_SET_METHOD( | ||
| 86 | + cls, | ||
| 87 | + TR_Connection, | ||
| 88 | + TR_CEP_EVENT_WRITE_READY, | ||
| 89 | + ioHandlerWrite); | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +TR_INSTANCE(TR_Hash, ioHandlerEventMethods); | ||
| 93 | +TR_INIT_IFACE(TR_Class, ioHandlerCtor, ioHandlerDtor, NULL); | ||
| 94 | +TR_CREATE_CLASS( | ||
| 95 | + TR_ProtocolHandler, | ||
| 96 | + TR_EventHandler, | ||
| 97 | + ioHandlerCvInit, | ||
| 98 | + TR_IF(TR_Class)) = { | ||
| 99 | + { &(_ioHandlerEventMethods.data) } | ||
| 100 | +}; | ||
| 101 | + | ||
| 102 | +// vim: set ts=4 sw=4: |
Please
register
or
login
to post a comment