config.guess
config.h
config.h.in
+config.h.in~
config.log
config.status
config.sub
AC_PREFIX_DEFAULT([~/iotest])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign])
-#AM_SILENT_RULES([yes])
+AM_SILENT_RULES([yes])
AC_CONFIG_HEADERS([config.h])
#LT_INIT([disable-static])
# Checks for programs.
AC_PROG_AWK
AC_PROG_CC
+AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_RANLIB
])
])
-AC_CONFIG_FILES([Makefile src/Makefile src/IOHandler/Makefile src/IOHandler_test/Makefile src/IOHandler_test/socket/Makefile src/IOHandler_test/timer/Makefile])
+AC_CONFIG_FILES([Makefile src/Makefile src/IOHandler/Makefile src/IOHandler++/Makefile src/IOHandler_test/Makefile src/IOHandler_test/socket/Makefile src/IOHandler_test/socket++/Makefile src/IOHandler_test/timer/Makefile])
AC_OUTPUT
--- /dev/null
+.deps
+Makefile.in
+Makefile
+*.o
+*.a
--- /dev/null
+/* IOHandler.cpp - IOMultiplexer v2
+ * Copyright (C) 2014 Philipp Kreil (pk910)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+extern "C" {
+ #include "../IOHandler/IOHandler.h"
+}
+#include "IOHandler.h"
+
+CIOHandler::CIOHandler() {
+ iohandler_init();
+}
+
+void CIOHandler::start() {
+ iohandler_run();
+}
+
+void CIOHandler::stop() {
+ iohandler_stop();
+}
--- /dev/null
+/* IOHandler.h - IOMultiplexer v2
+ * Copyright (C) 2014 Philipp Kreil (pk910)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _IOHandler_cpp_h
+#define _IOHandler_cpp_h
+
+extern "C" {
+ #define IOSOCKET_CPP
+ #include "../IOHandler/IOHandler.h"
+}
+
+class CIOHandler {
+public:
+ CIOHandler();
+
+ void start();
+ void stop();
+};
+
+#endif
--- /dev/null
+/* IOSocket.cpp - IOMultiplexer v2
+ * Copyright (C) 2014 Philipp Kreil (pk910)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+extern "C" {
+ #include "../IOHandler/IOSockets.h"
+}
+#include "IOSocket.h"
+#include <cstdarg>
+#include <cstdio>
+#include <cstring>
+
+static IOSOCKET_CALLBACK(c_socket_callback) {
+ CIOSocket *ciosock = (CIOSocket *) event->socket->data;
+ ciosock->socket_callback(event);
+}
+
+CIOSocket::CIOSocket() {
+
+}
+CIOSocket::CIOSocket(IOSocket *iosocket) {
+ this->iosocket = iosocket;
+}
+
+int CIOSocket::connect(char *hostname, unsigned int port, int ssl, char *bindhost) {
+ return this->connect(hostname, port, ssl, bindhost, IOSOCKET_ADDR_IPV6 | IOSOCKET_ADDR_IPV4);
+}
+
+int CIOSocket::connect(char *hostname, unsigned int port, int ssl, char *bindhost, int flags) {
+ this->iosocket = iosocket_connect_flags(hostname, port, (ssl ? 1 : 0), (bindhost ? bindhost : NULL), c_socket_callback, flags);
+ if(this->iosocket) {
+ this->iosocket->data = this;
+ return 1;
+ } else
+ return 0;
+}
+
+int CIOSocket::listen(char *hostname, unsigned int port) {
+ return this->listen(hostname, port, IOSOCKET_ADDR_IPV6 | IOSOCKET_ADDR_IPV4);
+}
+int CIOSocket::listen(char *hostname, unsigned int port, int flags) {
+ this->iosocket = iosocket_listen_flags(hostname, port, c_socket_callback, flags);
+ if(this->iosocket) {
+ this->iosocket->data = this;
+ return 1;
+ } else
+ return 0;
+}
+
+int CIOSocket::listen_ssl(char *hostname, unsigned int port, char *certfile, char *keyfile) {
+ return listen_ssl(hostname, port, certfile, keyfile, IOSOCKET_ADDR_IPV6 | IOSOCKET_ADDR_IPV4);
+}
+int CIOSocket::listen_ssl(char *hostname, unsigned int port, char *certfile, char *keyfile, int flags) {
+ this->iosocket = iosocket_listen_ssl_flags(hostname, port, certfile, keyfile, c_socket_callback, flags);
+ if(this->iosocket) {
+ this->iosocket->data = this;
+ return 1;
+ } else
+ return 0;
+}
+
+void CIOSocket::write(const char *data, int len) {
+ iosocket_send(iosocket, data, len);
+}
+#define IOSOCKET_PRINTF_LEN 2048
+void CIOSocket::writef(const char *format, ...) {
+ va_list arg_list;
+ char sendBuf[IOSOCKET_PRINTF_LEN];
+ int pos;
+ sendBuf[0] = '\0';
+ va_start(arg_list, format);
+ pos = vsnprintf(sendBuf, IOSOCKET_PRINTF_LEN - 1, format, arg_list);
+ va_end(arg_list);
+ if (pos < 0 || pos > (IOSOCKET_PRINTF_LEN - 1)) pos = IOSOCKET_PRINTF_LEN - 1;
+ sendBuf[pos] = '\0';
+ iosocket_send(iosocket, sendBuf, pos);
+}
+
+void CIOSocket::close() {
+ iosocket_close(iosocket);
+};
+
+
+void CIOSocket::socket_callback(IOSocketEvent *event) {
+ switch(event->type) {
+ case IOSOCKETEVENT_RECV:
+ if(iosocket->parse_delimiter)
+ this->recvLine(event->data.recv_str);
+ else {
+ IOSocketBuffer *recvbuf = event->data.recv_buf;
+ int usedlen;
+ usedlen = this->recvEvent(recvbuf->buffer, recvbuf->bufpos);
+ if(usedlen == recvbuf->bufpos) {
+ recvbuf->bufpos = 0;
+ } else {
+ memmove(recvbuf->buffer, recvbuf->buffer + usedlen, recvbuf->bufpos - usedlen);
+ recvbuf->bufpos -= usedlen;
+ }
+ }
+ break;
+ case IOSOCKETEVENT_CONNECTED:
+ this->connectedEvent();
+ break;
+ case IOSOCKETEVENT_NOTCONNECTED:
+ this->notConnectedEvent(event->data.errid);
+ break;
+ case IOSOCKETEVENT_CLOSED:
+ this->closedEvent(event->data.errid);
+ break;
+ case IOSOCKETEVENT_ACCEPT:
+ this->acceptedEvent(new CIOSocket(event->data.accept_socket));
+ break;
+ case IOSOCKETEVENT_DNSFAILED:
+ this->dnsErrEvent(event->data.recv_str);
+ break;
+ }
+}
+
+int CIOSocket::getSSL() {
+
+}
+int CIOSocket::getIPv6() {
+
+}
+int CIOSocket::getConnected() {
+
+}
+int CIOSocket::getListening() {
+
+}
--- /dev/null
+/* IOSocket.h - IOMultiplexer v2
+ * Copyright (C) 2014 Philipp Kreil (pk910)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _IOSocket_cpp_h
+#define _IOSocket_cpp_h
+
+extern "C" {
+ #define IOSOCKET_CPP
+ #include "../IOHandler/IOSockets.h"
+}
+#include <iostream>
+#include <string>
+
+struct IOSocket;
+
+class CIOSocket {
+public:
+ CIOSocket();
+
+ int connect(char *hostname, unsigned int port, int ssl, char *bindhost);
+ int connect(char *hostname, unsigned int port, int ssl, char *bindhost, int flags);
+
+ int listen(char *hostname, unsigned int port);
+ int listen(char *hostname, unsigned int port, int flags);
+ int listen_ssl(char *hostname, unsigned int port, char *certfile, char *keyfile);
+ int listen_ssl(char *hostname, unsigned int port, char *certfile, char *keyfile, int flags);
+
+ void write(const char *data, int len);
+ void writef(const char *format, ...);
+
+ CIOSocket accept();
+
+ void close();
+
+
+ int getSSL();
+ int getIPv6();
+ int getConnected();
+ int getListening();
+
+
+ void socket_callback(IOSocketEvent *event);
+protected:
+ virtual int recvEvent(const char *data, int len) { return len; };
+ virtual void recvLine(char *line) {};
+ void enableRecvLine();
+ void disableRecvLine();
+
+ virtual void connectedEvent() {};
+ virtual void notConnectedEvent(int errid) {};
+ virtual void closedEvent(int errid) {};
+ virtual void acceptedEvent(CIOSocket *client) { client->close(); };
+ virtual void dnsErrEvent(char *errormsg) {};
+
+private:
+ IOSocket *iosocket;
+
+ CIOSocket(IOSocket *iosocket);
+};
+
+#endif
--- /dev/null
+##Process this file with automake to create Makefile.in
+ACLOCAL_AMFLAGS = -I m4
+
+noinst_LIBRARIES = libiohandler.cpp.a
+
+libiohandler_cpp_a_LIBADD = ../IOHandler/libiohandler.a
+libiohandler_cpp_a_SOURCES = IOHandler.cpp \
+IOSocket.cpp
+
#define iosocket_wants_reads(IOSOCK) \
(\
((IOSOCK->socket_flags & (IOSOCKETFLAG_SSL_READHS | IOSOCKETFLAG_SSL_WRITEHS)) && !(IOSOCK->socket_flags & IOSOCKETFLAG_SSL_WANTWRITE)) || \
- (!(IOSOCK->socket_flags & IOSOCKETFLAG_OVERRIDE_WANT_RW) || \
+ (!(IOSOCK->socket_flags & IOSOCKETFLAG_OVERRIDE_WANT_RW)) || \
(IOSOCK->socket_flags & (IOSOCKETFLAG_OVERRIDE_WANT_RW | IOSOCKETFLAG_OVERRIDE_WANT_R) == (IOSOCKETFLAG_OVERRIDE_WANT_RW | IOSOCKETFLAG_OVERRIDE_WANT_R)) \
)\r
#define iosocket_wants_writes(IOSOCK) \
IOSOCKETEVENT_DNSFAILED /* failed to lookup DNS information (recv_str contains error message) */
};
+#define IOSOCKET_ADDR_IPV4 0x01
+#define IOSOCKET_ADDR_IPV6 0x02 /* overrides IOSOCKET_ADDR_IPV4 */
+#define IOSOCKET_PROTO_UDP 0x04
+
+#if !defined IOSOCKET_CPP
struct IOSocket {
void *iosocket;
} data;
};
-
-#define IOSOCKET_ADDR_IPV4 0x01
-#define IOSOCKET_ADDR_IPV6 0x02 /* overrides IOSOCKET_ADDR_IPV4 */
-#define IOSOCKET_PROTO_UDP 0x04
-
struct IOSocket *iosocket_connect(const char *hostname, unsigned int port, int ssl, const char *bindhost, iosocket_callback *callback);
struct IOSocket *iosocket_connect_flags(const char *hostname, unsigned int port, int ssl, const char *bindhost, iosocket_callback *callback, int flags);
struct IOSocket *iosocket_listen(const char *hostname, unsigned int port, iosocket_callback *callback);
void iosocket_close(struct IOSocket *iosocket);
#endif
+#endif
##Process this file with automake to create Makefile.in
ACLOCAL_AMFLAGS = -I m4
-SUBDIRS = socket timer
+SUBDIRS = socket socket++ timer
--- /dev/null
+.deps
+.libs
+*.o
+*.exe
+iotest
+Makefile
+Makefile.in
--- /dev/null
+##Process this file with automake to create Makefile.in
+ACLOCAL_AMFLAGS = -I m4
+
+noinst_PROGRAMS = iotest
+
+iotest_LDADD = ../../IOHandler++/libiohandler.cpp.a \
+../../IOHandler/libiohandler.a
+iotest_SOURCES = iotest.cpp
--- /dev/null
+/* main.c - IOMultiplexer
+ * Copyright (C) 2012 Philipp Kreil (pk910)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include "../../IOHandler++/IOHandler.h"
+#include "../../IOHandler++/IOSocket.h"
+
+class IOTestSocket : public CIOSocket {
+protected:
+ virtual void connectedEvent() {
+ printf("[connect]\n");
+ this->writef("GET / HTTP/1.1\r\n");
+ this->writef("Host: test.pk910.de\r\n");
+ this->writef("\r\n");
+ };
+ virtual void notConnectedEvent(int errid) {
+ printf("[not connected]\n");
+ };
+ virtual void closedEvent(int errid) {
+ printf("[disconnect]\n");
+ };
+ virtual void acceptedEvent(CIOSocket *client) {
+ client->close();
+ };
+ virtual void dnsErrEvent(std::string *errormsg) {
+
+ };
+ virtual int recvEvent(const char *data, int len) {
+ int i;
+ for(i = 0; i < len; i++)
+ putchar(data[i]);
+ return len;
+ };
+};
+
+
+int main(int argc, char *argv[]) {
+ CIOHandler *iohandler = new CIOHandler();
+ IOTestSocket *sock = new IOTestSocket();
+ sock->connect("test.pk910.de", 443, 1, NULL);
+
+ iohandler->start();
+}
.deps
+.libs
*.o
+*.exe
iotest
+Makefile
+Makefile.in
--- /dev/null
+.deps
+.libs
+*.o
+*.exe
+iotest
+Makefile
+Makefile.in
##Process this file with automake to create Makefile.in
ACLOCAL_AMFLAGS = -I m4
-SUBDIRS = IOHandler IOHandler_test
+SUBDIRS = IOHandler IOHandler++ IOHandler_test