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 <poll.h>
00024 #include <sstream>
00025 #include <string>
00026 
00027 enum InspSocketState { I_DISCONNECTED, I_CONNECTING, I_CONNECTED, I_LISTENING, I_ERROR };
00028 enum InspSocketError { I_ERR_TIMEOUT, I_ERR_SOCKET, I_ERR_CONNECT, I_ERR_BIND };
00029 
00030 class InspSocket
00031 {
00032 private:
00033         int fd;
00034         std::string host;
00035         int port;
00036         InspSocketState state;
00037         sockaddr_in addr;
00038         in_addr addy;
00039         time_t timeout_end;
00040         bool timeout;
00041         pollfd polls;
00042         char ibuf[1024];
00043         sockaddr_in client;
00044         sockaddr_in server;
00045         socklen_t length;
00046 public:
00047         InspSocket();
00048         InspSocket(int newfd);
00049         InspSocket(std::string host, int port, bool listening, unsigned long maxtime);
00050         virtual bool OnConnected();
00051         virtual void OnError(InspSocketError e);
00052         virtual int OnDisconnect();
00053         virtual bool OnDataReady();
00054         virtual void OnTimeout();
00055         virtual void OnClose();
00056         virtual char* Read();
00057         virtual int Write(std::string data);
00058         virtual int OnIncomingConnection(int newfd, char* ip);
00059         void SetState(InspSocketState s);
00060         InspSocketState GetState();
00061         bool Poll();
00062         virtual void Close();
00063         virtual ~InspSocket();
00064 };
00065 
00066 #endif

Generated on Sun Nov 27 01:43:24 2005 for InspIRCd by  doxygen 1.4.4-20050815