X-Git-Url: http://git.pk910.de/?p=NextIRCd.git;a=blobdiff_plain;f=src%2FIOHandler_test%2Fserver%2Fiotest.c;fp=src%2FIOHandler_test%2Fserver%2Fiotest.c;h=8894cf7f26aad6409c146d6e4bbe49cb4fd98206;hp=0000000000000000000000000000000000000000;hb=88a5f99033da59a0865f4ca631a40fa780ebfdda;hpb=d2ac212695ab026aebc171d0d7c615f29c03a77c diff --git a/src/IOHandler_test/server/iotest.c b/src/IOHandler_test/server/iotest.c new file mode 100644 index 0000000..8894cf7 --- /dev/null +++ b/src/IOHandler_test/server/iotest.c @@ -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 . + */ + +#include +#include +#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 = "Test Page

IOHandler SSL Test

"; + 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); +}