summaryrefslogtreecommitdiff
path: root/include/socket.h
blob: 499a4d375fa869054cc33eaaf8e73b61f7fc8fae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*       +------------------------------------+
 *       | Inspire Internet Relay Chat Daemon |
 *       +------------------------------------+
 *
 *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
 *                       E-mail:
 *                <brain@chatspike.net>
 *           	  <Craig@chatspike.net>
 *     
 * Written by Craig Edwards, Craig McLure, and others.
 * This program is free but copyrighted software; see
 *            the file COPYING for details.
 *
 * ---------------------------------------------------
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sstream>
#include <string>

enum InspSocketState { I_DISCONNECTED, I_CONNECTING, I_CONNECTED, I_LISTENING, I_ERROR };

class InspSocket
{
private:
        int fd;
	std::string host;
	int port;
	InspSocketState state;
        sockaddr_in addr;
        in_addr addy;
        time_t timeout_end;
        bool timeout;
public:
	InspSocket();
	InspSocket(std::string host, int port, bool listening, unsigned long maxtime);
	virtual int OnConnected();
	virtual int OnError();
	virtual int OnDisconnect();
	virtual int OnDataReady();
	virtual int OnIncomingConnection();
	void SetState(InspSocketState s);
	void EngineTrigger();
	virtual ~InspSocket();
};