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[65535];
00107 
00111         std::string Buffer;
00112 
00118         std::string IP;
00119 
00124         sockaddr_in client;
00125 
00130         sockaddr_in server;
00131 
00136         socklen_t length;
00137 
00140         void FlushWriteBuffer();
00141 
00142 public:
00143 
00148         InspSocket();
00149 
00158         InspSocket(int newfd, char* ip);
00159 
00169         InspSocket(std::string host, int port, bool listening, unsigned long maxtime);
00170 
00176         virtual bool OnConnected();
00177 
00184         virtual void OnError(InspSocketError e);
00185 
00190         virtual int OnDisconnect();
00191 
00204         virtual bool OnDataReady();
00205 
00213         virtual void OnTimeout();
00214 
00223         virtual void OnClose();
00224 
00230         virtual char* Read();
00231 
00237         std::string GetIP();
00238 
00245         bool Timeout(time_t current);
00246 
00252         virtual int Write(std::string data);
00253 
00267         virtual int OnIncomingConnection(int newfd, char* ip);
00268 
00274         void SetState(InspSocketState s);
00275 
00279         InspSocketState GetState();
00280 
00289         bool Poll();
00290 
00296         int GetFd();
00297 
00303         virtual void Close();
00304 
00310         virtual ~InspSocket();
00311 };
00312 
00313 #endif

Generated on Mon Dec 19 18:05:20 2005 for InspIRCd by  doxygen 1.4.4-20050815