X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2FIOHandler_test%2Fclient%2Fiotest.c;fp=src%2FIOHandler_test%2Fclient%2Fiotest.c;h=2826c4e7f1f2994f593631996392995b68ef5412;hb=db1e9413159cdfd975bf9ebcd5f43b665b13ab0b;hp=0000000000000000000000000000000000000000;hpb=70a1c9616475c6978e4fa361c4263e0916d2649e;p=IOMultiplexer.git diff --git a/src/IOHandler_test/client/iotest.c b/src/IOHandler_test/client/iotest.c new file mode 100644 index 0000000..2826c4e --- /dev/null +++ b/src/IOHandler_test/client/iotest.c @@ -0,0 +1,69 @@ +/* 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 "../../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_connect("test.pk910.de", 80, 0, NULL, io_callback); + + iohandler_run(); + + return 0; +} + +static IOSOCKET_CALLBACK(io_callback) { + switch(event->type) { + case IOSOCKETEVENT_CONNECTED: + printf("[connect]\n"); + iosocket_printf(event->socket, "GET / HTTP/1.1\r\n"); + iosocket_printf(event->socket, "Host: test.pk910.de\r\n"); + iosocket_printf(event->socket, "\r\n"); + break; + case IOSOCKETEVENT_CLOSED: + printf("[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); +}