[IOMultiplexerV2] added c++ interface
[NextIRCd.git] / src / IOHandler++ / IOSocket.h
1 /* IOSocket.h - IOMultiplexer v2
2  * Copyright (C) 2014  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 #ifndef _IOSocket_cpp_h
18 #define _IOSocket_cpp_h
19
20 extern "C" {
21         #define IOSOCKET_CPP
22         #include "../IOHandler/IOSockets.h"
23 }
24 #include <iostream>
25 #include <string>
26
27 struct IOSocket;
28
29 class CIOSocket {
30 public:
31         CIOSocket();
32         
33         int connect(char *hostname, unsigned int port, int ssl, char *bindhost);
34         int connect(char *hostname, unsigned int port, int ssl, char *bindhost, int flags);
35         
36         int listen(char *hostname, unsigned int port);
37         int listen(char *hostname, unsigned int port, int flags);
38         int listen_ssl(char *hostname, unsigned int port, char *certfile, char *keyfile);
39         int listen_ssl(char *hostname, unsigned int port, char *certfile, char *keyfile, int flags);
40         
41         void write(const char *data, int len);
42         void writef(const char *format, ...);
43         
44         CIOSocket accept();
45         
46         void close();
47         
48         
49         int getSSL();
50         int getIPv6();
51         int getConnected();
52         int getListening();
53         
54         
55         void socket_callback(IOSocketEvent *event);
56 protected:
57         virtual int recvEvent(const char *data, int len) { return len; };
58         virtual void recvLine(char *line) {};
59         void enableRecvLine();
60         void disableRecvLine();
61         
62         virtual void connectedEvent() {};
63         virtual void notConnectedEvent(int errid) {};
64         virtual void closedEvent(int errid) {};
65         virtual void acceptedEvent(CIOSocket *client) { client->close(); };
66         virtual void dnsErrEvent(char *errormsg) {};
67         
68 private:
69         IOSocket *iosocket;
70         
71         CIOSocket(IOSocket *iosocket);
72 };
73
74 #endif