X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fsocket.h;h=1dd2e6827372b33fa6e2ab564418b7764d1020f9;hb=90639721625b5da867effc7dd4adec003c1bd3b4;hp=f148b8e341342d27e9b0123c3012ebc7485dfc81;hpb=f3a1d7ea4bc13126996daf10031e89fd850c5945;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/socket.h b/include/socket.h index f148b8e34..1dd2e6827 100644 --- a/include/socket.h +++ b/include/socket.h @@ -2,7 +2,7 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * Inspire is copyright (C) 2002-2004 ChatSpike-Dev. + * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. * E-mail: * * @@ -14,52 +14,50 @@ * --------------------------------------------------- */ -#ifndef __INSP_SOCKET_H__ -#define __INSP_SOCKET_H__ +#ifndef INSPIRCD_SOCKET_H +#define INSPIRCD_SOCKET_H +/* This is where we'll define wrappers for socket IO stuff, for neat winsock compatability */ + +#ifndef WIN32 + +#include +#include +#include #include #include +#include #include +#include +#include #include -#include -#include +#include +#include + +#else + +#include +#include + +#endif -enum InspSocketState { I_DISCONNECTED, I_CONNECTING, I_CONNECTED, I_LISTENING, I_ERROR }; -enum InspSocketError { I_ERR_TIMEOUT, I_ERR_SOCKET, I_ERR_CONNECT, I_ERR_BIND }; +#include "inspircd_config.h" + +/* macros to the relevant system address description structs */ +#ifdef IPV6 + +typedef struct sockaddr_in6 insp_sockaddr; +typedef struct in6_addr insp_inaddr; + +#else + +typedef struct sockaddr_in insp_sockaddr; +typedef struct in_addr insp_inaddr; + +#endif -class InspSocket -{ -private: - int fd; - std::string host; - int port; - InspSocketState state; - sockaddr_in addr; - in_addr addy; - time_t timeout_end; - bool timeout; - pollfd polls; - char ibuf[1024]; - sockaddr_in client; - sockaddr_in server; - socklen_t length; -public: - InspSocket(); - InspSocket(int newfd); - InspSocket(std::string host, int port, bool listening, unsigned long maxtime); - virtual bool OnConnected(); - virtual void OnError(InspSocketError e); - virtual int OnDisconnect(); - virtual bool OnDataReady(); - virtual void OnTimeout(); - virtual void OnClose(); - virtual char* Read(); - virtual int Write(std::string data); - virtual int OnIncomingConnection(int newfd, char* ip); - void SetState(InspSocketState s); - bool Poll(); - virtual void Close(); - virtual ~InspSocket(); -}; +int OpenTCPSocket(); +bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr); +int BindPorts(bool bail); #endif