diff options
author | maximius <none@none> | 2009-10-17 15:35:07 -0700 |
---|---|---|
committer | maximius <none@none> | 2009-10-17 15:35:07 -0700 |
commit | 26b5e033ffde3d161382fc9addbfa99738379641 (patch) | |
tree | a344f369ca32945f787a02dee35c3dbe342bed7e /dep/include/sockets | |
parent | f21f47005dcb6b76e1abc9f35fbcd03eed191bff (diff) |
*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget
--HG--
branch : trunk
Diffstat (limited to 'dep/include/sockets')
26 files changed, 7 insertions, 659 deletions
diff --git a/dep/include/sockets/Base64.h b/dep/include/sockets/Base64.h index b1fd5364fc2..7db41c27d36 100644 --- a/dep/include/sockets/Base64.h +++ b/dep/include/sockets/Base64.h @@ -4,63 +4,49 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_Base64_H #define _SOCKETS_Base64_H - #include "sockets-config.h" #ifdef _MSC_VER #pragma warning(disable:4514) #endif - #include <stdio.h> #include <string> - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /** \defgroup util Utilities */ - /** Base64 encode/decode. \ingroup util */ class Base64 { public: Base64(); - void encode(FILE *, std::string& , bool add_crlf = true); void encode(const std::string&, std::string& , bool add_crlf = true); void encode(const char *, size_t, std::string& , bool add_crlf = true); void encode(const unsigned char *, size_t, std::string& , bool add_crlf = true); - void decode(const std::string&, std::string& ); void decode(const std::string&, unsigned char *, size_t&); - size_t decode_length(const std::string& ); - private: Base64(const Base64& ) {} Base64& operator=(const Base64& ) { return *this; } @@ -68,11 +54,8 @@ static const char *bstr; static const char rstr[128]; }; - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_Base64_H - diff --git a/dep/include/sockets/Exception.h b/dep/include/sockets/Exception.h index ae48ab765ba..ac33ea1c6d6 100644 --- a/dep/include/sockets/Exception.h +++ b/dep/include/sockets/Exception.h @@ -5,55 +5,39 @@ **/ /* Copyright (C) 2007 Anders Hedstrom - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _Sockets_Exception_H #define _Sockets_Exception_H - #include <string> - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - - class Exception { public: Exception(const std::string& description); virtual ~Exception() {} - virtual const std::string ToString() const; - Exception(const Exception& ) {} // copy constructor - Exception& operator=(const Exception& ) { return *this; } // assignment operator - private: std::string m_description; - }; - - #ifdef SOCKETS_NAMESPACE } // namespace SOCKETS_NAMESPACE { #endif - #endif // _Sockets_Exception_H - diff --git a/dep/include/sockets/File.h b/dep/include/sockets/File.h index e1d00ec38c7..104f79b4d13 100644 --- a/dep/include/sockets/File.h +++ b/dep/include/sockets/File.h @@ -4,41 +4,33 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_File_H #define _SOCKETS_File_H - #include "sockets-config.h" #include "IFile.h" #include <stdio.h> - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /** IFile implementation of a disk file. \ingroup file */ class File : public IFile @@ -46,26 +38,19 @@ class File : public IFile public: File(); ~File(); - bool fopen(const std::string&, const std::string&); void fclose(); - size_t fread(char *, size_t, size_t) const; size_t fwrite(const char *, size_t, size_t); - char *fgets(char *, int) const; void fprintf(const char *format, ...); - off_t size() const; bool eof() const; - void reset_read() const; void reset_write(); - private: File(const File& ) {} // copy constructor File& operator=(const File& ) { return *this; } // assignment operator - std::string m_path; std::string m_mode; FILE *m_fil; @@ -74,12 +59,8 @@ private: }; - - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_File_H - diff --git a/dep/include/sockets/IFile.h b/dep/include/sockets/IFile.h index e1e39727b52..ef4c859427e 100644 --- a/dep/include/sockets/IFile.h +++ b/dep/include/sockets/IFile.h @@ -4,39 +4,31 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_IFile_H #define _SOCKETS_IFile_H - #include "sockets-config.h" #include <string> - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /** \defgroup file File handling */ /** Pure virtual file I/O interface. \ingroup file */ @@ -44,29 +36,20 @@ class IFile { public: virtual ~IFile() {} - virtual bool fopen(const std::string&, const std::string&) = 0; virtual void fclose() = 0; - virtual size_t fread(char *, size_t, size_t) const = 0; virtual size_t fwrite(const char *, size_t, size_t) = 0; - virtual char *fgets(char *, int) const = 0; virtual void fprintf(const char *format, ...) = 0; - virtual off_t size() const = 0; virtual bool eof() const = 0; - virtual void reset_read() const = 0; virtual void reset_write() = 0; - }; - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_IFile_H - diff --git a/dep/include/sockets/ISocketHandler.h b/dep/include/sockets/ISocketHandler.h index bb1aa42bafc..4bc72949e5e 100644 --- a/dep/include/sockets/ISocketHandler.h +++ b/dep/include/sockets/ISocketHandler.h @@ -4,25 +4,20 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -30,17 +25,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _SOCKETS_ISocketHandler_H #define _SOCKETS_ISocketHandler_H #include "sockets-config.h" - #include <list> - #include "socket_include.h" #include "Socket.h" #include "StdLog.h" - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - typedef enum { LIST_CALLONCONNECT = 0, #ifdef ENABLE_DETACH @@ -50,17 +41,14 @@ typedef enum { LIST_RETRY, LIST_CLOSE } list_t; - class SocketAddress; class Mutex; - /** Socket container class, event generator. \ingroup basic */ class ISocketHandler { friend class Socket; - public: /** Connection pool class for internal use by the ISocketHandler. \ingroup internal */ @@ -72,29 +60,22 @@ public: CopyConnection( src ); SetIsClient(); } - void OnRead() { Handler().LogError(this, "OnRead", 0, "data on hibernating socket", LOG_LEVEL_FATAL); SetCloseAndDelete(); } void OnOptions(int,int,int,SOCKET) {} - }; #endif - public: virtual ~ISocketHandler() {} - /** Get mutex reference for threadsafe operations. */ virtual Mutex& GetMutex() const = 0; - /** Register StdLog object for error callback. \param log Pointer to log class */ virtual void RegStdLog(StdLog *log) = 0; - /** Log error to log class for print out / storage. */ virtual void LogError(Socket *p,const std::string& user_text,int err,const std::string& sys_err,loglevel_t t = LOG_LEVEL_WARNING) = 0; - // ------------------------------------------------------------------------- // Socket stuff // ------------------------------------------------------------------------- @@ -108,26 +89,21 @@ public: virtual void Get(SOCKET s,bool& r,bool& w,bool& e) = 0; /** Set read/write/exception file descriptor sets (fd_set). */ virtual void Set(SOCKET s,bool bRead,bool bWrite,bool bException = true) = 0; - /** Wait for events, generate callbacks. */ virtual int Select(long sec,long usec) = 0; /** This method will not return until an event has been detected. */ virtual int Select() = 0; /** Wait for events, generate callbacks. */ virtual int Select(struct timeval *tsel) = 0; - /** Check that a socket really is handled by this socket handler. */ virtual bool Valid(Socket *) = 0; /** Return number of sockets handled by this handler. */ virtual size_t GetCount() = 0; - /** Override and return false to deny all incoming connections. \param p ListenSocket class pointer (use GetPort to identify which one) */ virtual bool OkToAccept(Socket *p) = 0; - /** Called by Socket when a socket changes state. */ virtual void AddList(SOCKET s,list_t which_one,bool add) = 0; - // ------------------------------------------------------------------------- // Connection pool // ------------------------------------------------------------------------- @@ -140,7 +116,6 @@ public: \return true if connection pool is enabled */ virtual bool PoolEnabled() = 0; #endif // ENABLE_POOL - // ------------------------------------------------------------------------- // Socks4 // ------------------------------------------------------------------------- @@ -168,7 +143,6 @@ public: \return true if direct connection should be tried if connection to socks4 server fails */ virtual bool Socks4TryDirect() = 0; #endif // ENABLE_SOCKS4 - // ------------------------------------------------------------------------- // DNS resolve server // ------------------------------------------------------------------------- @@ -198,7 +172,6 @@ public: /** Returns true if socket waiting for a resolve event. */ virtual bool Resolving(Socket *) = 0; #endif // ENABLE_RESOLVER - #ifdef ENABLE_TRIGGERS /** Fetch unique trigger id. */ virtual int TriggerID(Socket *src) = 0; @@ -213,21 +186,16 @@ public: Leave them in place if 'false' - if a trigger should be called many times */ virtual void Trigger(int id, Socket::TriggerData& data, bool erase = true) = 0; #endif // ENABLE_TRIGGERS - #ifdef ENABLE_DETACH /** Indicates that the handler runs under SocketThread. */ virtual void SetSlave(bool x = true) = 0; /** Indicates that the handler runs under SocketThread. */ virtual bool IsSlave() = 0; #endif // ENABLE_DETACH - }; - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_ISocketHandler_H - diff --git a/dep/include/sockets/Ipv4Address.h b/dep/include/sockets/Ipv4Address.h index ba2292425a0..5a8d9a6ce20 100644 --- a/dep/include/sockets/Ipv4Address.h +++ b/dep/include/sockets/Ipv4Address.h @@ -5,33 +5,27 @@ **/ /* Copyright (C) 2007 Anders Hedstrom - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_Ipv4Address_H #define _SOCKETS_Ipv4Address_H - #include "sockets-config.h" #include "SocketAddress.h" - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /* Ipv4 address implementation. \ingroup basic */ class Ipv4Address : public SocketAddress @@ -54,33 +48,25 @@ public: Ipv4Address(const std::string& host,port_t port); Ipv4Address(struct sockaddr_in&); ~Ipv4Address(); - // SocketAddress implementation - operator struct sockaddr *(); operator socklen_t(); bool operator==(SocketAddress&); - void SetPort(port_t port); port_t GetPort(); - void SetAddress(struct sockaddr *sa); int GetFamily(); - bool IsValid(); std::auto_ptr<SocketAddress> GetCopy(); - /** Convert address struct to text. */ std::string Convert(bool include_port = false); std::string Reverse(); - /** Resolve hostname. */ static bool Resolve(const std::string& hostname,struct in_addr& a); /** Reverse resolve (IP to hostname). */ static bool Reverse(struct in_addr& a,std::string& name); /** Convert address struct to text. */ static std::string Convert(struct in_addr& a); - private: Ipv4Address(const Ipv4Address& ) {} // copy constructor Ipv4Address& operator=(const Ipv4Address& ) { return *this; } // assignment operator @@ -89,11 +75,8 @@ private: }; - - #ifdef SOCKETS_NAMESPACE } // namespace SOCKETS_NAMESPACE { #endif #endif // _SOCKETS_Ipv4Address_H - diff --git a/dep/include/sockets/Ipv6Address.h b/dep/include/sockets/Ipv6Address.h index 9bd651786bc..b1a6afa98c6 100644 --- a/dep/include/sockets/Ipv6Address.h +++ b/dep/include/sockets/Ipv6Address.h @@ -5,17 +5,14 @@ **/ /* Copyright (C) 2007 Anders Hedstrom - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -24,18 +21,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define _SOCKETS_Ipv6Address_H #include "sockets-config.h" #ifdef ENABLE_IPV6 - #include "SocketAddress.h" #ifdef IPPROTO_IPV6 #if defined( _WIN32) && !defined(__CYGWIN__) typedef unsigned __int32 uint32_t; #endif - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /** Ipv6 address implementation. \ingroup basic */ class Ipv6Address : public SocketAddress @@ -54,40 +48,31 @@ public: Ipv6Address(const std::string& host,port_t port); Ipv6Address(struct sockaddr_in6&); ~Ipv6Address(); - // SocketAddress implementation - operator struct sockaddr *(); operator socklen_t(); bool operator==(SocketAddress&); - void SetPort(port_t port); port_t GetPort(); - void SetAddress(struct sockaddr *sa); int GetFamily(); - bool IsValid(); std::auto_ptr<SocketAddress> GetCopy(); - /** Convert address struct to text. */ std::string Convert(bool include_port = false); std::string Reverse(); - /** Resolve hostname. */ static bool Resolve(const std::string& hostname,struct in6_addr& a); /** Reverse resolve (IP to hostname). */ static bool Reverse(struct in6_addr& a,std::string& name); /** Convert address struct to text. */ static std::string Convert(struct in6_addr& a,bool mixed = false); - void SetFlowinfo(uint32_t); uint32_t GetFlowinfo(); #ifndef _WIN32 void SetScopeId(uint32_t); uint32_t GetScopeId(); #endif - private: Ipv6Address(const Ipv6Address& ) {} // copy constructor Ipv6Address& operator=(const Ipv6Address& ) { return *this; } // assignment operator @@ -96,8 +81,6 @@ private: }; - - #ifdef SOCKETS_NAMESPACE } // namespace SOCKETS_NAMESPACE { #endif @@ -105,4 +88,3 @@ private: #endif // ENABLE_IPV6 #endif // _SOCKETS_Ipv6Address_H - diff --git a/dep/include/sockets/ListenSocket.h b/dep/include/sockets/ListenSocket.h index 80aa48f20b4..aeb5bf028f2 100644 --- a/dep/include/sockets/ListenSocket.h +++ b/dep/include/sockets/ListenSocket.h @@ -4,25 +4,20 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -30,13 +25,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _SOCKETS_ListenSocket_H #define _SOCKETS_ListenSocket_H #include "sockets-config.h" - #ifdef _WIN32 #include <stdlib.h> #else #include <errno.h> #endif - #include "ISocketHandler.h" #include "Socket.h" #include "Utility.h" @@ -46,12 +39,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifdef ENABLE_EXCEPTIONS #include "Exception.h" #endif - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /** Binds incoming port number to new Socket class X. \ingroup basic */ template <class X> @@ -84,7 +75,6 @@ public: delete m_creator; } } - /** Close file descriptor. */ int Close() { if (GetSocket() != INVALID_SOCKET) @@ -93,7 +83,6 @@ public: } return 0; } - /** Bind and listen to any interface. \param port Port (0 is random) \param depth Listen queue depth */ @@ -113,7 +102,6 @@ public: return Bind(ad, depth); } } - int Bind(SocketAddress& ad,int depth) { #ifdef USE_SCTP if (dynamic_cast<SctpSocket *>(m_creator)) @@ -123,7 +111,6 @@ public: #endif return Bind(ad, "tcp", depth); } - /** Bind and listen to any interface, with optional protocol. \param port Port (0 is random) \param protocol Network protocol @@ -144,7 +131,6 @@ public: return Bind(ad, protocol, depth); } } - /** Bind and listen to specific interface. \param intf Interface hostname \param port Port (0 is random) @@ -175,7 +161,6 @@ public: return -1; } } - /** Bind and listen to specific interface. \param intf Interface hostname \param port Port (0 is random) @@ -207,7 +192,6 @@ public: return -1; } } - /** Bind and listen to ipv4 interface. \param a Ipv4 interface address \param port Port (0 is random) @@ -231,7 +215,6 @@ public: Ipv4Address ad(a, port); return Bind(ad, protocol, depth); } - #ifdef ENABLE_IPV6 #ifdef IPPROTO_IPV6 /** Bind and listen to ipv6 interface. @@ -259,7 +242,6 @@ public: } #endif #endif - /** Bind and listen to network interface. \param ad Interface address \param protocol Network protocol @@ -292,26 +274,22 @@ public: Attach(s); return 0; } - /** Return assigned port number. */ port_t GetPort() { return GetSockPort(); } - /** Return listen queue depth. */ int GetDepth() { return m_depth; } - /** OnRead on a ListenSocket receives an incoming connection. */ void OnRead() { struct sockaddr sa; socklen_t sa_len = sizeof(struct sockaddr); SOCKET a_s = accept(GetSocket(), &sa, &sa_len); - if (a_s == INVALID_SOCKET) { Handler().LogError(this, "accept", Errno, StrError(Errno), LOG_LEVEL_ERROR); @@ -387,20 +365,16 @@ public: tmp -> OnAccept(); } } - /** Please don't use this method. "accept()" is handled automatically in the OnRead() method. */ virtual SOCKET Accept(SOCKET socket, struct sockaddr *saptr, socklen_t *lenptr) { return accept(socket, saptr, lenptr); } - bool HasCreator() { return m_bHasCreate; } - void OnOptions(int,int,int,SOCKET) { SetSoReuseaddr(true); } - protected: ListenSocket(const ListenSocket& s) : Socket(s) {} private: @@ -410,12 +384,8 @@ private: bool m_bHasCreate; }; - - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_ListenSocket_H - diff --git a/dep/include/sockets/Lock.h b/dep/include/sockets/Lock.h index e819537ef26..f2d9e6fb713 100644 --- a/dep/include/sockets/Lock.h +++ b/dep/include/sockets/Lock.h @@ -4,39 +4,31 @@ **/ /* Copyright (C) 2005,2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_Lock_H #define _SOCKETS_Lock_H - #include "sockets-config.h" #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - class Mutex; - /** Mutex encapsulation class. \ingroup threading */ class Lock @@ -44,17 +36,13 @@ class Lock public: Lock(Mutex&); ~Lock(); - private: Mutex& m_mutex; }; - - #ifdef SOCKETS_NAMESPACE } #endif #endif // _SOCKETS_Lock_H - diff --git a/dep/include/sockets/Mutex.h b/dep/include/sockets/Mutex.h index 8fce2ce08ba..4dba5e7b401 100644 --- a/dep/include/sockets/Mutex.h +++ b/dep/include/sockets/Mutex.h @@ -4,43 +4,35 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_Mutex_H #define _SOCKETS_Mutex_H - #include "sockets-config.h" #ifndef _WIN32 #include <pthread.h> #else #include <windows.h> #endif - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /** Mutex container class, used by Lock. \ingroup threading */ class Mutex @@ -49,7 +41,6 @@ class Mutex public: Mutex(); ~Mutex(); - void Lock(); void Unlock(); private: @@ -60,10 +51,8 @@ private: #endif }; - #ifdef SOCKETS_NAMESPACE } #endif #endif // _SOCKETS_Mutex_H - diff --git a/dep/include/sockets/Parse.h b/dep/include/sockets/Parse.h index 4b42ea768b2..6ad4d44290c 100644 --- a/dep/include/sockets/Parse.h +++ b/dep/include/sockets/Parse.h @@ -2,51 +2,39 @@ ** ** Written: 1999-Feb-10 grymse@alhem.net **/ - /* Copyright (C) 1999-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - #ifndef _SOCKETS_Parse_H #define _SOCKETS_Parse_H - #include "sockets-config.h" #ifdef _MSC_VER #pragma warning(disable:4514) #endif - #include <string> - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /***************************************************/ /* interface of class Parse */ - /** Splits a string whatever way you want. \ingroup util */ class Parse @@ -79,7 +67,6 @@ public: void getline(std::string&); size_t getptr() { return pa_the_ptr; } void EnableQuote(bool b) { pa_quote = b; } - private: std::string pa_the_str; std::string pa_splits; @@ -92,11 +79,8 @@ private: bool pa_quote; }; - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_Parse_H - diff --git a/dep/include/sockets/ResolvServer.h b/dep/include/sockets/ResolvServer.h index b713a8ad382..fb3f5ec1527 100644 --- a/dep/include/sockets/ResolvServer.h +++ b/dep/include/sockets/ResolvServer.h @@ -4,25 +4,20 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -33,11 +28,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifdef ENABLE_RESOLVER #include "socket_include.h" #include "Thread.h" - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /** \defgroup async Asynchronous DNS */ /** Async DNS resolver thread. \ingroup async */ @@ -46,29 +39,21 @@ class ResolvServer : public Thread public: ResolvServer(port_t); ~ResolvServer(); - void Run(); void Quit(); - bool Ready(); - private: ResolvServer(const ResolvServer& ) {} // copy constructor ResolvServer& operator=(const ResolvServer& ) { return *this; } // assignment operator - bool m_quit; port_t m_port; bool m_ready; }; - - #ifdef SOCKETS_NAMESPACE } #endif - #endif // ENABLE_RESOLVER #endif // _SOCKETS_ResolvServer_H - diff --git a/dep/include/sockets/ResolvSocket.h b/dep/include/sockets/ResolvSocket.h index 38ff3335c28..2347f040a7a 100644 --- a/dep/include/sockets/ResolvSocket.h +++ b/dep/include/sockets/ResolvSocket.h @@ -4,25 +4,20 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -33,13 +28,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifdef ENABLE_RESOLVER #include "TcpSocket.h" #include <map> - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - class Mutex; - /** Async DNS resolver socket. \ingroup async */ class ResolvSocket : public TcpSocket @@ -48,7 +40,6 @@ class ResolvSocket : public TcpSocket std::map<std::string, std::string> > cache_t; /* host, result */ typedef std::map<std::string, /* type */ std::map<std::string, time_t> > timeout_t; /* host, time */ - public: ResolvSocket(ISocketHandler&); ResolvSocket(ISocketHandler&, Socket *parent, const std::string& host, port_t port, bool ipv6 = false); @@ -57,25 +48,19 @@ public: ResolvSocket(ISocketHandler&, Socket *parent, in6_addr&); #endif ~ResolvSocket(); - void OnAccept() { m_bServer = true; } void OnLine(const std::string& line); void OnDetached(); void OnDelete(); - void SetId(int x) { m_resolv_id = x; } int GetId() { return m_resolv_id; } - void OnConnect(); - #ifdef ENABLE_IPV6 void SetResolveIpv6(bool x = true) { m_resolve_ipv6 = x; } #endif - private: ResolvSocket(const ResolvSocket& s) : TcpSocket(s) {} // copy constructor ResolvSocket& operator=(const ResolvSocket& ) { return *this; } // assignment operator - std::string m_query; std::string m_data; bool m_bServer; @@ -95,13 +80,9 @@ private: }; - - #ifdef SOCKETS_NAMESPACE } #endif - #endif // ENABLE_RESOLVER #endif // _SOCKETS_ResolvSocket_H - diff --git a/dep/include/sockets/SctpSocket.h b/dep/include/sockets/SctpSocket.h index 50757fc4b13..b3fdd9ae1ab 100644 --- a/dep/include/sockets/SctpSocket.h +++ b/dep/include/sockets/SctpSocket.h @@ -5,17 +5,14 @@ **/ /* Copyright (C) 2007 Anders Hedstrom - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -23,20 +20,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _SOCKETS_SctpSocket_H #define _SOCKETS_SctpSocket_H #include "sockets-config.h" - #include "StreamSocket.h" #ifdef USE_SCTP #include <netinet/sctp.h> - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - #define SCTP_BUFSIZE_READ 16400 - class SocketAddress; - class SctpSocket : public StreamSocket { public: @@ -45,7 +37,6 @@ public: \param type SCTP_STREAM or SCTP_SEQPACKET */ SctpSocket(ISocketHandler& h,int type); ~SctpSocket(); - /** bind() */ int Bind(const std::string&,port_t); int Bind(SocketAddress&); @@ -55,56 +46,43 @@ public: /** sctp_bindx() */ int RemoveAddress(const std::string&,port_t); int RemoveAddress(SocketAddress&); - /** connect() */ int Open(const std::string&,port_t); int Open(SocketAddress&); - /** Connect timeout callback. */ void OnConnectTimeout(); #ifdef _WIN32 /** Connection failed reported as exception on win32 */ void OnException(); #endif - #ifndef SOLARIS /** sctp_connectx() */ int AddConnection(const std::string&,port_t); int AddConnection(SocketAddress&); #endif - /** Get peer addresses of an association. */ int getpaddrs(sctp_assoc_t id,std::list<std::string>&); /** Get all bound addresses of an association. */ int getladdrs(sctp_assoc_t id,std::list<std::string>&); - /** sctp_peeloff */ int PeelOff(sctp_assoc_t id); - /** recvmsg callback */ virtual void OnReceiveMessage(const char *buf,size_t sz,struct sockaddr *sa,socklen_t sa_len,struct sctp_sndrcvinfo *sinfo,int msg_flags) = 0; - void OnOptions(int,int,int,SOCKET) {} - virtual int Protocol(); - protected: SctpSocket(const SctpSocket& s) : StreamSocket(s) {} void OnRead(); void OnWrite(); - private: SctpSocket& operator=(const SctpSocket& s) { return *this; } int m_type; ///< SCTP_STREAM or SCTP_SEQPACKET char *m_buf; ///< Temporary receive buffer }; - #ifdef SOCKETS_NAMESPACE } // namespace SOCKETS_NAMESPACE #endif - #endif // USE_SCTP #endif // _SOCKETS_SctpSocket_H - diff --git a/dep/include/sockets/Socket.h b/dep/include/sockets/Socket.h index 8a7fdc9d2fd..cb1c2fb3c29 100644 --- a/dep/include/sockets/Socket.h +++ b/dep/include/sockets/Socket.h @@ -4,25 +4,20 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This software is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -30,30 +25,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _SOCKETS_Socket_H #define _SOCKETS_Socket_H #include "sockets-config.h" - #include <string> #include <vector> #include <list> #ifdef HAVE_OPENSSL #include <openssl/ssl.h> #endif - #include "socket_include.h" #include <time.h> #include "SocketAddress.h" #include "Thread.h" - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - class ISocketHandler; class SocketAddress; class IFile; - /** \defgroup basic Basic sockets */ /** Socket base class. \ingroup basic */ @@ -68,9 +58,7 @@ class Socket public: SocketThread(Socket *p); ~SocketThread(); - void Run(); - private: Socket *GetSocket() const { return m_socket; } SocketThread(const SocketThread& s) : m_socket(s.GetSocket()) {} @@ -78,7 +66,6 @@ class Socket Socket *m_socket; }; #endif // ENABLE_DETACH - #ifdef ENABLE_TRIGGERS public: /** Data pass class from source to destination. */ @@ -87,15 +74,12 @@ public: public: TriggerData() : m_src(NULL) {} virtual ~TriggerData() {} - Socket *GetSource() const { return m_src; } void SetSource(Socket *x) { m_src = x; } - private: Socket *m_src; }; #endif // ENABLE_TRIGGERS - /** Socket mode flags. */ /* enum { @@ -104,20 +88,17 @@ public: SOCK_CLOSE = 0x02, ///< Close and delete flag SOCK_DISABLE_READ = 0x04, ///< Disable checking for read events SOCK_CONNECTED = 0x08, ///< Socket is connected (tcp/udp) - SOCK_ERASED_BY_HANDLER = 0x10, ///< Set by handler before delete // HAVE_OPENSSL SOCK_ENABLE_SSL = 0x20, ///< Enable SSL for this TcpSocket SOCK_SSL = 0x40, ///< ssl negotiation mode (TcpSocket) SOCK_SSL_SERVER = 0x80, ///< True if this is an incoming ssl TcpSocket connection - // ENABLE_IPV6 SOCK_IPV6 = 0x0100, ///< This is an ipv6 socket if this one is true // ENABLE_POOL SOCK_CLIENT = 0x0200, ///< only client connections are pooled SOCK_RETAIN = 0x0400, ///< keep connection on close SOCK_LOST = 0x0800, ///< connection lost - // ENABLE_SOCKS4 SOCK_SOCKS4 = 0x1000, ///< socks4 negotiation mode (TcpSocket) // ENABLE_DETACH @@ -125,38 +106,30 @@ public: SOCK_DETACHED = 0x4000, ///< Socket has been detached // StreamSocket STREAMSOCK_CONNECTING = 0x8000, ///< Flag indicating connection in progress - STREAMSOCK_FLUSH_BEFORE_CLOSE = 0x010000L, ///< Send all data before closing (default true) STREAMSOCK_CALL_ON_CONNECT = 0x020000L, ///< OnConnect will be called next ISocketHandler cycle if true STREAMSOCK_RETRY_CONNECT = 0x040000L, ///< Try another connection attempt next ISocketHandler cycle STREAMSOCK_LINE_PROTOCOL = 0x080000L, ///< Line protocol mode flag - }; */ - public: /** "Default" constructor */ Socket(ISocketHandler&); - virtual ~Socket(); - /** Socket class instantiation method. Used when a "non-standard" constructor * needs to be used for the socket class. Note: the socket class still needs * the "default" constructor with one ISocketHandler& as input parameter. */ virtual Socket *Create() { return NULL; } - /** Returns reference to sockethandler that owns the socket. If the socket is detached, this is a reference to the slave sockethandler. */ ISocketHandler& Handler() const; - /** Returns reference to sockethandler that owns the socket. This one always returns the reference to the original sockethandler, even if the socket is detached. */ ISocketHandler& MasterHandler() const; - /** Called by ListenSocket after accept but before socket is added to handler. * CTcpSocket uses this to create its ICrypt member variable. * The ICrypt member variable is created by a virtual method, therefore @@ -165,83 +138,59 @@ public: * or ssl (port 443). */ virtual void Init(); - /** Create a socket file descriptor. \param af Address family AF_INET / AF_INET6 / ... \param type SOCK_STREAM / SOCK_DGRAM / ... \param protocol "tcp" / "udp" / ... */ SOCKET CreateSocket(int af,int type,const std::string& protocol = ""); - /** Assign this socket a file descriptor created by a call to socket() or otherwise. */ void Attach(SOCKET s); - /** Return file descriptor assigned to this socket. */ SOCKET GetSocket(); - /** Close connection immediately - internal use. \sa SetCloseAndDelete */ virtual int Close(); - /** Add file descriptor to sockethandler fd_set's. */ void Set(bool bRead,bool bWrite,bool bException = true); - /** Returns true when socket file descriptor is valid and socket is not about to be closed. */ virtual bool Ready(); - /** Returns pointer to ListenSocket that created this instance * on an incoming connection. */ Socket *GetParent(); - /** Used by ListenSocket to set parent pointer of newly created * socket instance. */ void SetParent(Socket *); - /** Get listening port from ListenSocket<>. */ virtual port_t GetPort(); - /** Set socket non-block operation. */ bool SetNonblocking(bool); - /** Set socket non-block operation. */ bool SetNonblocking(bool, SOCKET); - /** Total lifetime of instance. */ time_t Uptime(); - /** Set address/port of last connect() call. */ void SetClientRemoteAddress(SocketAddress&); - /** Get address/port of last connect() call. */ std::auto_ptr<SocketAddress> GetClientRemoteAddress(); - /** Common interface for SendBuf used by Tcp and Udp sockets. */ virtual void SendBuf(const char *,size_t,int = 0); - /** Common interface for Send used by Tcp and Udp sockets. */ virtual void Send(const std::string&,int = 0); - /** Outgoing traffic counter. */ virtual uint64_t GetBytesSent(bool clear = false); - /** Incoming traffic counter. */ virtual uint64_t GetBytesReceived(bool clear = false); - // LIST_TIMEOUT - /** Enable timeout control. 0=disable timeout check. */ void SetTimeout(time_t secs); - /** Check timeout. \return true if time limit reached */ bool Timeout(time_t tnow); - /** Used by ListenSocket. ipv4 and ipv6 */ void SetRemoteAddress(SocketAddress&); - /** \name Event callbacks */ //@{ - /** Called when there is something to be read from the file descriptor. */ virtual void OnRead(); /** Called when there is room for another write on the file descriptor. */ @@ -279,7 +228,6 @@ public: /** Connection timeout. */ virtual void OnConnectTimeout(); //@} - /** \name Socket mode flags, set/reset */ //@{ /** Set delete by handler true when you want the sockethandler to @@ -288,43 +236,34 @@ public: /** Check delete by handler flag. \return true if this instance should be deleted by the sockethandler */ bool DeleteByHandler(); - // LIST_CLOSE - conditional event queue - /** Set close and delete to terminate the connection. */ void SetCloseAndDelete(bool = true); /** Check close and delete flag. \return true if this socket should be closed and the instance removed */ bool CloseAndDelete(); - /** Return number of seconds since socket was ordered to close. \sa SetCloseAndDelete */ time_t TimeSinceClose(); - /** Ignore read events for an output only socket. */ void DisableRead(bool x = true); /** Check ignore read events flag. \return true if read events should be ignored */ bool IsDisableRead(); - /** Set connected status. */ void SetConnected(bool = true); /** Check connected status. \return true if connected */ bool IsConnected(); - /** Connection lost - error while reading/writing from a socket - TcpSocket only. */ void SetLost(); /** Check connection lost status flag, used by TcpSocket only. \return true if there was an error while r/w causing the socket to close */ bool Lost(); - /** Set flag indicating the socket is being actively deleted by the sockethandler. */ void SetErasedByHandler(bool x = true); /** Get value of flag indicating socket is deleted by sockethandler. */ bool ErasedByHandler(); - //@} - /** \name Information about remote connection */ //@{ /** Returns address of remote end. */ @@ -344,7 +283,6 @@ public: /** ipv4 and ipv6(not implemented) */ std::string GetRemoteHostname(); //@} - /** Returns local port number for bound socket file descriptor. */ port_t GetSockPort(); /** Returns local ipv4 address for bound socket file descriptor. */ @@ -366,10 +304,8 @@ public: checked with an #ifdef below. This might cause a compile error on other operating systems. */ // -------------------------------------------------------------------------- - // IP options //@{ - bool SetIpOptions(const void *p, socklen_t len); bool SetIpTOS(unsigned char tos); unsigned char IpTOS(); @@ -381,7 +317,6 @@ public: bool SetMulticastLoop(bool x = true); bool IpAddMembership(struct ip_mreq&); bool IpDropMembership(struct ip_mreq&); - #ifdef IP_PKTINFO bool SetIpPktinfo(bool x = true); #endif @@ -416,11 +351,9 @@ public: bool IpDropMembership(struct ip_mreqn&); #endif //@} - // SOCKET options /** @name Socket Options */ //@{ - bool SoAcceptconn(); bool SetSoBroadcast(bool x = true); bool SetSoDebug(bool x = true); @@ -439,7 +372,6 @@ public: int SoType(); bool SetSoReuseaddr(bool x = true); bool SetSoKeepalive(bool x = true); - #ifdef SO_BSDCOMPAT bool SetSoBsdcompat(bool x = true); #endif @@ -468,10 +400,8 @@ public: bool SetSoNosigpipe(bool x = true); #endif //@} - // TCP options in TcpSocket.h/TcpSocket.cpp - #ifdef HAVE_OPENSSL /** @name SSL Support */ //@{ @@ -506,7 +436,6 @@ public: virtual SSL *GetSsl() { return NULL; } //@} #endif // HAVE_OPENSSL - #ifdef ENABLE_IPV6 /** Enable ipv6 for this socket. */ void SetIpv6(bool x = true); @@ -514,7 +443,6 @@ public: \return true if this is an ipv6 socket */ bool IsIpv6(); #endif - #ifdef ENABLE_POOL /** @name Connection Pool */ //@{ @@ -542,7 +470,6 @@ public: void CopyConnection(Socket *sock); //@} #endif // ENABLE_POOL - #ifdef ENABLE_SOCKS4 /** \name Socks4 support */ //@{ @@ -558,7 +485,6 @@ public: bool Socks4(); /** Set flag indicating Socks4 handshaking in progress */ void SetSocks4(bool x = true); - /** Set socks4 server host address to use */ void SetSocks4Host(ipaddr_t a); /** Set socks4 server hostname to use. */ @@ -578,7 +504,6 @@ public: const std::string& GetSocks4Userid(); //@} #endif // ENABLE_SOCKS4 - #ifdef ENABLE_RESOLVER /** \name Asynchronous Resolver */ //@{ @@ -613,7 +538,6 @@ public: virtual void OnResolveFailed(int id); //@} #endif // ENABLE_RESOLVER - #ifdef ENABLE_DETACH /** \name Thread Support */ //@{ @@ -621,15 +545,12 @@ public: socket is ready for operation again. \sa ResolvSocket */ virtual void OnDetached(); - // LIST_DETACH - /** Internal use. */ void SetDetach(bool x = true); /** Check detach flag. \return true if the socket should detach to its own thread */ bool IsDetach(); - /** Internal use. */ void SetDetached(bool x = true); /** Check detached flag. @@ -644,10 +565,8 @@ public: void DetachSocket(); //@} #endif // ENABLE_DETACH - /** Write traffic to an IFile. Socket will not delete this object. */ void SetTrafficMonitor(IFile *p) { m_traffic_monitor = p; } - #ifdef ENABLE_TRIGGERS /** \name Triggers */ //@{ @@ -661,21 +580,16 @@ public: virtual void OnCancelled(int id); //@} #endif - protected: /** default constructor not available */ Socket() : m_handler(m_handler) {} /** copy constructor not available */ Socket(const Socket& s) : m_handler(s.m_handler) {} - /** assignment operator not available. */ Socket& operator=(const Socket& ) { return *this; } - /** All traffic will be written to this IFile, if set. */ IFile *GetTrafficMonitor() { return m_traffic_monitor; } - // unsigned long m_flags; ///< boolean flags, replacing old 'bool' members - private: ISocketHandler& m_handler; ///< Reference of ISocketHandler in control of this socket SOCKET m_socket; ///< File descriptor @@ -693,35 +607,29 @@ private: time_t m_timeout_start; ///< Set by SetTimeout time_t m_timeout_limit; ///< Defined by SetTimeout bool m_bLost; ///< connection lost - #ifdef _WIN32 static WSAInitializer m_winsock_init; ///< Winsock initialization singleton class #endif - #ifdef HAVE_OPENSSL bool m_b_enable_ssl; ///< Enable SSL for this TcpSocket bool m_b_ssl; ///< ssl negotiation mode (TcpSocket) bool m_b_ssl_server; ///< True if this is an incoming ssl TcpSocket connection #endif - #ifdef ENABLE_IPV6 bool m_ipv6; ///< This is an ipv6 socket if this one is true #endif - #ifdef ENABLE_POOL int m_socket_type; ///< Type of socket, from socket() call std::string m_socket_protocol; ///< Protocol, from socket() call bool m_bClient; ///< only client connections are pooled bool m_bRetain; ///< keep connection on close #endif - #ifdef ENABLE_SOCKS4 bool m_bSocks4; ///< socks4 negotiation mode (TcpSocket) ipaddr_t m_socks4_host; ///< socks4 server address port_t m_socks4_port; ///< socks4 server port number std::string m_socks4_userid; ///< socks4 server usedid #endif - #ifdef ENABLE_DETACH bool m_detach; ///< Socket ordered to detach flag bool m_detached; ///< Socket has been detached @@ -729,12 +637,9 @@ static WSAInitializer m_winsock_init; ///< Winsock initialization singleton cla ISocketHandler *m_slave_handler; ///< Actual sockethandler while detached #endif }; - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_Socket_H - diff --git a/dep/include/sockets/SocketAddress.h b/dep/include/sockets/SocketAddress.h index 496600b112c..af7aaa3a03d 100644 --- a/dep/include/sockets/SocketAddress.h +++ b/dep/include/sockets/SocketAddress.h @@ -5,34 +5,28 @@ **/ /* Copyright (C) 2007 Anders Hedstrom - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_SocketAddress_H #define _SOCKETS_SocketAddress_H - #include "sockets-config.h" #include <string> #include <memory> #include "socket_include.h" - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /** This class and its subclasses is intended to be used as replacement for the internal data type 'ipaddr_t' and various implementations of @@ -47,50 +41,36 @@ class SocketAddress { public: virtual ~SocketAddress() {} - /** Get a pointer to the address struct. */ virtual operator struct sockaddr *() = 0; - /** Get length of address struct. */ virtual operator socklen_t() = 0; - /** Compare two addresses. */ virtual bool operator==(SocketAddress&) = 0; - /** Set port number. \param port Port number in host byte order */ virtual void SetPort(port_t port) = 0; - /** Get port number. \return Port number in host byte order. */ virtual port_t GetPort() = 0; - /** Set socket address. \param sa Pointer to either 'struct sockaddr_in' or 'struct sockaddr_in6'. */ virtual void SetAddress(struct sockaddr *sa) = 0; - /** Convert address to text. */ virtual std::string Convert(bool include_port) = 0; - /** Reverse lookup of address. */ virtual std::string Reverse() = 0; - /** Get address family. */ virtual int GetFamily() = 0; - /** Address structure is valid. */ virtual bool IsValid() = 0; - /** Get a copy of this SocketAddress object. */ virtual std::auto_ptr<SocketAddress> GetCopy() = 0; }; - - #ifdef SOCKETS_NAMESPACE } // namespace SOCKETS_NAMESPACE { #endif #endif // _SOCKETS_SocketAddress_H - diff --git a/dep/include/sockets/SocketHandler.h b/dep/include/sockets/SocketHandler.h index 1812c9c386f..e187de5f675 100644 --- a/dep/include/sockets/SocketHandler.h +++ b/dep/include/sockets/SocketHandler.h @@ -4,50 +4,40 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_SocketHandler_H #define _SOCKETS_SocketHandler_H - #include "sockets-config.h" #include <map> #include <list> - #include "socket_include.h" #include "ISocketHandler.h" - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - class Socket; #ifdef ENABLE_RESOLVER class ResolvServer; #endif class Mutex; - /** Socket container class, event generator. \ingroup basic */ class SocketHandler : public ISocketHandler @@ -55,60 +45,43 @@ class SocketHandler : public ISocketHandler protected: /** Map type for holding file descriptors/socket object pointers. */ typedef std::map<SOCKET,Socket *> socket_m; - public: /** SocketHandler constructor. \param log Optional log class pointer */ SocketHandler(StdLog *log = NULL); - /** SocketHandler threadsafe constructor. \param mutex Externally declared mutex variable \param log Optional log class pointer */ SocketHandler(Mutex& mutex,StdLog *log = NULL); - ~SocketHandler(); - /** Get mutex reference for threadsafe operations. */ Mutex& GetMutex() const; - /** Register StdLog object for error callback. \param log Pointer to log class */ void RegStdLog(StdLog *log); - /** Log error to log class for print out / storage. */ void LogError(Socket *p,const std::string& user_text,int err,const std::string& sys_err,loglevel_t t = LOG_LEVEL_WARNING); - /** Add socket instance to socket map. Removal is always automatic. */ void Add(Socket *); - /** Get status of read/write/exception file descriptor set for a socket. */ void Get(SOCKET s,bool& r,bool& w,bool& e); - /** Set read/write/exception file descriptor sets (fd_set). */ void Set(SOCKET s,bool bRead,bool bWrite,bool bException = true); - /** Wait for events, generate callbacks. */ int Select(long sec,long usec); - /** This method will not return until an event has been detected. */ int Select(); - /** Wait for events, generate callbacks. */ int Select(struct timeval *tsel); - /** Check that a socket really is handled by this socket handler. */ bool Valid(Socket *); - /** Return number of sockets handled by this handler. */ size_t GetCount(); - /** Override and return false to deny all incoming connections. \param p ListenSocket class pointer (use GetPort to identify which one) */ bool OkToAccept(Socket *p); - /** Called by Socket when a socket changes state. */ void AddList(SOCKET s,list_t which_one,bool add); - // Connection pool #ifdef ENABLE_POOL /** Find available open connection (used by connection pool). */ @@ -119,7 +92,6 @@ public: \return true if connection pool is enabled */ bool PoolEnabled(); #endif // ENABLE_POOL - // Socks4 #ifdef ENABLE_SOCKS4 /** Set socks4 server ip that all new tcp sockets should use. */ @@ -145,7 +117,6 @@ public: \return true if direct connection should be tried if connection to socks4 server fails */ bool Socks4TryDirect(); #endif // ENABLE_SOCKS4 - // DNS resolve server #ifdef ENABLE_RESOLVER /** Enable asynchronous DNS. @@ -173,7 +144,6 @@ public: /** Returns true if the socket is waiting for a resolve event. */ bool Resolving(Socket *); #endif // ENABLE_RESOLVER - #ifdef ENABLE_TRIGGERS /** Fetch unique trigger id. */ int TriggerID(Socket *src); @@ -188,27 +158,22 @@ public: Leave them in place if 'false' - if a trigger should be called many times */ void Trigger(int id, Socket::TriggerData& data, bool erase = true); #endif // ENABLE_TRIGGERS - #ifdef ENABLE_DETACH /** Indicates that the handler runs under SocketThread. */ void SetSlave(bool x = true); /** Indicates that the handler runs under SocketThread. */ bool IsSlave(); #endif - /** Sanity check of those accursed lists. */ void CheckSanity(); - protected: socket_m m_sockets; ///< Active sockets map socket_m m_add; ///< Sockets to be added to sockets map std::list<Socket *> m_delete; ///< Sockets to be deleted (failed when Add) - protected: StdLog *m_stdlog; ///< Registered log class, or NULL Mutex& m_mutex; ///< Thread safety mutex bool m_b_use_mutex; ///< Mutex correctly initialized - private: void CheckList(socket_v&,const std::string&); ///< Used by CheckSanity /** Remove socket from socket map, used by Socket class. */ @@ -220,7 +185,6 @@ private: int m_preverror; ///< debug select() error int m_errcnt; ///< debug select() error time_t m_tlast; ///< timeout control - // state lists socket_v m_fds; ///< Active file descriptor list socket_v m_fds_erase; ///< File descriptors that are to be erased from m_sockets @@ -231,7 +195,6 @@ private: socket_v m_fds_timeout; ///< checklist timeout socket_v m_fds_retry; ///< checklist retry client connect socket_v m_fds_close; ///< checklist close and delete - #ifdef ENABLE_SOCKS4 ipaddr_t m_socks4_host; ///< Socks4 server host ip port_t m_socks4_port; ///< Socks4 server port number @@ -257,11 +220,8 @@ private: #endif }; - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_SocketHandler_H - diff --git a/dep/include/sockets/StdLog.h b/dep/include/sockets/StdLog.h index 8266479f21c..65d91081338 100644 --- a/dep/include/sockets/StdLog.h +++ b/dep/include/sockets/StdLog.h @@ -4,39 +4,31 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_StdLog_H #define _SOCKETS_StdLog_H - #include "sockets-config.h" #include <string> - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /** error level enum. */ typedef enum { @@ -46,10 +38,8 @@ typedef enum LOG_LEVEL_INFO } loglevel_t; - class ISocketHandler; class Socket; - /** \defgroup logging Log help classes */ /** Log class interface. \ingroup logging */ @@ -57,7 +47,6 @@ class StdLog { public: virtual ~StdLog() {} - virtual void error(ISocketHandler *,Socket *, const std::string& user_text, int err, @@ -65,11 +54,8 @@ public: loglevel_t = LOG_LEVEL_WARNING) = 0; }; - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_StdLog_H - diff --git a/dep/include/sockets/StdoutLog.h b/dep/include/sockets/StdoutLog.h index aee865be6af..8e97700a2ff 100644 --- a/dep/include/sockets/StdoutLog.h +++ b/dep/include/sockets/StdoutLog.h @@ -4,40 +4,32 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_StdoutLog_H #define _SOCKETS_StdoutLog_H - #include "sockets-config.h" #include "StdLog.h" - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /** StdLog implementation, logs to stdout. \ingroup logging */ class StdoutLog : public StdLog @@ -47,12 +39,8 @@ public: }; - - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_StdoutLog_H - diff --git a/dep/include/sockets/StreamSocket.h b/dep/include/sockets/StreamSocket.h index e839040e2b0..6abb936b6cd 100644 --- a/dep/include/sockets/StreamSocket.h +++ b/dep/include/sockets/StreamSocket.h @@ -1,14 +1,11 @@ #ifndef _StreamSocket_H #define _StreamSocket_H - #include "Socket.h" - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /** SOCK_STREAM Socket base class. \ingroup basic */ class StreamSocket : public Socket @@ -16,96 +13,70 @@ class StreamSocket : public Socket public: StreamSocket(ISocketHandler& ); ~StreamSocket(); - /** Socket should Check Connect on next write event from select(). */ void SetConnecting(bool = true); - /** Check connecting flag. \return true if the socket is still trying to connect */ bool Connecting(); - /** Returns true when socket file descriptor is valid, socket connection is established, and socket is not about to be closed. */ bool Ready(); - /** Set timeout to use for connection attempt. \param x Timeout in seconds */ void SetConnectTimeout(int x); - /** Return number of seconds to wait for a connection. \return Connection timeout (seconds) */ int GetConnectTimeout(); - /** Set flush before close to make a tcp socket completely empty its output buffer before closing the connection. */ void SetFlushBeforeClose(bool = true); - /** Check flush before status. \return true if the socket should send all data before closing */ bool GetFlushBeforeClose(); - /** Define number of connection retries (tcp only). n = 0 - no retry n > 0 - number of retries n = -1 - unlimited retries */ void SetConnectionRetry(int n); - /** Get number of maximum connection retries (tcp only). */ int GetConnectionRetry(); - /** Increase number of actual connection retries (tcp only). */ void IncreaseConnectionRetries(); - /** Get number of actual connection retries (tcp only). */ int GetConnectionRetries(); - /** Reset actual connection retries (tcp only). */ void ResetConnectionRetries(); - // LIST_CALLONCONNECT - /** Instruct socket to call OnConnect callback next sockethandler cycle. */ void SetCallOnConnect(bool x = true); - /** Check call on connect flag. \return true if OnConnect() should be called a.s.a.p */ bool CallOnConnect(); - // LIST_RETRY - /** Set flag to initiate a connection attempt after a connection timeout. */ void SetRetryClientConnect(bool x = true); - /** Check if a connection attempt should be made. \return true when another attempt should be made */ bool RetryClientConnect(); - /** Called after OnRead if socket is in line protocol mode. \sa SetLineProtocol */ /** Enable the OnLine callback. Do not create your own OnRead * callback when using this. */ virtual void SetLineProtocol(bool = true); - /** Check line protocol mode. \return true if socket is in line protocol mode */ bool LineProtocol(); - /** Set shutdown status. */ void SetShutdown(int); - /** Get shutdown status. */ int GetShutdown(); - /** Returns IPPROTO_TCP or IPPROTO_SCTP */ virtual int Protocol() = 0; - protected: StreamSocket(const StreamSocket& ) {} // copy constructor - private: StreamSocket& operator=(const StreamSocket& ) { return *this; } // assignment operator - bool m_bConnecting; ///< Flag indicating connection in progress int m_connect_timeout; ///< Connection timeout (seconds) bool m_flush_before_close; ///< Send all data before closing (default true) @@ -117,12 +88,9 @@ private: int m_shutdown; ///< Shutdown status }; - #ifdef SOCKETS_NAMESPACE } // namespace SOCKETS_NAMESPACE { #endif - #endif // _StreamSocket_H - diff --git a/dep/include/sockets/TcpSocket.h b/dep/include/sockets/TcpSocket.h index 4caeb548aaa..34561f59cdc 100644 --- a/dep/include/sockets/TcpSocket.h +++ b/dep/include/sockets/TcpSocket.h @@ -4,25 +4,20 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -35,20 +30,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <openssl/ssl.h> #include "SSLInitializer.h" #endif - #include <string.h> - #define TCP_BUFSIZE_READ 16400 #define TCP_OUTPUT_CAPACITY 1024000 - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - class SocketAddress; - /** Socket implementation for TCP. \ingroup basic */ class TcpSocket : public StreamSocket @@ -62,7 +52,6 @@ protected: public: CircularBuffer(size_t size); ~CircularBuffer(); - /** append l bytes from p to buffer */ bool Write(const char *p,size_t l); /** copy l bytes from buffer to dest */ @@ -73,7 +62,6 @@ protected: bool Remove(size_t l); /** read l bytes from buffer, returns as string. */ std::string ReadString(size_t l); - /** total buffer length */ size_t GetLength(); /** pointer to circular buffer beginning */ @@ -82,10 +70,8 @@ protected: size_t GetL(); /** return free space in buffer, number of bytes until buffer overrun */ size_t Space(); - /** return total number of bytes written to this buffer, ever */ unsigned long ByteCounter(bool clear = false); - private: CircularBuffer(const CircularBuffer& /*s*/) {} CircularBuffer& operator=(const CircularBuffer& ) { return *this; } @@ -128,7 +114,6 @@ protected: char _buf[TCP_OUTPUT_CAPACITY]; }; typedef std::list<OUTPUT *> output_l; - public: /** Constructor with standard values on input/output buffers. */ TcpSocket(ISocketHandler& ); @@ -138,7 +123,6 @@ public: \param osize Output buffer size */ TcpSocket(ISocketHandler& h,size_t isize,size_t osize); ~TcpSocket(); - /** Open a connection to a remote server. If you want your socket to connect to a server, always call Open before Add'ing a socket to the sockethandler. @@ -163,18 +147,15 @@ public: \param host Hostname \param port Port number */ bool Open(const std::string &host,port_t port); - /** Connect timeout callback. */ void OnConnectTimeout(); #ifdef _WIN32 /** Connection failed reported as exception on win32 */ void OnException(); #endif - /** Close file descriptor - internal use only. \sa SetCloseAndDelete */ int Close(); - /** Send a string. \param s String to send \param f Dummy flags -- not used */ @@ -190,7 +171,6 @@ public: \param buf Pointer to the data \param len Length of the data */ virtual void OnRawData(const char *buf,size_t len); - /** Called when output buffer has been sent. Note: Will only be called IF the output buffer has been used. Send's that was successful without needing the output buffer @@ -200,7 +180,6 @@ public: size_t GetInputLength(); /** Number of bytes in output buffer. */ size_t GetOutputLength(); - /** Callback fires when a socket in line protocol has read one full line. \param line Line read */ void OnLine(const std::string& line); @@ -208,7 +187,6 @@ public: uint64_t GetBytesReceived(bool clear = false); /** Get counter of number of bytes sent. */ uint64_t GetBytesSent(bool clear = false); - /** Socks4 specific callback. */ void OnSocks4Connect(); /** Socks4 specific callback. */ @@ -216,7 +194,6 @@ public: /** Socks4 specific callback. \return 'need_more' */ bool OnSocks4Read(); - #ifdef ENABLE_RESOLVER /** Callback executed when resolver thread has finished a resolve request. */ void OnResolved(int id,ipaddr_t a,port_t port); @@ -236,7 +213,6 @@ public: the ssl context for an incoming connection. */ virtual void InitSSLServer(); #endif - #ifdef ENABLE_RECONNECT /** Flag that says a broken connection will try to reconnect. */ void SetReconnect(bool = true); @@ -247,24 +223,17 @@ public: /** Socket is reconnecting. */ bool IsReconnect(); #endif - void DisableInputBuffer(bool = true); - void OnOptions(int,int,int,SOCKET); - void SetLineProtocol(bool = true); - // TCP options bool SetTcpNodelay(bool = true); - virtual int Protocol(); - /** Trigger limit for callback OnTransferLimit. */ void SetTransferLimit(size_t sz); /** This callback fires when the output buffer drops below the value set by SetTransferLimit. Default: 0 (disabled). */ virtual void OnTransferLimit(); - protected: TcpSocket(const TcpSocket& ); void OnRead(); @@ -296,17 +265,13 @@ static int SSL_password_cb(char *buf,int num,int rwflag,void *userdata); /** SSL; Get ssl password. */ const std::string& GetPassword(); #endif - CircularBuffer ibuf; ///< Circular input buffer - private: TcpSocket& operator=(const TcpSocket& ) { return *this; } - /** the actual send() */ int TryWrite(const char *buf, size_t len); /** add data to output buffer top */ void Buffer(const char *buf, size_t len); - // bool m_b_input_buffer_disabled; uint64_t m_bytes_sent; @@ -321,7 +286,6 @@ private: OUTPUT *m_obuf_top; ///< output buffer on top size_t m_transfer_limit; size_t m_output_length; - #ifdef HAVE_OPENSSL static SSLInitializer m_ssl_init; SSL_CTX *m_ssl_ctx; ///< ssl context @@ -329,7 +293,6 @@ static SSLInitializer m_ssl_init; BIO *m_sbio; ///< ssl bio std::string m_password; ///< ssl password #endif - #ifdef ENABLE_SOCKS4 int m_socks4_state; ///< socks4 support char m_socks4_vn; ///< socks4 support, temporary variable @@ -337,23 +300,17 @@ static SSLInitializer m_ssl_init; unsigned short m_socks4_dstport; ///< socks4 support unsigned long m_socks4_dstip; ///< socks4 support #endif - #ifdef ENABLE_RESOLVER int m_resolver_id; ///< Resolver id (if any) for current Open call #endif - #ifdef ENABLE_RECONNECT bool m_b_reconnect; ///< Reconnect on lost connection flag bool m_b_is_reconnect; ///< Trying to reconnect #endif - }; - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_TcpSocket_H - diff --git a/dep/include/sockets/Thread.h b/dep/include/sockets/Thread.h index e065a257a85..4c649ed14d5 100644 --- a/dep/include/sockets/Thread.h +++ b/dep/include/sockets/Thread.h @@ -4,37 +4,30 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_Thread_H #define _SOCKETS_Thread_H - #include "sockets-config.h" #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - #ifdef _WIN32 // to be //typedef DWORD threadfunc_t; @@ -45,12 +38,10 @@ typedef void * threadparam_t; #define STDPREFIX __stdcall #else #include <pthread.h> - typedef void * threadfunc_t; typedef void * threadparam_t; #define STDPREFIX #endif - /** \defgroup threading Threading */ /** Thread base class. The Thread class is used by the resolver (ResolvServer) and running a detached socket (SocketThread). @@ -63,11 +54,8 @@ class Thread public: Thread(bool release = true); virtual ~Thread(); - static threadfunc_t STDPREFIX StartThread(threadparam_t); - virtual void Run() = 0; - bool IsRunning(); void SetRunning(bool x); bool IsReleased(); @@ -75,7 +63,6 @@ public: bool DeleteOnExit(); void SetDeleteOnExit(bool x = true); bool IsDestructor(); - private: Thread(const Thread& ) {} Thread& operator=(const Thread& ) { return *this; } @@ -91,11 +78,8 @@ private: bool m_b_destructor; }; - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_Thread_H - diff --git a/dep/include/sockets/UdpSocket.h b/dep/include/sockets/UdpSocket.h index fd9965e96e8..010a7b23143 100644 --- a/dep/include/sockets/UdpSocket.h +++ b/dep/include/sockets/UdpSocket.h @@ -4,39 +4,31 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_UdpSocket_H #define _SOCKETS_UdpSocket_H - #include "sockets-config.h" #include "Socket.h" - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - /** Socket implementation for UDP. \ingroup basic */ class UdpSocket : public Socket @@ -48,14 +40,12 @@ public: \param ipv6 'true' if this is an ipv6 socket */ UdpSocket(ISocketHandler& h,int ibufsz = 16384,bool ipv6 = false, int retries = 0); ~UdpSocket(); - /** Called when incoming data has been received. \param buf Pointer to data \param len Length of data \param sa Pointer to sockaddr struct of sender \param sa_len Length of sockaddr struct */ virtual void OnRawData(const char *buf,size_t len,struct sockaddr *sa,socklen_t sa_len); - /** Called when incoming data has been received and read timestamp is enabled. \param buf Pointer to data \param len Length of data @@ -63,7 +53,6 @@ public: \param sa_len Length of sockaddr struct \param ts Timestamp from message */ virtual void OnRawData(const char *buf,size_t len,struct sockaddr *sa,socklen_t sa_len,struct timeval *ts); - /** To receive incoming data, call Bind to setup an incoming port. \param port Incoming port number \param range Port range to try if ports already in use @@ -96,7 +85,6 @@ public: \param range Port range \return 0 if bind succeeded */ int Bind(SocketAddress& ad,int range = 1); - /** Define remote host. \param l Address of remote host \param port Port of remote host @@ -120,7 +108,6 @@ public: \param ad Socket address \return true if successful */ bool Open(SocketAddress& ad); - /** Send to specified host */ void SendToBuf(const std::string& ,port_t,const char *data,int len,int flags = 0); /** Send to specified address */ @@ -133,7 +120,6 @@ public: #endif /** Send to specified socket address */ void SendToBuf(SocketAddress& ad,const char *data,int len,int flags = 0); - /** Send string to specified host */ void SendTo(const std::string&,port_t,const std::string&,int flags = 0); /** Send string to specified address */ @@ -146,18 +132,15 @@ public: #endif /** Send string to specified socket address */ void SendTo(SocketAddress& ad,const std::string&,int flags = 0); - /** Send to connected address */ void SendBuf(const char *data,size_t,int flags = 0); /** Send string to connected address. */ void Send(const std::string& ,int flags = 0); - /** Set broadcast */ void SetBroadcast(bool b = true); /** Check broadcast flag. \return true broadcast is enabled. */ bool IsBroadcast(); - /** multicast */ void SetMulticastTTL(int ttl = 1); int GetMulticastTTL(); @@ -177,14 +160,10 @@ public: bool IsBound(); /** Return Bind port number */ port_t GetPort(); - void OnOptions(int,int,int,SOCKET) {} - int GetLastSizeWritten(); - /** Also read timestamp information from incoming message */ void SetTimestamp(bool = true); - protected: UdpSocket(const UdpSocket& s) : Socket(s) {} void OnRead(); @@ -192,7 +171,6 @@ protected: /** This method emulates socket recvfrom, but uses messages so we can get the timestamp */ int ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen_t fromlen, struct timeval *ts); #endif - private: UdpSocket& operator=(const UdpSocket& ) { return *this; } /** create before using sendto methods */ @@ -206,11 +184,8 @@ private: bool m_b_read_ts; }; - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_UdpSocket_H - diff --git a/dep/include/sockets/Utility.h b/dep/include/sockets/Utility.h index be0f6a05498..8f1c15ab260 100644 --- a/dep/include/sockets/Utility.h +++ b/dep/include/sockets/Utility.h @@ -4,32 +4,26 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_Utility_H #define _SOCKETS_Utility_H - #include "sockets-config.h" #include <ctype.h> #include <string.h> @@ -37,15 +31,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "socket_include.h" #include <map> #include <string> - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - #define TWIST_LEN 624 - class SocketAddress; - /** Conversion utilities. \ingroup util */ class Utility @@ -57,9 +47,7 @@ class Utility class Rng { public: Rng(unsigned long seed); - unsigned long Get(); - private: int m_value; unsigned long m_tmp[TWIST_LEN]; @@ -84,16 +72,13 @@ public: static unsigned int hex2unsigned(const std::string& str); static std::string rfc1738_encode(const std::string& src); static std::string rfc1738_decode(const std::string& src); - /** Checks whether a string is a valid ipv4/ipv6 ip number. */ static bool isipv4(const std::string&); /** Checks whether a string is a valid ipv4/ipv6 ip number. */ static bool isipv6(const std::string&); - /** Hostname to ip resolution ipv4, not asynchronous. */ static bool u2ip(const std::string&, ipaddr_t&); static bool u2ip(const std::string&, struct sockaddr_in& sa, int ai_flags = 0); - #ifdef ENABLE_IPV6 #ifdef IPPROTO_IPV6 /** Hostname to ip resolution ipv6, not asynchronous. */ @@ -101,13 +86,10 @@ public: static bool u2ip(const std::string&, struct sockaddr_in6& sa, int ai_flags = 0); #endif #endif - /** Reverse lookup of address to hostname */ static bool reverse(struct sockaddr *sa, socklen_t sa_len, std::string&, int flags = 0); static bool reverse(struct sockaddr *sa, socklen_t sa_len, std::string& hostname, std::string& service, int flags = 0); - static bool u2service(const std::string& name, int& service, int ai_flags = 0); - /** Convert binary ip address to string: ipv4. */ static void l2ip(const ipaddr_t,std::string& ); static void l2ip(const in_addr&,std::string& ); @@ -115,7 +97,6 @@ public: #ifdef IPPROTO_IPV6 /** Convert binary ip address to string: ipv6. */ static void l2ip(const struct in6_addr&,std::string& ,bool mixed = false); - /** ipv6 address compare. */ static int in6_addr_compare(in6_addr,in6_addr); #endif @@ -148,22 +129,15 @@ public: /** Convert sockaddr struct to human readable string. \param sa Ptr to sockaddr struct */ static std::string Sa2String(struct sockaddr *sa); - /** Get current time in sec/microseconds. */ static void GetTime(struct timeval *); - static std::auto_ptr<SocketAddress> CreateAddress(struct sockaddr *,socklen_t); - static unsigned long ThreadID(); - static std::string ToLower(const std::string& str); static std::string ToUpper(const std::string& str); - static std::string ToString(double d); - /** Returns a random 32-bit integer */ static unsigned long Rnd(); - private: static std::string m_host; ///< local hostname static ipaddr_t m_ip; ///< local ip address @@ -177,11 +151,8 @@ private: static bool m_local_resolved; ///< ResolveLocal has been called if true }; - #ifdef SOCKETS_NAMESPACE } #endif - #endif // _SOCKETS_Utility_H - diff --git a/dep/include/sockets/socket_include.h b/dep/include/sockets/socket_include.h index dcfd4acfbd6..e5a216432b5 100644 --- a/dep/include/sockets/socket_include.h +++ b/dep/include/sockets/socket_include.h @@ -4,25 +4,20 @@ **/ /* Copyright (C) 2004-2007 Anders Hedstrom - This library is made available under the terms of the GNU GPL. - If you would like to use this library in a closed-source application, a separate license agreement is available. For information about the closed-source license agreement for the C++ sockets library, please visit http://www.alhem.net/Sockets/license.html and/or email license@alhem.net. - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -30,24 +25,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _SOCKETS_socket_include_H #define _SOCKETS_socket_include_H #include "sockets-config.h" - #ifdef _MSC_VER #pragma warning(disable:4514) #endif - // common defines affecting library and applications using library - /* Define SOCKETS_DYNAMIC_TEMP to use dynamically allocated buffers in read operations - helps on ECOS */ #define SOCKETS_DYNAMIC_TEMP - // platform specific stuff #if (defined(__unix__) || defined(unix)) && !defined(USG) #include <sys/param.h> #endif #include <list> - // int64 #ifdef _WIN32 typedef unsigned __int64 uint64_t; @@ -59,7 +49,6 @@ typedef unsigned __int64 uint64_t; # include <stdint.h> #endif #endif - #ifndef _WIN32 // ---------------------------------------- // common unix includes / defines @@ -70,44 +59,35 @@ typedef unsigned __int64 uint64_t; #include <netinet/in.h> #include <arpa/inet.h> //#include <netdb.h> - // all typedefs in this file will be declared outside the sockets namespace, // because some os's will already have one or more of the type defined. typedef int SOCKET; #define Errno errno #define StrError strerror - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - // WIN32 adapt #define closesocket close #define INVALID_SOCKET -1 #define SOCKET_ERROR -1 - #ifndef INADDR_NONE #define INADDR_NONE ((unsigned long) -1) #endif // INADDR_NONE - #ifdef SOCKETS_NAMESPACE } #endif - #endif // !_WIN32 - // ---------------------------------------- // Generic #ifndef SOL_IP #define SOL_IP IPPROTO_IP #endif - // ---------------------------------------- // OS specific adaptions - #ifdef SOLARIS // ---------------------------------------- // Solaris @@ -116,14 +96,11 @@ typedef unsigned short port_t; namespace SOCKETS_NAMESPACE { #endif // no defs - #ifdef SOCKETS_NAMESPACE } #endif - #define s6_addr16 _S6_un._S6_u8 #define MSG_NOSIGNAL 0 - #elif defined __FreeBSD__ // ---------------------------------------- // FreeBSD @@ -139,25 +116,22 @@ typedef in_port_t port_t; namespace SOCKETS_NAMESPACE { #endif // no defs - #ifdef SOCKETS_NAMESPACE } #endif - # define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP # define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP # else # error FreeBSD versions prior to 400014 does not support ipv6 # endif - #elif defined (__NetBSD__) || defined (__OpenBSD__) -# if !defined(MSG_NOSIGNAL) -# define MSG_NOSIGNAL 0 -# endif -# include <netinet/in.h> -typedef in_addr_t ipaddr_t; -typedef in_port_t port_t; -#elif defined MACOSX +# if !defined(MSG_NOSIGNAL) +# define MSG_NOSIGNAL 0 +# endif +# include <netinet/in.h> +typedef in_addr_t ipaddr_t; +typedef in_port_t port_t; +#elif defined MACOSX // ---------------------------------------- // Mac OS X #include <string.h> @@ -171,16 +145,13 @@ typedef unsigned long ipaddr_t; namespace SOCKETS_NAMESPACE { #endif // no defs - #ifdef SOCKETS_NAMESPACE } #endif - #define s6_addr16 __u6_addr.__u6_addr16 #define MSG_NOSIGNAL 0 // oops - thanks Derek #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP - #elif defined _WIN32 // ---------------------------------------- // Win32 @@ -188,7 +159,6 @@ namespace SOCKETS_NAMESPACE { #pragma comment(lib, "wsock32.lib") #endif #define strcasecmp _stricmp - typedef unsigned long ipaddr_t; typedef unsigned short port_t; typedef int socklen_t; @@ -196,15 +166,12 @@ typedef int socklen_t; namespace SOCKETS_NAMESPACE { #endif // no defs - #ifdef SOCKETS_NAMESPACE } #endif - // 1.8.6: define FD_SETSIZE to something bigger than 64 if there are a lot of // simultaneous connections (must be done before including winsock.h) #define FD_SETSIZE 1024 - // windows 2000 with ipv6 preview installed: // http://msdn.microsoft.com/downloads/sdks/platform/tpipv6.asp // see the FAQ on how to install @@ -219,19 +186,15 @@ namespace SOCKETS_NAMESPACE { #endif #endif // _MSC_VER < 1200 - #define MSG_NOSIGNAL 0 //#define SHUT_RDWR 2 #define SHUT_WR 1 - #define Errno WSAGetLastError() const char *StrError(int x); - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif - // class WSAInitializer is a part of the Socket class (on win32) // as a static instance - so whenever an application uses a Socket, // winsock is initialized @@ -250,11 +213,9 @@ public: private: WSADATA m_wsadata; }; - #ifdef SOCKETS_NAMESPACE } #endif - #else // ---------------------------------------- // LINUX @@ -264,26 +225,21 @@ typedef unsigned short port_t; namespace SOCKETS_NAMESPACE { #endif // no defs - #ifdef SOCKETS_NAMESPACE } #endif - #endif - #ifdef SOCKETS_NAMESPACE namespace SOCKETS_NAMESPACE { #endif /** List type containing file descriptors. */ typedef std::list<SOCKET> socket_v; - #ifdef SOCKETS_NAMESPACE } #endif - // getaddrinfo / getnameinfo replacements #ifdef NO_GETADDRINFO #ifndef AI_NUMERICHOST @@ -294,7 +250,5 @@ namespace SOCKETS_NAMESPACE { #endif #endif - #endif // _SOCKETS_socket_include_H - diff --git a/dep/include/sockets/sockets-config.h b/dep/include/sockets/sockets-config.h index 464ed34cabb..f2de433756c 100644 --- a/dep/include/sockets/sockets-config.h +++ b/dep/include/sockets/sockets-config.h @@ -5,24 +5,20 @@ **/ /* Copyright (C) 2007 Anders Hedstrom - This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SOCKETS_CONFIG_H #define _SOCKETS_CONFIG_H - #ifndef _RUN_DP /* First undefine symbols if already defined. */ #undef HAVE_OPENSSL @@ -37,66 +33,51 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #undef ENABLE_TRIGGERS #undef ENABLE_EXCEPTIONS #endif // _RUN_DP - // define MACOSX for internal socket library checks #if defined(__APPLE__) && defined(__MACH__) && !defined(MACOSX) #define MACOSX #endif - /* OpenSSL support. */ //#define HAVE_OPENSSL - /* Ipv6 support. */ //#define ENABLE_IPV6 - /* SCTP support. */ //#define USE_SCTP - /* Define NO_GETADDRINFO if your operating system does not support the "getaddrinfo" and "getnameinfo" function calls. */ #define NO_GETADDRINFO - /* Connection pool support. */ #define ENABLE_POOL - /* Socks4 client support. */ //#define ENABLE_SOCKS4 - /* Asynchronous resolver. */ #define ENABLE_RESOLVER - /* Enable TCP reconnect on lost connection. Socket::OnReconnect Socket::OnDisconnect */ #define ENABLE_RECONNECT - /* Enable socket thread detach functionality. */ #define ENABLE_DETACH - /* Enable socket to socket triggers. Not yet in use. */ //#define ENABLE_TRIGGERS - /* Enabled exceptions. */ //#define ENABLE_EXCEPTIONS - /* Resolver uses the detach function so either enable both or disable both. */ #ifndef ENABLE_DETACH #undef ENABLE_RESOLVER #endif - #endif // _SOCKETS_CONFIG_H - |