Merge remote-tracking branch 'remotes/IOMultiplexer/v2'
authorpk910 <philipp@zoelle1.de>
Wed, 28 Jan 2015 01:20:45 +0000 (02:20 +0100)
committerpk910 <philipp@zoelle1.de>
Wed, 28 Jan 2015 01:20:45 +0000 (02:20 +0100)
Conflicts:
configure.ac

configure.ac
src/IOHandler/IOSockets.c
src/IOHandler_test/Makefile.am
src/IOHandler_test/server/.gitignore [new file with mode: 0644]
src/IOHandler_test/server/Makefile.am [new file with mode: 0644]
src/IOHandler_test/server/iotest.c [new file with mode: 0644]

index f0bc9a63c1f518594b344704a7db2ebf6f054824..29e982775c2fb6663d8917e8e6f710097339a6ba 100644 (file)
@@ -42,16 +42,24 @@ AC_CHECK_LIB(ws2_32, main, [
   is_win32="no"
 ])
 
-if test x$is_win32 = xyes ; then
-  openssl_deps="-lcrypto -lgdi32"
-else
-  openssl_deps="-lcrypto"
+have_gnutls="no"
+AC_CHECK_LIB(gnutls, gnutls_init, [
+  AC_CHECK_HEADERS(gnutls/gnutls.h, [
+    LIBS="$LIBS -lgnutls"
+    have_gnutls="yes"
+  ])
+])
+if test x"$have_gnutls" = xno; then
+  if test x$is_win32 = xyes ; then
+    openssl_deps="-lcrypto -lgdi32"
+  else
+    openssl_deps="-lcrypto"
+  fi
+  AC_CHECK_LIB([ssl],[SSL_library_init], [
+    LIBS="$LIBS -lssl $openssl_deps"
+  ], [AC_MSG_ERROR([OpenSSL libraries required])], $openssl_deps)
 fi
 
