]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/socket.h
051d9a4533f9f845bf8be7d12eb86df8dd2f3b17
[user/henk/code/inspircd.git] / include / socket.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #ifndef __INSP_SOCKET_H__
18 #define __INSP_SOCKET_H__
19
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <poll.h>
24 #include <sstream>
25 #include <string>
26
27 enum InspSocketState { I_DISCONNECTED, I_CONNECTING, I_CONNECTED, I_LISTENING, I_ERROR };
28 enum InspSocketError { I_ERR_TIMEOUT, I_ERR_SOCKET, I_ERR_CONNECT };
29
30 class InspSocket
31 {
32 private:
33         int fd;
34         std::string host;
35         int port;
36         InspSocketState state;
37         sockaddr_in addr;
38         in_addr addy;
39         time_t timeout_end;
40         bool timeout;
41         pollfd polls;
42         char ibuf[1024];
43 public:
44         InspSocket();
45         InspSocket(std::string host, int port, bool listening, unsigned long maxtime);
46         virtual bool OnConnected();
47         virtual void OnError(InspSocketError e);
48         virtual int OnDisconnect();
49         virtual bool OnDataReady();
50         virtual void OnTimeout();
51         virtual void OnClose();
52         virtual char* Read();
53         virtual int Write(std::string data);
54         virtual int OnIncomingConnection();
55         void SetState(InspSocketState s);
56         bool Poll();
57         virtual void Close();
58         virtual ~InspSocket();
59 };
60
61 #endif