Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

socket.h

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
00006  *                       E-mail:
00007  *                <brain@chatspike.net>
00008  *                <Craig@chatspike.net>
00009  *     
00010  * Written by Craig Edwards, Craig McLure, and others.
00011  * This program is free but copyrighted software; see
00012  *            the file COPYING for details.
00013  *
00014  * ---------------------------------------------------
00015  */
00016 
00017 #ifndef __INSP_SOCKET_H__
00018 #define __INSP_SOCKET_H__
00019 
00020 #include <sys/types.h>
00021 #include <sys/socket.h>
00022 #include <netinet/in.h>
00023 #include <sstream>
00024 #include <string>
00025 
00029 enum InspSocketState { I_DISCONNECTED, I_CONNECTING, I_CONNECTED, I_LISTENING, I_ERROR };
00030 
00034 enum InspSocketError { I_ERR_TIMEOUT, I_ERR_SOCKET, I_ERR_CONNECT, I_ERR_BIND };
00035 
00047 class InspSocket
00048 {
00049 private:
00050 
00054         int fd;
00055 
00059         std::string host;
00060 
00065         int port;
00066 
00072         InspSocketState state;
00073 
00078         sockaddr_in addr;
00079 
00084         in_addr addy;
00085 
00091         time_t timeout_end;
00092 
00097         bool timeout;
00098         
00106         char ibuf[16384];
00107 
00113         std::string IP;
00114 
00119         sockaddr_in client;
00120 
00125         sockaddr_in server;
00126 
00131         socklen_t length;
00132 
00133 public:
00134 
00139         InspSocket();
00140 
00149         InspSocket(int newfd, char* ip);
00150 
00160         InspSocket(std::string host, int port, bool listening, unsigned long maxtime);
00161 
00167         virtual bool OnConnected();
00168 
00175         virtual void OnError(InspSocketError e);
00176 
00181         virtual int OnDisconnect();
00182 
00195         virtual bool OnDataReady();
00196 
00204         virtual void OnTimeout();
00205 
00214         virtual void OnClose();
00215 
00221         virtual char* Read();
00222 
00228         std::string GetIP();
00229 
00236         bool Timeout(time_t current);
00237 
00243         virtual int Write(std::string data);
00244 
00258         virtual int OnIncomingConnection(int newfd, char* ip);
00259 
00265         void SetState(InspSocketState s);
00266 
00270         InspSocketState GetState();
00271 
00280         bool Poll();
00281 
00287         int GetFd();
00288 
00294         virtual void Close();
00295 
00301         virtual ~InspSocket();
00302 };
00303 
00304 #endif

Generated on Thu Dec 15 11:14:14 2005 for InspIRCd by  doxygen 1.4.4-20050815