[IOMultiplexer] initial commit
[NeonServV5.git] / src / main.c
1 /* main.c - IOMultiplexer
2  * Copyright (C) 2012  Philipp Kreil (pk910)
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License 
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
16  */
17
18 #include <stdio.h>
19 #include "IOHandler.h"
20
21 static IOHANDLER_CALLBACK(io_callback);
22 static IOHANDLER_LOG_BACKEND(io_log);
23
24 int main(int argc, char *argv[]) {
25     iolog_backend = io_log;
26     
27     iohandler_connect("pk910.de", 6667, 0, NULL, io_callback);
28     
29     struct IODescriptor *iofd;
30     iofd = iohandler_add(0, IOTYPE_STDIN, NULL, io_callback);
31     iofd->read_lines = 1;
32     
33     while(1) {
34         iohandler_poll();
35     }
36 }
37
38 static IOHANDLER_CALLBACK(io_callback) {
39     switch(event->type) {
40         case IOEVENT_CONNECTED:
41             printf("[connect]\n");
42             break;
43         case IOEVENT_RECV:
44             printf("[in] %s\n", event->data.recv_str);
45             break;
46         default:
47             break;
48     }
49 }
50
51 static IOHANDLER_LOG_BACKEND(io_log) {
52     printf("%s\n", line);
53 }