2005-11-23 10:06:54 +00:00
|
|
|
/* +------------------------------------+
|
|
|
|
* | 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.
|
|
|
|
*
|
|
|
|
* ---------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2005-11-23 11:22:06 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
2005-11-23 10:06:54 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
2005-11-23 11:22:06 +00:00
|
|
|
enum InspSocketState { I_DISCONNECTED, I_CONNECTING, I_CONNECTED, I_LISTENING, I_ERROR };
|
2005-11-25 09:32:17 +00:00
|
|
|
enum InspSocketError { I_ERR_TIMEOUT, I_ERR_SOCKET, I_ERR_CONNECT };
|
2005-11-23 10:06:54 +00:00
|
|
|
|
|
|
|
class InspSocket
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int fd;
|
|
|
|
std::string host;
|
|
|
|
int port;
|
|
|
|
InspSocketState state;
|
2005-11-23 11:22:06 +00:00
|
|
|
sockaddr_in addr;
|
|
|
|
in_addr addy;
|
|
|
|
time_t timeout_end;
|
|
|
|
bool timeout;
|
2005-11-25 09:32:17 +00:00
|
|
|
pollfd polls;
|
|
|
|
char ibuf[1024];
|
2005-11-23 10:06:54 +00:00
|
|
|
public:
|
|
|
|
InspSocket();
|
2005-11-23 11:22:06 +00:00
|
|
|
InspSocket(std::string host, int port, bool listening, unsigned long maxtime);
|
2005-11-25 09:32:17 +00:00
|
|
|
virtual bool OnConnected();
|
|
|
|
virtual void OnError(InspSocketError e);
|
2005-11-23 10:06:54 +00:00
|
|
|
virtual int OnDisconnect();
|
2005-11-25 09:32:17 +00:00
|
|
|
virtual bool OnDataReady();
|
|
|
|
virtual void OnTimeout();
|
|
|
|
virtual void OnClose();
|
|
|
|
virtual char* Read();
|
|
|
|
virtual int Write(std::string data);
|
2005-11-23 10:06:54 +00:00
|
|
|
virtual int OnIncomingConnection();
|
2005-11-23 11:22:06 +00:00
|
|
|
void SetState(InspSocketState s);
|
2005-11-25 09:32:17 +00:00
|
|
|
bool Poll();
|
|
|
|
virtual void Close();
|
2005-11-23 11:22:06 +00:00
|
|
|
virtual ~InspSocket();
|
2005-11-23 10:06:54 +00:00
|
|
|
};
|