-AC_CHECK_LIB([ssl],[SSL_library_init], [
-  LIBS="$LIBS -lssl $openssl_deps"
-], [AC_MSG_ERROR([OpenSSL libraries required])], $openssl_deps)
-
 AC_CHECK_LIB(pthread, pthread_create, [
   AC_CHECK_HEADERS(pthread.h, [
     LIBS="$LIBS -lpthread"
@@ -63,6 +71,7 @@ AC_CHECK_LIB(cares, ares_init, [
   ])
 ])
 
+
 AC_CONFIG_FILES([
   Makefile
   src/Makefile
@@ -72,6 +81,7 @@ AC_CONFIG_FILES([
   src/IOHandler_test/client/Makefile
   src/IOHandler_test/client++/Makefile
   src/IOHandler_test/client_ssl/Makefile
+  src/IOHandler_test/server/Makefile
   src/IOHandler_test/server_ssl/Makefile
   src/IOHandler_test/timer/Makefile
   src/IOHandler_test/timer++/Makefile
index 55c6cee6035114c67550db8b8fc98307b0fe15ae..7c3c50a8f7e8b8770afd72a77f12acaed628d27d 100644 (file)
@@ -47,7 +47,7 @@
 #include <stdarg.h>
 
 #ifndef EWOULDBLOCK
-#define EWOULDBLOCK EAGAIN
+#define EWOULDBLOCK WSAEWOULDBLOCK
 #endif
 
 struct _IOSocket *iosocket_first = NULL;
@@ -1072,14 +1072,20 @@ void iosocket_events_callback(struct _IOSocket *iosock, int readable, int writea
                                else 
                                        bytes = recv(iosock->fd, iosock->readbuf.buffer + iosock->readbuf.bufpos, iosock->readbuf.buflen - iosock->readbuf.bufpos, 0);
                                
-                               if(bytes <= 0) {\r
+                               if(bytes <= 0) {
+                                       int errcode;
+                                       #ifdef WIN32
+                                       errcode = WSAGetLastError();
+                                       #else
+                                       errcode = errno;
+                                       #endif\r
                                        if((iosock->socket_flags & (IOSOCKETFLAG_SSLSOCKET | IOSOCKETFLAG_SSL_READHS)) == (IOSOCKETFLAG_SSLSOCKET | IOSOCKETFLAG_SSL_READHS)) {\r
                                                ssl_rehandshake = 1;\r
-                                       } else if (errno != EAGAIN || errno != EWOULDBLOCK) {
+                                       } else if (errcode != EAGAIN && errcode != EWOULDBLOCK) {
                                                iosock->socket_flags |= IOSOCKETFLAG_DEAD;
                                                
                                                callback_event.type = IOSOCKETEVENT_CLOSED;
-                                               callback_event.data.errid = errno;
+                                               callback_event.data.errid = errcode;
                                        }
                                } else {
                                        int i;
index d8ca43d946728000a7e4407c5feff67bee86ba21..ef3454a9664036ef07d1e60eda08a90ccfe19a5d 100644 (file)
@@ -1,3 +1,3 @@
 ##Process this file with automake to create Makefile.in
 ACLOCAL_AMFLAGS = -I m4
-SUBDIRS = client client++ client_ssl server_ssl timer timer++ resolv
+SUBDIRS = client client++ client_ssl server server_ssl timer timer++ resolv
diff --git a/src/IOHandler_test/server/.gitignore b/src/IOHandler_test/server/.gitignore
new file mode 100644 (file)
index 0000000..7af2f69
--- /dev/null
@@ -0,0 +1,7 @@
+.deps
+.libs
+*.o
+*.exe
+iotest
+Makefile
+Makefile.in
diff --git a/src/IOHandler_test/server/Makefile.am b/src/IOHandler_test/server/Makefile.am
new file mode 100644 (file)
index 0000000..feda450
--- /dev/null
@@ -0,0 +1,8 @@
+##Process this file with automake to create Makefile.in
+ACLOCAL_AMFLAGS = -I m4
+
+noinst_PROGRAMS = iotest
+iotest_LDADD = ../../IOHandler/libiohandler.la
+
+iotest_SOURCES = iotest.c
+
diff --git a/src/IOHandler_test/server/iotest.c b/src/IOHandler_test/server/iotest.c
new file mode 100644 (file)
index 0000000..8894cf7
--- /dev/null
@@ -0,0 +1,81 @@
+/* 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 <string.h>
+#include "../../IOHandler/IOHandler.h"
+#include "../../IOHandler/IOSockets.h"
+#include "../../IOHandler/IOLog.h"
+
+static IOSOCKET_CALLBACK(io_callback);
+static IOLOG_CALLBACK(io_log);
+
+static struct IOSocket *irc_iofd = NULL;
+
+int main(int argc, char *argv[]) {
+       iohandler_init();
+       
+    iolog_register_callback(io_log);
+    
+    irc_iofd = iosocket_listen("0.0.0.0", 12345, io_callback);
+       
+       iohandler_run();
+       
+       return 0;
+}
+
+static IOSOCKET_CALLBACK(io_callback) {
+    switch(event->type) {
+        case IOSOCKETEVENT_ACCEPT:
+            printf("[client accepted]\n");
+                       struct IOSocket *client = event->data.accept_socket;
+                       client->callback = io_callback;
+                       
+                       char *html = "<html><head><title>Test Page</title></head><body><h1>IOHandler SSL Test</h1></body></html>";
+            iosocket_printf(client, "HTTP/1.1 200 OK\r\n");
+                       iosocket_printf(client, "Server: Apache\r\n");
+                       iosocket_printf(client, "Content-Length: %d\r\n", strlen(html));
+                       iosocket_printf(client, "Content-Type: text/html\r\n");
+                       iosocket_printf(client, "\r\n");
+                       iosocket_printf(client, "%s", html);
+                       
+            break;
+        case IOSOCKETEVENT_CLOSED:
+                       if(event->socket->listening)
+                               printf("[server closed]\n");
+                       else
+                               printf("[client disconnect]\n");
+            break;
+        case IOSOCKETEVENT_RECV:
+                       {
+                               struct IOSocketBuffer *recv_buf = event->data.recv_buf;
+                               int i;
+                               for(i = 0; i < recv_buf->bufpos; i++)
+                                       putchar(recv_buf->buffer[i]);
+                               recv_buf->bufpos = 0;
+                               printf("\n");
+            }
+            break;
+        
+        default:
+            break;
+    }
+}
+
+static IOLOG_CALLBACK(io_log) {
+       printf("%s", message);
+}