aboutsummaryrefslogtreecommitdiff
path: root/dep/include/sockets
diff options
context:
space:
mode:
Diffstat (limited to 'dep/include/sockets')
-rw-r--r--dep/include/sockets/Base64.h34
-rw-r--r--dep/include/sockets/Exception.h18
-rw-r--r--dep/include/sockets/File.h50
-rw-r--r--dep/include/sockets/IFile.h32
-rw-r--r--dep/include/sockets/ISocketHandler.h282
-rw-r--r--dep/include/sockets/Ipv4Address.h102
-rw-r--r--dep/include/sockets/Ipv6Address.h104
-rw-r--r--dep/include/sockets/ListenSocket.h604
-rw-r--r--dep/include/sockets/Lock.h16
-rw-r--r--dep/include/sockets/Mutex.h24
-rw-r--r--dep/include/sockets/Parse.h78
-rw-r--r--dep/include/sockets/ResolvServer.h30
-rw-r--r--dep/include/sockets/ResolvSocket.h78
-rw-r--r--dep/include/sockets/SctpSocket.h92
-rw-r--r--dep/include/sockets/Socket.h1112
-rw-r--r--dep/include/sockets/SocketAddress.h58
-rw-r--r--dep/include/sockets/SocketHandler.h302
-rw-r--r--dep/include/sockets/StdLog.h30
-rw-r--r--dep/include/sockets/StdoutLog.h12
-rw-r--r--dep/include/sockets/StreamSocket.h150
-rw-r--r--dep/include/sockets/TcpSocket.h498
-rw-r--r--dep/include/sockets/Thread.h54
-rw-r--r--dep/include/sockets/UdpSocket.h270
-rw-r--r--dep/include/sockets/Utility.h198
-rw-r--r--dep/include/sockets/socket_include.h60
-rw-r--r--dep/include/sockets/sockets-config.h10
26 files changed, 2149 insertions, 2149 deletions
diff --git a/dep/include/sockets/Base64.h b/dep/include/sockets/Base64.h
index a632bbec730..0620cee6a30 100644
--- a/dep/include/sockets/Base64.h
+++ b/dep/include/sockets/Base64.h
@@ -1,6 +1,6 @@
/** \file Base64.h
- ** \date 2004-02-13
- ** \author grymse@alhem.net
+ ** \date 2004-02-13
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -44,28 +44,28 @@ namespace SOCKETS_NAMESPACE {
/** \defgroup util Utilities */
-/** Base64 encode/decode.
- \ingroup util */
+/** Base64 encode/decode.
+ \ingroup util */
class Base64
{
public:
- Base64();
+ 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 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&);
+ void decode(const std::string&, std::string& );
+ void decode(const std::string&, unsigned char *, size_t&);
- size_t decode_length(const std::string& );
+ size_t decode_length(const std::string& );
private:
- Base64(const Base64& ) {}
- Base64& operator=(const Base64& ) { return *this; }
-static const char *bstr;
-static const char rstr[128];
+ Base64(const Base64& ) {}
+ Base64& operator=(const Base64& ) { return *this; }
+static const char *bstr;
+static const char rstr[128];
};
diff --git a/dep/include/sockets/Exception.h b/dep/include/sockets/Exception.h
index 81ba7373d0d..8bfa9904d8b 100644
--- a/dep/include/sockets/Exception.h
+++ b/dep/include/sockets/Exception.h
@@ -1,7 +1,7 @@
/**
- ** \file Exception.h
- ** \date 2007-09-28
- ** \author grymse@alhem.net
+ ** \file Exception.h
+ ** \date 2007-09-28
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2007 Anders Hedstrom
@@ -34,17 +34,17 @@ namespace SOCKETS_NAMESPACE {
class Exception
{
public:
- Exception(const std::string& description);
- virtual ~Exception() {}
+ Exception(const std::string& description);
+ virtual ~Exception() {}
- virtual const std::string ToString() const;
+ virtual const std::string ToString() const;
- Exception(const Exception& ) {} // copy constructor
+ Exception(const Exception& ) {} // copy constructor
- Exception& operator=(const Exception& ) { return *this; } // assignment operator
+ Exception& operator=(const Exception& ) { return *this; } // assignment operator
private:
- std::string m_description;
+ std::string m_description;
};
diff --git a/dep/include/sockets/File.h b/dep/include/sockets/File.h
index 58a1b71bb85..803930fc790 100644
--- a/dep/include/sockets/File.h
+++ b/dep/include/sockets/File.h
@@ -1,6 +1,6 @@
/** \file File.h
- ** \date 2005-04-25
- ** \author grymse@alhem.net
+ ** \date 2005-04-25
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -39,38 +39,38 @@ namespace SOCKETS_NAMESPACE {
#endif
-/** IFile implementation of a disk file.
- \ingroup file */
+/** IFile implementation of a disk file.
+ \ingroup file */
class File : public IFile
{
public:
- File();
- ~File();
+ File();
+ ~File();
- bool fopen(const std::string&, const std::string&);
- void fclose();
+ 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);
+ 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, ...);
+ char *fgets(char *, int) const;
+ void fprintf(const char *format, ...);
- off_t size() const;
- bool eof() const;
+ off_t size() const;
+ bool eof() const;
- void reset_read() const;
- void reset_write();
+ 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;
- mutable long m_rptr;
- long m_wptr;
+ File(const File& ) {} // copy constructor
+ File& operator=(const File& ) { return *this; } // assignment operator
+
+ std::string m_path;
+ std::string m_mode;
+ FILE *m_fil;
+ mutable long m_rptr;
+ long m_wptr;
};
diff --git a/dep/include/sockets/IFile.h b/dep/include/sockets/IFile.h
index aecc50f5997..f086d9ef1f1 100644
--- a/dep/include/sockets/IFile.h
+++ b/dep/include/sockets/IFile.h
@@ -1,6 +1,6 @@
/** \file IFile.h
- ** \date 2005-04-25
- ** \author grymse@alhem.net
+ ** \date 2005-04-25
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -38,27 +38,27 @@ namespace SOCKETS_NAMESPACE {
#endif
/** \defgroup file File handling */
-/** Pure virtual file I/O interface.
- \ingroup file */
+/** Pure virtual file I/O interface.
+ \ingroup file */
class IFile
{
public:
- virtual ~IFile() {}
+ virtual ~IFile() {}
- virtual bool fopen(const std::string&, const std::string&) = 0;
- virtual void fclose() = 0;
+ 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 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 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 off_t size() const = 0;
+ virtual bool eof() const = 0;
- virtual void reset_read() const = 0;
- virtual void reset_write() = 0;
+ virtual void reset_read() const = 0;
+ virtual void reset_write() = 0;
};
diff --git a/dep/include/sockets/ISocketHandler.h b/dep/include/sockets/ISocketHandler.h
index 2667e2d22ed..5c9d539b3a9 100644
--- a/dep/include/sockets/ISocketHandler.h
+++ b/dep/include/sockets/ISocketHandler.h
@@ -1,6 +1,6 @@
/** \file ISocketHandler.h
- ** \date 2004-02-13
- ** \author grymse@alhem.net
+ ** \date 2004-02-13
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -42,183 +42,183 @@ namespace SOCKETS_NAMESPACE {
#endif
typedef enum {
- LIST_CALLONCONNECT = 0,
+ LIST_CALLONCONNECT = 0,
#ifdef ENABLE_DETACH
- LIST_DETACH,
+ LIST_DETACH,
#endif
- LIST_TIMEOUT,
- LIST_RETRY,
- LIST_CLOSE
+ LIST_TIMEOUT,
+ LIST_RETRY,
+ LIST_CLOSE
} list_t;
class SocketAddress;
class Mutex;
-/** Socket container class, event generator.
- \ingroup basic */
+/** Socket container class, event generator.
+ \ingroup basic */
class ISocketHandler
{
- friend class Socket;
+ friend class Socket;
public:
- /** Connection pool class for internal use by the ISocketHandler.
- \ingroup internal */
+ /** Connection pool class for internal use by the ISocketHandler.
+ \ingroup internal */
#ifdef ENABLE_POOL
- class PoolSocket : public Socket
- {
- public:
- PoolSocket(ISocketHandler& h,Socket *src) : Socket(h) {
- CopyConnection( src );
- SetIsClient();
- }
-
- void OnRead() {
- Handler().LogError(this, "OnRead", 0, "data on hibernating socket", LOG_LEVEL_FATAL);
- SetCloseAndDelete();
- }
- void OnOptions(int,int,int,SOCKET) {}
-
- };
+ class PoolSocket : public Socket
+ {
+ public:
+ PoolSocket(ISocketHandler& h,Socket *src) : Socket(h) {
+ 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() {}
+ virtual ~ISocketHandler() {}
- /** Get mutex reference for threadsafe operations. */
- virtual Mutex& GetMutex() const = 0;
+ /** 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;
+ /** 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;
+ /** 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
- // -------------------------------------------------------------------------
- /** Add socket instance to socket map. Removal is always automatic. */
- virtual void Add(Socket *) = 0;
+ // -------------------------------------------------------------------------
+ // Socket stuff
+ // -------------------------------------------------------------------------
+ /** Add socket instance to socket map. Removal is always automatic. */
+ virtual void Add(Socket *) = 0;
private:
- /** Remove socket from socket map, used by Socket class. */
- virtual void Remove(Socket *) = 0;
+ /** Remove socket from socket map, used by Socket class. */
+ virtual void Remove(Socket *) = 0;
public:
- /** Get status of read/write/exception file descriptor set for a socket. */
- 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
- // -------------------------------------------------------------------------
+ /** Get status of read/write/exception file descriptor set for a socket. */
+ 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
+ // -------------------------------------------------------------------------
#ifdef ENABLE_POOL
- /** Find available open connection (used by connection pool). */
- virtual ISocketHandler::PoolSocket *FindConnection(int type,const std::string& protocol,SocketAddress&) = 0;
- /** Enable connection pool (by default disabled). */
- virtual void EnablePool(bool = true) = 0;
- /** Check pool status.
- \return true if connection pool is enabled */
- virtual bool PoolEnabled() = 0;
+ /** Find available open connection (used by connection pool). */
+ virtual ISocketHandler::PoolSocket *FindConnection(int type,const std::string& protocol,SocketAddress&) = 0;
+ /** Enable connection pool (by default disabled). */
+ virtual void EnablePool(bool = true) = 0;
+ /** Check pool status.
+ \return true if connection pool is enabled */
+ virtual bool PoolEnabled() = 0;
#endif // ENABLE_POOL
- // -------------------------------------------------------------------------
- // Socks4
- // -------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
+ // Socks4
+ // -------------------------------------------------------------------------
#ifdef ENABLE_SOCKS4
- /** Set socks4 server ip that all new tcp sockets should use. */
- virtual void SetSocks4Host(ipaddr_t) = 0;
- /** Set socks4 server hostname that all new tcp sockets should use. */
- virtual void SetSocks4Host(const std::string& ) = 0;
- /** Set socks4 server port number that all new tcp sockets should use. */
- virtual void SetSocks4Port(port_t) = 0;
- /** Set optional socks4 userid. */
- virtual void SetSocks4Userid(const std::string& ) = 0;
- /** If connection to socks4 server fails, immediately try direct connection to final host. */
- virtual void SetSocks4TryDirect(bool = true) = 0;
- /** Get socks4 server ip.
- \return socks4 server ip */
- virtual ipaddr_t GetSocks4Host() = 0;
- /** Get socks4 port number.
- \return socks4 port number */
- virtual port_t GetSocks4Port() = 0;
- /** Get socks4 userid (optional).
- \return socks4 userid */
- virtual const std::string& GetSocks4Userid() = 0;
- /** Check status of socks4 try direct flag.
- \return true if direct connection should be tried if connection to socks4 server fails */
- virtual bool Socks4TryDirect() = 0;
+ /** Set socks4 server ip that all new tcp sockets should use. */
+ virtual void SetSocks4Host(ipaddr_t) = 0;
+ /** Set socks4 server hostname that all new tcp sockets should use. */
+ virtual void SetSocks4Host(const std::string& ) = 0;
+ /** Set socks4 server port number that all new tcp sockets should use. */
+ virtual void SetSocks4Port(port_t) = 0;
+ /** Set optional socks4 userid. */
+ virtual void SetSocks4Userid(const std::string& ) = 0;
+ /** If connection to socks4 server fails, immediately try direct connection to final host. */
+ virtual void SetSocks4TryDirect(bool = true) = 0;
+ /** Get socks4 server ip.
+ \return socks4 server ip */
+ virtual ipaddr_t GetSocks4Host() = 0;
+ /** Get socks4 port number.
+ \return socks4 port number */
+ virtual port_t GetSocks4Port() = 0;
+ /** Get socks4 userid (optional).
+ \return socks4 userid */
+ virtual const std::string& GetSocks4Userid() = 0;
+ /** Check status of socks4 try direct flag.
+ \return true if direct connection should be tried if connection to socks4 server fails */
+ virtual bool Socks4TryDirect() = 0;
#endif // ENABLE_SOCKS4
- // -------------------------------------------------------------------------
- // DNS resolve server
- // -------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
+ // DNS resolve server
+ // -------------------------------------------------------------------------
#ifdef ENABLE_RESOLVER
- /** Enable asynchronous DNS.
- \param port Listen port of asynchronous dns server */
- virtual void EnableResolver(port_t = 16667) = 0;
- /** Check resolver status.
- \return true if resolver is enabled */
- virtual bool ResolverEnabled() = 0;
- /** Queue a dns request.
- \param host Hostname to be resolved
- \param port Port number will be echoed in Socket::OnResolved callback */
- virtual int Resolve(Socket *,const std::string& host,port_t port) = 0;
+ /** Enable asynchronous DNS.
+ \param port Listen port of asynchronous dns server */
+ virtual void EnableResolver(port_t = 16667) = 0;
+ /** Check resolver status.
+ \return true if resolver is enabled */
+ virtual bool ResolverEnabled() = 0;
+ /** Queue a dns request.
+ \param host Hostname to be resolved
+ \param port Port number will be echoed in Socket::OnResolved callback */
+ virtual int Resolve(Socket *,const std::string& host,port_t port) = 0;
#ifdef ENABLE_IPV6
- virtual int Resolve6(Socket *,const std::string& host,port_t port) = 0;
+ virtual int Resolve6(Socket *,const std::string& host,port_t port) = 0;
#endif
- /** Do a reverse dns lookup. */
- virtual int Resolve(Socket *,ipaddr_t a) = 0;
+ /** Do a reverse dns lookup. */
+ virtual int Resolve(Socket *,ipaddr_t a) = 0;
#ifdef ENABLE_IPV6
- virtual int Resolve(Socket *,in6_addr& a) = 0;
+ virtual int Resolve(Socket *,in6_addr& a) = 0;
#endif
- /** Get listen port of asynchronous dns server. */
- virtual port_t GetResolverPort() = 0;
- /** Resolver thread ready for queries. */
- virtual bool ResolverReady() = 0;
- /** Returns true if socket waiting for a resolve event. */
- virtual bool Resolving(Socket *) = 0;
+ /** Get listen port of asynchronous dns server. */
+ virtual port_t GetResolverPort() = 0;
+ /** Resolver thread ready for queries. */
+ virtual bool ResolverReady() = 0;
+ /** 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;
- /** Subscribe socket to trigger id. */
- virtual bool Subscribe(int id, Socket *dst) = 0;
- /** Unsubscribe socket from trigger id. */
- virtual bool Unsubscribe(int id, Socket *dst) = 0;
- /** Execute OnTrigger for subscribed sockets.
- \param id Trigger ID
- \param data Data passed from source to destination
- \param erase Empty trigger id source and destination maps if 'true',
- 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;
+ /** Fetch unique trigger id. */
+ virtual int TriggerID(Socket *src) = 0;
+ /** Subscribe socket to trigger id. */
+ virtual bool Subscribe(int id, Socket *dst) = 0;
+ /** Unsubscribe socket from trigger id. */
+ virtual bool Unsubscribe(int id, Socket *dst) = 0;
+ /** Execute OnTrigger for subscribed sockets.
+ \param id Trigger ID
+ \param data Data passed from source to destination
+ \param erase Empty trigger id source and destination maps if 'true',
+ 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;
+ /** 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
};
diff --git a/dep/include/sockets/Ipv4Address.h b/dep/include/sockets/Ipv4Address.h
index b58c2ce9425..2c43881a68a 100644
--- a/dep/include/sockets/Ipv4Address.h
+++ b/dep/include/sockets/Ipv4Address.h
@@ -1,7 +1,7 @@
/**
- ** \file Ipv4Address.h
- ** \date 2006-09-21
- ** \author grymse@alhem.net
+ ** \file Ipv4Address.h
+ ** \date 2006-09-21
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2007 Anders Hedstrom
@@ -33,59 +33,59 @@ namespace SOCKETS_NAMESPACE {
/* Ipv4 address implementation.
- \ingroup basic */
+ \ingroup basic */
class Ipv4Address : public SocketAddress
{
public:
- /** Create empty Ipv4 address structure.
- \param port Port number */
- Ipv4Address(port_t port = 0);
- /** Create Ipv4 address structure.
- \param a Socket address in network byte order (as returned by Utility::u2ip)
- \param port Port number in host byte order */
- Ipv4Address(ipaddr_t a,port_t port);
- /** Create Ipv4 address structure.
- \param a Socket address in network byte order
- \param port Port number in host byte order */
- Ipv4Address(struct in_addr& a,port_t port);
- /** Create Ipv4 address structure.
- \param host Hostname to be resolved
- \param port Port number in host byte order */
- 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);
+ /** Create empty Ipv4 address structure.
+ \param port Port number */
+ Ipv4Address(port_t port = 0);
+ /** Create Ipv4 address structure.
+ \param a Socket address in network byte order (as returned by Utility::u2ip)
+ \param port Port number in host byte order */
+ Ipv4Address(ipaddr_t a,port_t port);
+ /** Create Ipv4 address structure.
+ \param a Socket address in network byte order
+ \param port Port number in host byte order */
+ Ipv4Address(struct in_addr& a,port_t port);
+ /** Create Ipv4 address structure.
+ \param host Hostname to be resolved
+ \param port Port number in host byte order */
+ 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
- struct sockaddr_in m_addr;
- bool m_valid;
+ Ipv4Address(const Ipv4Address& ) {} // copy constructor
+ Ipv4Address& operator=(const Ipv4Address& ) { return *this; } // assignment operator
+ struct sockaddr_in m_addr;
+ bool m_valid;
};
diff --git a/dep/include/sockets/Ipv6Address.h b/dep/include/sockets/Ipv6Address.h
index a0711417956..a3b24b0b092 100644
--- a/dep/include/sockets/Ipv6Address.h
+++ b/dep/include/sockets/Ipv6Address.h
@@ -1,7 +1,7 @@
/**
- ** \file Ipv6Address.h
- ** \date 2006-09-21
- ** \author grymse@alhem.net
+ ** \file Ipv6Address.h
+ ** \date 2006-09-21
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2007 Anders Hedstrom
@@ -37,62 +37,62 @@ namespace SOCKETS_NAMESPACE {
/** Ipv6 address implementation.
- \ingroup basic */
+ \ingroup basic */
class Ipv6Address : public SocketAddress
{
public:
- /** Create empty Ipv6 address structure.
- \param port Port number */
- Ipv6Address(port_t port = 0);
- /** Create Ipv6 address structure.
- \param a Socket address in network byte order
- \param port Port number in host byte order */
- Ipv6Address(struct in6_addr& a,port_t port);
- /** Create Ipv6 address structure.
- \param host Hostname to be resolved
- \param port Port number in host byte order */
- 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();
+ /** Create empty Ipv6 address structure.
+ \param port Port number */
+ Ipv6Address(port_t port = 0);
+ /** Create Ipv6 address structure.
+ \param a Socket address in network byte order
+ \param port Port number in host byte order */
+ Ipv6Address(struct in6_addr& a,port_t port);
+ /** Create Ipv6 address structure.
+ \param host Hostname to be resolved
+ \param port Port number in host byte order */
+ 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();
+ void SetScopeId(uint32_t);
+ uint32_t GetScopeId();
#endif
private:
- Ipv6Address(const Ipv6Address& ) {} // copy constructor
- Ipv6Address& operator=(const Ipv6Address& ) { return *this; } // assignment operator
- struct sockaddr_in6 m_addr;
- bool m_valid;
+ Ipv6Address(const Ipv6Address& ) {} // copy constructor
+ Ipv6Address& operator=(const Ipv6Address& ) { return *this; } // assignment operator
+ struct sockaddr_in6 m_addr;
+ bool m_valid;
};
diff --git a/dep/include/sockets/ListenSocket.h b/dep/include/sockets/ListenSocket.h
index f4edc37d6c3..7dcee47d9ba 100644
--- a/dep/include/sockets/ListenSocket.h
+++ b/dep/include/sockets/ListenSocket.h
@@ -1,6 +1,6 @@
/** \file ListenSocket.h
- ** \date 2004-02-13
- ** \author grymse@alhem.net
+ ** \date 2004-02-13
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -18,7 +18,7 @@ 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,
+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.
@@ -52,344 +52,344 @@ namespace SOCKETS_NAMESPACE {
#endif
-/** Binds incoming port number to new Socket class X.
- \ingroup basic */
+/** Binds incoming port number to new Socket class X.
+ \ingroup basic */
template <class X>
class ListenSocket : public Socket
{
public:
- /** Constructor.
- \param h ISocketHandler reference
- \param use_creator Optional use of creator (default true) */
- ListenSocket(ISocketHandler& h,bool use_creator = true) : Socket(h), m_depth(0), m_creator(NULL)
- ,m_bHasCreate(false)
- {
- if (use_creator)
- {
- m_creator = new X(h);
- Socket *tmp = m_creator -> Create();
- if (tmp && dynamic_cast<X *>(tmp))
- {
- m_bHasCreate = true;
- }
- if (tmp)
- {
- delete tmp;
- }
- }
- }
- ~ListenSocket() {
- if (m_creator)
- {
- delete m_creator;
- }
- }
-
- /** Close file descriptor. */
- int Close() {
- if (GetSocket() != INVALID_SOCKET)
- {
- closesocket(GetSocket());
- }
- return 0;
- }
-
- /** Bind and listen to any interface.
- \param port Port (0 is random)
- \param depth Listen queue depth */
- int Bind(port_t port,int depth = 20) {
+ /** Constructor.
+ \param h ISocketHandler reference
+ \param use_creator Optional use of creator (default true) */
+ ListenSocket(ISocketHandler& h,bool use_creator = true) : Socket(h), m_depth(0), m_creator(NULL)
+ ,m_bHasCreate(false)
+ {
+ if (use_creator)
+ {
+ m_creator = new X(h);
+ Socket *tmp = m_creator -> Create();
+ if (tmp && dynamic_cast<X *>(tmp))
+ {
+ m_bHasCreate = true;
+ }
+ if (tmp)
+ {
+ delete tmp;
+ }
+ }
+ }
+ ~ListenSocket() {
+ if (m_creator)
+ {
+ delete m_creator;
+ }
+ }
+
+ /** Close file descriptor. */
+ int Close() {
+ if (GetSocket() != INVALID_SOCKET)
+ {
+ closesocket(GetSocket());
+ }
+ return 0;
+ }
+
+ /** Bind and listen to any interface.
+ \param port Port (0 is random)
+ \param depth Listen queue depth */
+ int Bind(port_t port,int depth = 20) {
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- if (IsIpv6())
- {
- Ipv6Address ad(port);
- return Bind(ad, depth);
- }
- else
+ if (IsIpv6())
+ {
+ Ipv6Address ad(port);
+ return Bind(ad, depth);
+ }
+ else
#endif
#endif
- {
- Ipv4Address ad(port);
- return Bind(ad, depth);
- }
- }
+ {
+ Ipv4Address ad(port);
+ return Bind(ad, depth);
+ }
+ }
- int Bind(SocketAddress& ad,int depth) {
+ int Bind(SocketAddress& ad,int depth) {
#ifdef USE_SCTP
- if (dynamic_cast<SctpSocket *>(m_creator))
- {
- return Bind(ad, "sctp", depth);
- }
+ if (dynamic_cast<SctpSocket *>(m_creator))
+ {
+ return Bind(ad, "sctp", depth);
+ }
#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
- \param depth Listen queue depth */
- int Bind(port_t port,const std::string& protocol,int depth = 20) {
+ return Bind(ad, "tcp", depth);
+ }
+
+ /** Bind and listen to any interface, with optional protocol.
+ \param port Port (0 is random)
+ \param protocol Network protocol
+ \param depth Listen queue depth */
+ int Bind(port_t port,const std::string& protocol,int depth = 20) {
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- if (IsIpv6())
- {
- Ipv6Address ad(port);
- return Bind(ad, protocol, depth);
- }
- else
+ if (IsIpv6())
+ {
+ Ipv6Address ad(port);
+ return Bind(ad, protocol, depth);
+ }
+ else
#endif
#endif
- {
- Ipv4Address ad(port);
- return Bind(ad, protocol, depth);
- }
- }
-
- /** Bind and listen to specific interface.
- \param intf Interface hostname
- \param port Port (0 is random)
- \param depth Listen queue depth */
- int Bind(const std::string& intf,port_t port,int depth = 20) {
+ {
+ Ipv4Address ad(port);
+ return Bind(ad, protocol, depth);
+ }
+ }
+
+ /** Bind and listen to specific interface.
+ \param intf Interface hostname
+ \param port Port (0 is random)
+ \param depth Listen queue depth */
+ int Bind(const std::string& intf,port_t port,int depth = 20) {
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- if (IsIpv6())
- {
- Ipv6Address ad(intf, port);
- if (ad.IsValid())
- {
- return Bind(ad, depth);
- }
- Handler().LogError(this, "Bind", 0, "name resolution of interface name failed", LOG_LEVEL_FATAL);
- return -1;
- }
- else
+ if (IsIpv6())
+ {
+ Ipv6Address ad(intf, port);
+ if (ad.IsValid())
+ {
+ return Bind(ad, depth);
+ }
+ Handler().LogError(this, "Bind", 0, "name resolution of interface name failed", LOG_LEVEL_FATAL);
+ return -1;
+ }
+ else
#endif
#endif
- {
- Ipv4Address ad(intf, port);
- if (ad.IsValid())
- {
- return Bind(ad, depth);
- }
- Handler().LogError(this, "Bind", 0, "name resolution of interface name failed", LOG_LEVEL_FATAL);
- return -1;
- }
- }
-
- /** Bind and listen to specific interface.
- \param intf Interface hostname
- \param port Port (0 is random)
- \param protocol Network protocol
- \param depth Listen queue depth */
- int Bind(const std::string& intf,port_t port,const std::string& protocol,int depth = 20) {
+ {
+ Ipv4Address ad(intf, port);
+ if (ad.IsValid())
+ {
+ return Bind(ad, depth);
+ }
+ Handler().LogError(this, "Bind", 0, "name resolution of interface name failed", LOG_LEVEL_FATAL);
+ return -1;
+ }
+ }
+
+ /** Bind and listen to specific interface.
+ \param intf Interface hostname
+ \param port Port (0 is random)
+ \param protocol Network protocol
+ \param depth Listen queue depth */
+ int Bind(const std::string& intf,port_t port,const std::string& protocol,int depth = 20) {
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- if (IsIpv6())
- {
- Ipv6Address ad(intf, port);
- if (ad.IsValid())
- {
- return Bind(ad, protocol, depth);
- }
- Handler().LogError(this, "Bind", 0, "name resolution of interface name failed", LOG_LEVEL_FATAL);
- return -1;
- }
- else
+ if (IsIpv6())
+ {
+ Ipv6Address ad(intf, port);
+ if (ad.IsValid())
+ {
+ return Bind(ad, protocol, depth);
+ }
+ Handler().LogError(this, "Bind", 0, "name resolution of interface name failed", LOG_LEVEL_FATAL);
+ return -1;
+ }
+ else
#endif
#endif
- {
- Ipv4Address ad(intf, port);
- if (ad.IsValid())
- {
- return Bind(ad, protocol, depth);
- }
- Handler().LogError(this, "Bind", 0, "name resolution of interface name failed", LOG_LEVEL_FATAL);
- return -1;
- }
- }
-
- /** Bind and listen to ipv4 interface.
- \param a Ipv4 interface address
- \param port Port (0 is random)
- \param depth Listen queue depth */
- int Bind(ipaddr_t a,port_t port,int depth = 20) {
- Ipv4Address ad(a, port);
+ {
+ Ipv4Address ad(intf, port);
+ if (ad.IsValid())
+ {
+ return Bind(ad, protocol, depth);
+ }
+ Handler().LogError(this, "Bind", 0, "name resolution of interface name failed", LOG_LEVEL_FATAL);
+ return -1;
+ }
+ }
+
+ /** Bind and listen to ipv4 interface.
+ \param a Ipv4 interface address
+ \param port Port (0 is random)
+ \param depth Listen queue depth */
+ int Bind(ipaddr_t a,port_t port,int depth = 20) {
+ Ipv4Address ad(a, port);
#ifdef USE_SCTP
- if (dynamic_cast<SctpSocket *>(m_creator))
- {
- return Bind(ad, "sctp", depth);
- }
+ if (dynamic_cast<SctpSocket *>(m_creator))
+ {
+ return Bind(ad, "sctp", depth);
+ }
#endif
- return Bind(ad, "tcp", depth);
- }
- /** Bind and listen to ipv4 interface.
- \param a Ipv4 interface address
- \param port Port (0 is random)
- \param protocol Network protocol
- \param depth Listen queue depth */
- int Bind(ipaddr_t a,port_t port,const std::string& protocol,int depth) {
- Ipv4Address ad(a, port);
- return Bind(ad, protocol, depth);
- }
+ return Bind(ad, "tcp", depth);
+ }
+ /** Bind and listen to ipv4 interface.
+ \param a Ipv4 interface address
+ \param port Port (0 is random)
+ \param protocol Network protocol
+ \param depth Listen queue depth */
+ int Bind(ipaddr_t a,port_t port,const std::string& protocol,int depth) {
+ Ipv4Address ad(a, port);
+ return Bind(ad, protocol, depth);
+ }
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- /** Bind and listen to ipv6 interface.
- \param a Ipv6 interface address
- \param port Port (0 is random)
- \param depth Listen queue depth */
- int Bind(in6_addr a,port_t port,int depth = 20) {
- Ipv6Address ad(a, port);
+ /** Bind and listen to ipv6 interface.
+ \param a Ipv6 interface address
+ \param port Port (0 is random)
+ \param depth Listen queue depth */
+ int Bind(in6_addr a,port_t port,int depth = 20) {
+ Ipv6Address ad(a, port);
#ifdef USE_SCTP
- if (dynamic_cast<SctpSocket *>(m_creator))
- {
- return Bind(ad, "sctp", depth);
- }
+ if (dynamic_cast<SctpSocket *>(m_creator))
+ {
+ return Bind(ad, "sctp", depth);
+ }
#endif
- return Bind(ad, "tcp", depth);
- }
- /** Bind and listen to ipv6 interface.
- \param a Ipv6 interface address
- \param port Port (0 is random)
- \param protocol Network protocol
- \param depth Listen queue depth */
- int Bind(in6_addr a,port_t port,const std::string& protocol,int depth) {
- Ipv6Address ad(a, port);
- return Bind(ad, protocol, depth);
- }
+ return Bind(ad, "tcp", depth);
+ }
+ /** Bind and listen to ipv6 interface.
+ \param a Ipv6 interface address
+ \param port Port (0 is random)
+ \param protocol Network protocol
+ \param depth Listen queue depth */
+ int Bind(in6_addr a,port_t port,const std::string& protocol,int depth) {
+ Ipv6Address ad(a, port);
+ return Bind(ad, protocol, depth);
+ }
#endif
#endif
- /** Bind and listen to network interface.
- \param ad Interface address
- \param protocol Network protocol
- \param depth Listen queue depth */
- int Bind(SocketAddress& ad,const std::string& protocol,int depth) {
- SOCKET s;
- if ( (s = CreateSocket(ad.GetFamily(), SOCK_STREAM, protocol)) == INVALID_SOCKET)
- {
- return -1;
- }
- if (bind(s, ad, ad) == -1)
- {
- Handler().LogError(this, "bind", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- closesocket(s);
+ /** Bind and listen to network interface.
+ \param ad Interface address
+ \param protocol Network protocol
+ \param depth Listen queue depth */
+ int Bind(SocketAddress& ad,const std::string& protocol,int depth) {
+ SOCKET s;
+ if ( (s = CreateSocket(ad.GetFamily(), SOCK_STREAM, protocol)) == INVALID_SOCKET)
+ {
+ return -1;
+ }
+ if (bind(s, ad, ad) == -1)
+ {
+ Handler().LogError(this, "bind", Errno, StrError(Errno), LOG_LEVEL_FATAL);
+ closesocket(s);
#ifdef ENABLE_EXCEPTIONS
- throw Exception("bind() failed for port " + Utility::l2string(ad.GetPort()) + ": " + StrError(Errno));
+ throw Exception("bind() failed for port " + Utility::l2string(ad.GetPort()) + ": " + StrError(Errno));
#endif
- return -1;
- }
- if (listen(s, depth) == -1)
- {
- Handler().LogError(this, "listen", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- closesocket(s);
+ return -1;
+ }
+ if (listen(s, depth) == -1)
+ {
+ Handler().LogError(this, "listen", Errno, StrError(Errno), LOG_LEVEL_FATAL);
+ closesocket(s);
#ifdef ENABLE_EXCEPTIONS
- throw Exception("listen() failed for port " + Utility::l2string(ad.GetPort()) + ": " + StrError(Errno));
+ throw Exception("listen() failed for port " + Utility::l2string(ad.GetPort()) + ": " + StrError(Errno));
#endif
- return -1;
- }
- m_depth = depth;
- 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);
- return;
- }
- if (!Handler().OkToAccept(this))
- {
- Handler().LogError(this, "accept", -1, "Not OK to accept", LOG_LEVEL_WARNING);
- closesocket(a_s);
- return;
- }
- if (Handler().GetCount() >= FD_SETSIZE)
- {
- Handler().LogError(this, "accept", (int)Handler().GetCount(), "ISocketHandler fd_set limit reached", LOG_LEVEL_FATAL);
- closesocket(a_s);
- return;
- }
- Socket *tmp = m_bHasCreate ? m_creator -> Create() : new X(Handler());
+ return -1;
+ }
+ m_depth = depth;
+ 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);
+ return;
+ }
+ if (!Handler().OkToAccept(this))
+ {
+ Handler().LogError(this, "accept", -1, "Not OK to accept", LOG_LEVEL_WARNING);
+ closesocket(a_s);
+ return;
+ }
+ if (Handler().GetCount() >= FD_SETSIZE)
+ {
+ Handler().LogError(this, "accept", (int)Handler().GetCount(), "ISocketHandler fd_set limit reached", LOG_LEVEL_FATAL);
+ closesocket(a_s);
+ return;
+ }
+ Socket *tmp = m_bHasCreate ? m_creator -> Create() : new X(Handler());
#ifdef ENABLE_IPV6
- tmp -> SetIpv6( IsIpv6() );
+ tmp -> SetIpv6( IsIpv6() );
#endif
- tmp -> SetParent(this);
- tmp -> Attach(a_s);
- tmp -> SetNonblocking(true);
- {
+ tmp -> SetParent(this);
+ tmp -> Attach(a_s);
+ tmp -> SetNonblocking(true);
+ {
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- if (sa_len == sizeof(struct sockaddr_in6))
- {
- struct sockaddr_in6 *p = (struct sockaddr_in6 *)&sa;
- if (p -> sin6_family == AF_INET6)
- {
- Ipv6Address ad(p -> sin6_addr,ntohs(p -> sin6_port));
- ad.SetFlowinfo(p -> sin6_flowinfo);
+ if (sa_len == sizeof(struct sockaddr_in6))
+ {
+ struct sockaddr_in6 *p = (struct sockaddr_in6 *)&sa;
+ if (p -> sin6_family == AF_INET6)
+ {
+ Ipv6Address ad(p -> sin6_addr,ntohs(p -> sin6_port));
+ ad.SetFlowinfo(p -> sin6_flowinfo);
#ifndef _WIN32
- ad.SetScopeId(p -> sin6_scope_id);
+ ad.SetScopeId(p -> sin6_scope_id);
#endif
- tmp -> SetRemoteAddress(ad);
- }
- }
+ tmp -> SetRemoteAddress(ad);
+ }
+ }
#endif
#endif
- if (sa_len == sizeof(struct sockaddr_in))
- {
- struct sockaddr_in *p = (struct sockaddr_in *)&sa;
- if (p -> sin_family == AF_INET)
- {
- Ipv4Address ad(p -> sin_addr,ntohs(p -> sin_port));
- tmp -> SetRemoteAddress(ad);
- }
- }
- }
- tmp -> SetConnected(true);
- tmp -> Init();
- tmp -> SetDeleteByHandler(true);
- Handler().Add(tmp);
+ if (sa_len == sizeof(struct sockaddr_in))
+ {
+ struct sockaddr_in *p = (struct sockaddr_in *)&sa;
+ if (p -> sin_family == AF_INET)
+ {
+ Ipv4Address ad(p -> sin_addr,ntohs(p -> sin_port));
+ tmp -> SetRemoteAddress(ad);
+ }
+ }
+ }
+ tmp -> SetConnected(true);
+ tmp -> Init();
+ tmp -> SetDeleteByHandler(true);
+ Handler().Add(tmp);
#ifdef HAVE_OPENSSL
- if (tmp -> IsSSL()) // SSL Enabled socket
- {
- // %! OnSSLAccept calls SSLNegotiate that can finish in this one call.
- // %! If that happens and negotiation fails, the 'tmp' instance is
- // %! still added to the list of active sockets in the sockethandler.
- // %! See bugfix for this in SocketHandler::Select - don't Set rwx
- // %! flags if CloseAndDelete() flag is true.
- // %! An even better fugbix (see TcpSocket::OnSSLAccept) now avoids
- // %! the Add problem altogether, so ignore the above.
- // %! (OnSSLAccept does no longer call SSLNegotiate().)
- tmp -> OnSSLAccept();
- }
- else
+ if (tmp -> IsSSL()) // SSL Enabled socket
+ {
+ // %! OnSSLAccept calls SSLNegotiate that can finish in this one call.
+ // %! If that happens and negotiation fails, the 'tmp' instance is
+ // %! still added to the list of active sockets in the sockethandler.
+ // %! See bugfix for this in SocketHandler::Select - don't Set rwx
+ // %! flags if CloseAndDelete() flag is true.
+ // %! An even better fugbix (see TcpSocket::OnSSLAccept) now avoids
+ // %! the Add problem altogether, so ignore the above.
+ // %! (OnSSLAccept does no longer call SSLNegotiate().)
+ tmp -> OnSSLAccept();
+ }
+ else
#endif
- {
- tmp -> OnAccept();
- }
- }
+ {
+ tmp -> OnAccept();
+ }
+ }
- /** Please don't use this method.
- "accept()" is handled automatically in the OnRead() method. */
+ /** 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);
@@ -397,17 +397,17 @@ public:
bool HasCreator() { return m_bHasCreate; }
- void OnOptions(int,int,int,SOCKET) {
- SetSoReuseaddr(true);
- }
+ void OnOptions(int,int,int,SOCKET) {
+ SetSoReuseaddr(true);
+ }
protected:
- ListenSocket(const ListenSocket& s) : Socket(s) {}
+ ListenSocket(const ListenSocket& s) : Socket(s) {}
private:
- ListenSocket& operator=(const ListenSocket& ) { return *this; }
- int m_depth;
- X *m_creator;
- bool m_bHasCreate;
+ ListenSocket& operator=(const ListenSocket& ) { return *this; }
+ int m_depth;
+ X *m_creator;
+ bool m_bHasCreate;
};
diff --git a/dep/include/sockets/Lock.h b/dep/include/sockets/Lock.h
index 71fdd5e733d..7d67716a26a 100644
--- a/dep/include/sockets/Lock.h
+++ b/dep/include/sockets/Lock.h
@@ -1,6 +1,6 @@
/** \file Lock.h
- ** \date 2005-08-22
- ** \author grymse@alhem.net
+ ** \date 2005-08-22
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2005,2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -37,16 +37,16 @@ namespace SOCKETS_NAMESPACE {
class Mutex;
-/** Mutex encapsulation class.
- \ingroup threading */
+/** Mutex encapsulation class.
+ \ingroup threading */
class Lock
{
public:
- Lock(Mutex&);
- ~Lock();
+ Lock(Mutex&);
+ ~Lock();
private:
- Mutex& m_mutex;
+ Mutex& m_mutex;
};
diff --git a/dep/include/sockets/Mutex.h b/dep/include/sockets/Mutex.h
index 1de27760a1c..35b753ca028 100644
--- a/dep/include/sockets/Mutex.h
+++ b/dep/include/sockets/Mutex.h
@@ -1,6 +1,6 @@
/** \file Mutex.h
- ** \date 2004-10-30
- ** \author grymse@alhem.net
+ ** \date 2004-10-30
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -41,22 +41,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
namespace SOCKETS_NAMESPACE {
#endif
-/** Mutex container class, used by Lock.
- \ingroup threading */
+/** Mutex container class, used by Lock.
+ \ingroup threading */
class Mutex
{
- friend class Lock;
+ friend class Lock;
public:
- Mutex();
- ~Mutex();
+ Mutex();
+ ~Mutex();
- void Lock();
- void Unlock();
+ void Lock();
+ void Unlock();
private:
#ifdef _WIN32
- HANDLE m_mutex;
+ HANDLE m_mutex;
#else
- pthread_mutex_t m_mutex;
+ pthread_mutex_t m_mutex;
#endif
};
diff --git a/dep/include/sockets/Parse.h b/dep/include/sockets/Parse.h
index 6961f3b1bc9..b5d15f00f5c 100644
--- a/dep/include/sockets/Parse.h
+++ b/dep/include/sockets/Parse.h
@@ -1,6 +1,6 @@
/** \file Parse.h - parse a string
**
- ** Written: 1999-Feb-10 grymse@alhem.net
+ ** Written: 1999-Feb-10 grymse@alhem.net
**/
/*
@@ -9,7 +9,7 @@ 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
+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.
@@ -48,48 +48,48 @@ namespace SOCKETS_NAMESPACE {
/* interface of class Parse */
/** Splits a string whatever way you want.
- \ingroup util */
+ \ingroup util */
class Parse
{
public:
- Parse();
- Parse(const std::string&);
- Parse(const std::string&,const std::string&);
- Parse(const std::string&,const std::string&,short);
- ~Parse();
- short issplit(const char);
- void getsplit();
- void getsplit(std::string&);
- std::string getword();
- void getword(std::string&);
- void getword(std::string&,std::string&,int);
- std::string getrest();
- void getrest(std::string&);
- long getvalue();
- void setbreak(const char);
- int getwordlen();
- int getrestlen();
- void enablebreak(const char c) {
- pa_enable = c;
- }
- void disablebreak(const char c) {
- pa_disable = c;
- }
- void getline();
- void getline(std::string&);
- size_t getptr() { return pa_the_ptr; }
- void EnableQuote(bool b) { pa_quote = b; }
+ Parse();
+ Parse(const std::string&);
+ Parse(const std::string&,const std::string&);
+ Parse(const std::string&,const std::string&,short);
+ ~Parse();
+ short issplit(const char);
+ void getsplit();
+ void getsplit(std::string&);
+ std::string getword();
+ void getword(std::string&);
+ void getword(std::string&,std::string&,int);
+ std::string getrest();
+ void getrest(std::string&);
+ long getvalue();
+ void setbreak(const char);
+ int getwordlen();
+ int getrestlen();
+ void enablebreak(const char c) {
+ pa_enable = c;
+ }
+ void disablebreak(const char c) {
+ pa_disable = c;
+ }
+ void getline();
+ 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;
- std::string pa_ord;
- size_t pa_the_ptr;
- char pa_breakchar;
- char pa_enable;
- char pa_disable;
- short pa_nospace;
- bool pa_quote;
+ std::string pa_the_str;
+ std::string pa_splits;
+ std::string pa_ord;
+ size_t pa_the_ptr;
+ char pa_breakchar;
+ char pa_enable;
+ char pa_disable;
+ short pa_nospace;
+ bool pa_quote;
};
diff --git a/dep/include/sockets/ResolvServer.h b/dep/include/sockets/ResolvServer.h
index f8f8f5aadbf..05dcfd58adf 100644
--- a/dep/include/sockets/ResolvServer.h
+++ b/dep/include/sockets/ResolvServer.h
@@ -1,6 +1,6 @@
/** \file ResolvServer.h
- ** \date 2005-03-24
- ** \author grymse@alhem.net
+ ** \date 2005-03-24
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -39,26 +39,26 @@ namespace SOCKETS_NAMESPACE {
#endif
/** \defgroup async Asynchronous DNS */
-/** Async DNS resolver thread.
- \ingroup async */
+/** Async DNS resolver thread.
+ \ingroup async */
class ResolvServer : public Thread
{
public:
- ResolvServer(port_t);
- ~ResolvServer();
+ ResolvServer(port_t);
+ ~ResolvServer();
- void Run();
- void Quit();
+ void Run();
+ void Quit();
- bool Ready();
+ bool Ready();
private:
- ResolvServer(const ResolvServer& ) {} // copy constructor
- ResolvServer& operator=(const ResolvServer& ) { return *this; } // assignment operator
+ ResolvServer(const ResolvServer& ) {} // copy constructor
+ ResolvServer& operator=(const ResolvServer& ) { return *this; } // assignment operator
- bool m_quit;
- port_t m_port;
- bool m_ready;
+ bool m_quit;
+ port_t m_port;
+ bool m_ready;
};
diff --git a/dep/include/sockets/ResolvSocket.h b/dep/include/sockets/ResolvSocket.h
index ff4b1a5a982..2396af894de 100644
--- a/dep/include/sockets/ResolvSocket.h
+++ b/dep/include/sockets/ResolvSocket.h
@@ -1,6 +1,6 @@
/** \file ResolvSocket.h
- ** \date 2005-03-24
- ** \author grymse@alhem.net
+ ** \date 2005-03-24
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -40,58 +40,58 @@ namespace SOCKETS_NAMESPACE {
class Mutex;
-/** Async DNS resolver socket.
- \ingroup async */
+/** Async DNS resolver socket.
+ \ingroup async */
class ResolvSocket : public TcpSocket
{
- typedef std::map<std::string, /* type */
- 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 */
+ typedef std::map<std::string, /* type */
+ 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);
- ResolvSocket(ISocketHandler&, Socket *parent, ipaddr_t);
+ ResolvSocket(ISocketHandler&);
+ ResolvSocket(ISocketHandler&, Socket *parent, const std::string& host, port_t port, bool ipv6 = false);
+ ResolvSocket(ISocketHandler&, Socket *parent, ipaddr_t);
#ifdef ENABLE_IPV6
- ResolvSocket(ISocketHandler&, Socket *parent, in6_addr&);
+ ResolvSocket(ISocketHandler&, Socket *parent, in6_addr&);
#endif
- ~ResolvSocket();
+ ~ResolvSocket();
- void OnAccept() { m_bServer = true; }
- void OnLine(const std::string& line);
- void OnDetached();
- void OnDelete();
+ 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 SetId(int x) { m_resolv_id = x; }
+ int GetId() { return m_resolv_id; }
- void OnConnect();
+ void OnConnect();
#ifdef ENABLE_IPV6
- void SetResolveIpv6(bool x = true) { m_resolve_ipv6 = x; }
+ 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;
- Socket *m_parent;
- int m_resolv_id;
- std::string m_resolv_host;
- port_t m_resolv_port;
- ipaddr_t m_resolv_address;
+ 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;
+ Socket *m_parent;
+ int m_resolv_id;
+ std::string m_resolv_host;
+ port_t m_resolv_port;
+ ipaddr_t m_resolv_address;
#ifdef ENABLE_IPV6
- bool m_resolve_ipv6;
- in6_addr m_resolv_address6;
+ bool m_resolve_ipv6;
+ in6_addr m_resolv_address6;
#endif
- static cache_t m_cache;
- static timeout_t m_cache_to;
- static Mutex m_cache_mutex;
- bool m_cached;
+ static cache_t m_cache;
+ static timeout_t m_cache_to;
+ static Mutex m_cache_mutex;
+ bool m_cached;
};
diff --git a/dep/include/sockets/SctpSocket.h b/dep/include/sockets/SctpSocket.h
index d6d55f6be78..49a360b16da 100644
--- a/dep/include/sockets/SctpSocket.h
+++ b/dep/include/sockets/SctpSocket.h
@@ -1,7 +1,7 @@
/**
- ** \file SctpSocket.h
- ** \date 2006-09-04
- ** \author grymse@alhem.net
+ ** \file SctpSocket.h
+ ** \date 2006-09-04
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2007 Anders Hedstrom
@@ -40,63 +40,63 @@ class SocketAddress;
class SctpSocket : public StreamSocket
{
public:
- /** SctpSocket constructor.
- \param h Owner
- \param type SCTP_STREAM or SCTP_SEQPACKET */
- SctpSocket(ISocketHandler& h,int type);
- ~SctpSocket();
-
- /** bind() */
- int Bind(const std::string&,port_t);
- int Bind(SocketAddress&);
- /** sctp_bindx() */
- int AddAddress(const std::string&,port_t);
- int AddAddress(SocketAddress&);
- /** 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();
+ /** SctpSocket constructor.
+ \param h Owner
+ \param type SCTP_STREAM or SCTP_SEQPACKET */
+ SctpSocket(ISocketHandler& h,int type);
+ ~SctpSocket();
+
+ /** bind() */
+ int Bind(const std::string&,port_t);
+ int Bind(SocketAddress&);
+ /** sctp_bindx() */
+ int AddAddress(const std::string&,port_t);
+ int AddAddress(SocketAddress&);
+ /** 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();
+ /** Connection failed reported as exception on win32 */
+ void OnException();
#endif
#ifndef SOLARIS
- /** sctp_connectx() */
- int AddConnection(const std::string&,port_t);
- int AddConnection(SocketAddress&);
+ /** 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>&);
+ /** 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);
+ /** 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;
+ /** 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) {}
+ void OnOptions(int,int,int,SOCKET) {}
- virtual int Protocol();
+ virtual int Protocol();
protected:
- SctpSocket(const SctpSocket& s) : StreamSocket(s) {}
- void OnRead();
- void OnWrite();
+ 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
+ SctpSocket& operator=(const SctpSocket& s) { return *this; }
+ int m_type; ///< SCTP_STREAM or SCTP_SEQPACKET
+ char *m_buf; ///< Temporary receive buffer
};
diff --git a/dep/include/sockets/Socket.h b/dep/include/sockets/Socket.h
index bdb5fc60392..0545ad7f849 100644
--- a/dep/include/sockets/Socket.h
+++ b/dep/include/sockets/Socket.h
@@ -8,7 +8,7 @@ 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
+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.
@@ -56,677 +56,677 @@ class IFile;
/** \defgroup basic Basic sockets */
/** Socket base class.
- \ingroup basic */
+ \ingroup basic */
class Socket
{
- friend class ISocketHandler;
+ friend class ISocketHandler;
#ifdef ENABLE_DETACH
- /** Detached socket run thread.
- \ingroup internal */
- class SocketThread : public Thread
- {
- public:
- SocketThread(Socket *p);
- ~SocketThread();
-
- void Run();
-
- private:
- Socket *GetSocket() const { return m_socket; }
- SocketThread(const SocketThread& s) : m_socket(s.GetSocket()) {}
- SocketThread& operator=(const SocketThread& ) { return *this; }
- Socket *m_socket;
- };
+ /** Detached socket run thread.
+ \ingroup internal */
+ class SocketThread : public Thread
+ {
+ public:
+ SocketThread(Socket *p);
+ ~SocketThread();
+
+ void Run();
+
+ private:
+ Socket *GetSocket() const { return m_socket; }
+ SocketThread(const SocketThread& s) : m_socket(s.GetSocket()) {}
+ SocketThread& operator=(const SocketThread& ) { return *this; }
+ Socket *m_socket;
+ };
#endif // ENABLE_DETACH
#ifdef ENABLE_TRIGGERS
public:
- /** Data pass class from source to destination. */
- class TriggerData
- {
- public:
- TriggerData() : m_src(NULL) {}
- virtual ~TriggerData() {}
-
- Socket *GetSource() const { return m_src; }
- void SetSource(Socket *x) { m_src = x; }
-
- private:
- Socket *m_src;
- };
+ /** Data pass class from source to destination. */
+ class TriggerData
+ {
+ 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. */
+ /** Socket mode flags. */
/*
- enum {
- // Socket
- SOCK_DEL = 0x01, ///< Delete by handler flag
- 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
- SOCK_DETACH = 0x2000, ///< Socket ordered to detach flag
- 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
-
- };
+ enum {
+ // Socket
+ SOCK_DEL = 0x01, ///< Delete by handler flag
+ 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
+ SOCK_DETACH = 0x2000, ///< Socket ordered to detach flag
+ 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&);
+ /** "Default" constructor */
+ Socket(ISocketHandler&);
- virtual ~Socket();
+ 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; }
+ /** 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.
+ 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
- * it can't be called directly from the CTcpSocket constructor.
- * Also used to determine if incoming HTTP connection is normal (port 80)
- * 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. */
- virtual void OnWrite();
- /** Called on socket exception. */
- virtual void OnException();
- /** Called before a socket class is deleted by the ISocketHandler. */
- virtual void OnDelete();
- /** Called when a connection has completed. */
- virtual void OnConnect();
- /** Called when an incoming connection has been completed. */
- virtual void OnAccept();
- /** Called when a complete line has been read and the socket is in
- * line protocol mode. */
- virtual void OnLine(const std::string& );
- /** Called on connect timeout (5s). */
- virtual void OnConnectFailed();
- /** Called when a client socket is created, to set socket options.
- \param family AF_INET, AF_INET6, etc
- \param type SOCK_STREAM, SOCK_DGRAM, etc
- \param protocol Protocol number (tcp, udp, sctp, etc)
- \param s Socket file descriptor
- */
- virtual void OnOptions(int family,int type,int protocol,SOCKET s) = 0;
- /** Connection retry callback - return false to abort connection attempts */
- virtual bool OnConnectRetry();
+ /** 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
+ * it can't be called directly from the CTcpSocket constructor.
+ * Also used to determine if incoming HTTP connection is normal (port 80)
+ * 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. */
+ virtual void OnWrite();
+ /** Called on socket exception. */
+ virtual void OnException();
+ /** Called before a socket class is deleted by the ISocketHandler. */
+ virtual void OnDelete();
+ /** Called when a connection has completed. */
+ virtual void OnConnect();
+ /** Called when an incoming connection has been completed. */
+ virtual void OnAccept();
+ /** Called when a complete line has been read and the socket is in
+ * line protocol mode. */
+ virtual void OnLine(const std::string& );
+ /** Called on connect timeout (5s). */
+ virtual void OnConnectFailed();
+ /** Called when a client socket is created, to set socket options.
+ \param family AF_INET, AF_INET6, etc
+ \param type SOCK_STREAM, SOCK_DGRAM, etc
+ \param protocol Protocol number (tcp, udp, sctp, etc)
+ \param s Socket file descriptor
+ */
+ virtual void OnOptions(int family,int type,int protocol,SOCKET s) = 0;
+ /** Connection retry callback - return false to abort connection attempts */
+ virtual bool OnConnectRetry();
#ifdef ENABLE_RECONNECT
- /** a reconnect has been made */
- virtual void OnReconnect();
-#endif
- /** TcpSocket: When a disconnect has been detected (recv/SSL_read returns 0 bytes). */
- virtual void OnDisconnect();
- /** Timeout callback. */
- virtual void OnTimeout();
- /** Connection timeout. */
- virtual void OnConnectTimeout();
- //@}
-
- /** \name Socket mode flags, set/reset */
- //@{
- /** Set delete by handler true when you want the sockethandler to
- delete the socket instance after use. */
- void SetDeleteByHandler(bool = true);
- /** 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. */
- std::auto_ptr<SocketAddress> GetRemoteSocketAddress();
- /** Returns address of remote end: ipv4. */
- ipaddr_t GetRemoteIP4();
+ /** a reconnect has been made */
+ virtual void OnReconnect();
+#endif
+ /** TcpSocket: When a disconnect has been detected (recv/SSL_read returns 0 bytes). */
+ virtual void OnDisconnect();
+ /** Timeout callback. */
+ virtual void OnTimeout();
+ /** Connection timeout. */
+ virtual void OnConnectTimeout();
+ //@}
+
+ /** \name Socket mode flags, set/reset */
+ //@{
+ /** Set delete by handler true when you want the sockethandler to
+ delete the socket instance after use. */
+ void SetDeleteByHandler(bool = true);
+ /** 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. */
+ std::auto_ptr<SocketAddress> GetRemoteSocketAddress();
+ /** Returns address of remote end: ipv4. */
+ ipaddr_t GetRemoteIP4();
#ifdef ENABLE_IPV6
- /** Returns address of remote end: ipv6. */
+ /** Returns address of remote end: ipv6. */
#ifdef IPPROTO_IPV6
- struct in6_addr GetRemoteIP6();
-#endif
-#endif
- /** Returns remote port number: ipv4 and ipv6. */
- port_t GetRemotePort();
- /** Returns remote ip as string? ipv4 and ipv6. */
- std::string GetRemoteAddress();
- /** 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. */
- ipaddr_t GetSockIP4();
- /** Returns local ipv4 address as text for bound socket file descriptor. */
- std::string GetSockAddress();
+ struct in6_addr GetRemoteIP6();
+#endif
+#endif
+ /** Returns remote port number: ipv4 and ipv6. */
+ port_t GetRemotePort();
+ /** Returns remote ip as string? ipv4 and ipv6. */
+ std::string GetRemoteAddress();
+ /** 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. */
+ ipaddr_t GetSockIP4();
+ /** Returns local ipv4 address as text for bound socket file descriptor. */
+ std::string GetSockAddress();
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- /** Returns local ipv6 address for bound socket file descriptor. */
- struct in6_addr GetSockIP6();
- /** Returns local ipv6 address as text for bound socket file descriptor. */
- std::string GetSockAddress6();
-#endif
-#endif
- // --------------------------------------------------------------------------
- /** @name IP options
- When an ip or socket option is available on all of the operating systems
- I'm testing on (linux 2.4.x, _win32, macosx, solaris9 intel) they are not
- 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();
- bool SetIpTTL(int ttl);
- int IpTTL();
- bool SetIpHdrincl(bool x = true);
- bool SetIpMulticastTTL(int);
- int IpMulticastTTL();
- bool SetMulticastLoop(bool x = true);
- bool IpAddMembership(struct ip_mreq&);
- bool IpDropMembership(struct ip_mreq&);
+ /** Returns local ipv6 address for bound socket file descriptor. */
+ struct in6_addr GetSockIP6();
+ /** Returns local ipv6 address as text for bound socket file descriptor. */
+ std::string GetSockAddress6();
+#endif
+#endif
+ // --------------------------------------------------------------------------
+ /** @name IP options
+ When an ip or socket option is available on all of the operating systems
+ I'm testing on (linux 2.4.x, _win32, macosx, solaris9 intel) they are not
+ 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();
+ bool SetIpTTL(int ttl);
+ int IpTTL();
+ bool SetIpHdrincl(bool x = true);
+ bool SetIpMulticastTTL(int);
+ int IpMulticastTTL();
+ bool SetMulticastLoop(bool x = true);
+ bool IpAddMembership(struct ip_mreq&);
+ bool IpDropMembership(struct ip_mreq&);
#ifdef IP_PKTINFO
- bool SetIpPktinfo(bool x = true);
+ bool SetIpPktinfo(bool x = true);
#endif
#ifdef IP_RECVTOS
- bool SetIpRecvTOS(bool x = true);
+ bool SetIpRecvTOS(bool x = true);
#endif
#ifdef IP_RECVTTL
- bool SetIpRecvTTL(bool x = true);
+ bool SetIpRecvTTL(bool x = true);
#endif
#ifdef IP_RECVOPTS
- bool SetIpRecvopts(bool x = true);
+ bool SetIpRecvopts(bool x = true);
#endif
#ifdef IP_RETOPTS
- bool SetIpRetopts(bool x = true);
+ bool SetIpRetopts(bool x = true);
#endif
#ifdef IP_RECVERR
- bool SetIpRecverr(bool x = true);
+ bool SetIpRecverr(bool x = true);
#endif
#ifdef IP_MTU_DISCOVER
- bool SetIpMtudiscover(bool x = true);
+ bool SetIpMtudiscover(bool x = true);
#endif
#ifdef IP_MTU
- int IpMtu();
+ int IpMtu();
#endif
#ifdef IP_ROUTER_ALERT
- bool SetIpRouterAlert(bool x = true);
+ bool SetIpRouterAlert(bool x = true);
#endif
#ifdef LINUX
- bool IpAddMembership(struct ip_mreqn&);
+ bool IpAddMembership(struct ip_mreqn&);
#endif
#ifdef LINUX
- bool IpDropMembership(struct ip_mreqn&);
-#endif
- //@}
-
- // SOCKET options
- /** @name Socket Options */
- //@{
-
- bool SoAcceptconn();
- bool SetSoBroadcast(bool x = true);
- bool SetSoDebug(bool x = true);
- int SoError();
- bool SetSoDontroute(bool x = true);
- bool SetSoLinger(int onoff, int linger);
- bool SetSoOobinline(bool x = true);
- bool SetSoRcvlowat(int);
- bool SetSoSndlowat(int);
- bool SetSoRcvtimeo(struct timeval&);
- bool SetSoSndtimeo(struct timeval&);
- bool SetSoRcvbuf(int);
- int SoRcvbuf();
- bool SetSoSndbuf(int);
- int SoSndbuf();
- int SoType();
- bool SetSoReuseaddr(bool x = true);
- bool SetSoKeepalive(bool x = true);
+ bool IpDropMembership(struct ip_mreqn&);
+#endif
+ //@}
+
+ // SOCKET options
+ /** @name Socket Options */
+ //@{
+
+ bool SoAcceptconn();
+ bool SetSoBroadcast(bool x = true);
+ bool SetSoDebug(bool x = true);
+ int SoError();
+ bool SetSoDontroute(bool x = true);
+ bool SetSoLinger(int onoff, int linger);
+ bool SetSoOobinline(bool x = true);
+ bool SetSoRcvlowat(int);
+ bool SetSoSndlowat(int);
+ bool SetSoRcvtimeo(struct timeval&);
+ bool SetSoSndtimeo(struct timeval&);
+ bool SetSoRcvbuf(int);
+ int SoRcvbuf();
+ bool SetSoSndbuf(int);
+ int SoSndbuf();
+ int SoType();
+ bool SetSoReuseaddr(bool x = true);
+ bool SetSoKeepalive(bool x = true);
#ifdef SO_BSDCOMPAT
- bool SetSoBsdcompat(bool x = true);
+ bool SetSoBsdcompat(bool x = true);
#endif
#ifdef SO_BINDTODEVICE
- bool SetSoBindtodevice(const std::string& intf);
+ bool SetSoBindtodevice(const std::string& intf);
#endif
#ifdef SO_PASSCRED
- bool SetSoPasscred(bool x = true);
+ bool SetSoPasscred(bool x = true);
#endif
#ifdef SO_PEERCRED
- bool SoPeercred(struct ucred& );
+ bool SoPeercred(struct ucred& );
#endif
#ifdef SO_PRIORITY
- bool SetSoPriority(int);
+ bool SetSoPriority(int);
#endif
#ifdef SO_RCVBUFFORCE
- bool SetSoRcvbufforce(int);
+ bool SetSoRcvbufforce(int);
#endif
#ifdef SO_SNDBUFFORCE
- bool SetSoSndbufforce(int);
+ bool SetSoSndbufforce(int);
#endif
#ifdef SO_TIMESTAMP
- bool SetSoTimestamp(bool x = true);
+ bool SetSoTimestamp(bool x = true);
#endif
#ifdef SO_NOSIGPIPE
- bool SetSoNosigpipe(bool x = true);
+ bool SetSoNosigpipe(bool x = true);
#endif
- //@}
+ //@}
- // TCP options in TcpSocket.h/TcpSocket.cpp
+ // TCP options in TcpSocket.h/TcpSocket.cpp
#ifdef HAVE_OPENSSL
- /** @name SSL Support */
- //@{
- /** SSL client/server support - internal use. \sa TcpSocket */
- virtual void OnSSLConnect();
- /** SSL client/server support - internal use. \sa TcpSocket */
- virtual void OnSSLAccept();
- /** SSL negotiation failed for client connect. */
- virtual void OnSSLConnectFailed();
- /** SSL negotiation failed for server accept. */
- virtual void OnSSLAcceptFailed();
- /** new SSL support */
- virtual bool SSLNegotiate();
- /** Check if SSL is Enabled for this TcpSocket.
- \return true if this is a TcpSocket with SSL enabled */
- bool IsSSL();
- /** Enable SSL operation for a TcpSocket. */
- void EnableSSL(bool x = true);
- /** Still negotiating ssl connection.
- \return true if ssl negotiating is still in progress */
- bool IsSSLNegotiate();
- /** Set flag indicating ssl handshaking still in progress. */
- void SetSSLNegotiate(bool x = true);
- /** OnAccept called with SSL Enabled.
- \return true if this is a TcpSocket with an incoming SSL connection */
- bool IsSSLServer();
- /** Set flag indicating that this is a TcpSocket with incoming SSL connection. */
- void SetSSLServer(bool x = true);
- /** SSL; Get pointer to ssl context structure. */
- virtual SSL_CTX *GetSslContext() { return NULL; }
- /** SSL; Get pointer to ssl structure. */
- virtual SSL *GetSsl() { return NULL; }
- //@}
+ /** @name SSL Support */
+ //@{
+ /** SSL client/server support - internal use. \sa TcpSocket */
+ virtual void OnSSLConnect();
+ /** SSL client/server support - internal use. \sa TcpSocket */
+ virtual void OnSSLAccept();
+ /** SSL negotiation failed for client connect. */
+ virtual void OnSSLConnectFailed();
+ /** SSL negotiation failed for server accept. */
+ virtual void OnSSLAcceptFailed();
+ /** new SSL support */
+ virtual bool SSLNegotiate();
+ /** Check if SSL is Enabled for this TcpSocket.
+ \return true if this is a TcpSocket with SSL enabled */
+ bool IsSSL();
+ /** Enable SSL operation for a TcpSocket. */
+ void EnableSSL(bool x = true);
+ /** Still negotiating ssl connection.
+ \return true if ssl negotiating is still in progress */
+ bool IsSSLNegotiate();
+ /** Set flag indicating ssl handshaking still in progress. */
+ void SetSSLNegotiate(bool x = true);
+ /** OnAccept called with SSL Enabled.
+ \return true if this is a TcpSocket with an incoming SSL connection */
+ bool IsSSLServer();
+ /** Set flag indicating that this is a TcpSocket with incoming SSL connection. */
+ void SetSSLServer(bool x = true);
+ /** SSL; Get pointer to ssl context structure. */
+ virtual SSL_CTX *GetSslContext() { return NULL; }
+ /** SSL; Get pointer to ssl structure. */
+ virtual SSL *GetSsl() { return NULL; }
+ //@}
#endif // HAVE_OPENSSL
#ifdef ENABLE_IPV6
- /** Enable ipv6 for this socket. */
- void SetIpv6(bool x = true);
- /** Check ipv6 socket.
- \return true if this is an ipv6 socket */
- bool IsIpv6();
+ /** Enable ipv6 for this socket. */
+ void SetIpv6(bool x = true);
+ /** Check ipv6 socket.
+ \return true if this is an ipv6 socket */
+ bool IsIpv6();
#endif
#ifdef ENABLE_POOL
- /** @name Connection Pool */
- //@{
- /** Client = connecting TcpSocket. */
- void SetIsClient();
- /** Socket type from socket() call. */
- void SetSocketType(int x);
- /** Socket type from socket() call. */
- int GetSocketType();
- /** Protocol type from socket() call. */
- void SetSocketProtocol(const std::string& x);
- /** Protocol type from socket() call. */
- const std::string& GetSocketProtocol();
- /** Instruct a client socket to stay open in the connection pool after use.
- If you have connected to a server using tcp, you can call SetRetain
- to leave the connection open after your socket instance has been deleted.
- The next connection you make to the same server will reuse the already
- opened connection, if it is still available.
- */
- void SetRetain();
- /** Check retain flag.
- \return true if the socket should be moved to connection pool after use */
- bool Retain();
- /** Copy connection parameters from sock. */
- void CopyConnection(Socket *sock);
- //@}
+ /** @name Connection Pool */
+ //@{
+ /** Client = connecting TcpSocket. */
+ void SetIsClient();
+ /** Socket type from socket() call. */
+ void SetSocketType(int x);
+ /** Socket type from socket() call. */
+ int GetSocketType();
+ /** Protocol type from socket() call. */
+ void SetSocketProtocol(const std::string& x);
+ /** Protocol type from socket() call. */
+ const std::string& GetSocketProtocol();
+ /** Instruct a client socket to stay open in the connection pool after use.
+ If you have connected to a server using tcp, you can call SetRetain
+ to leave the connection open after your socket instance has been deleted.
+ The next connection you make to the same server will reuse the already
+ opened connection, if it is still available.
+ */
+ void SetRetain();
+ /** Check retain flag.
+ \return true if the socket should be moved to connection pool after use */
+ bool Retain();
+ /** Copy connection parameters from sock. */
+ void CopyConnection(Socket *sock);
+ //@}
#endif // ENABLE_POOL
#ifdef ENABLE_SOCKS4
- /** \name Socks4 support */
- //@{
- /** Socks4 client support internal use. \sa TcpSocket */
- virtual void OnSocks4Connect();
- /** Socks4 client support internal use. \sa TcpSocket */
- virtual void OnSocks4ConnectFailed();
- /** Socks4 client support internal use. \sa TcpSocket */
- virtual bool OnSocks4Read();
- /** Called when the last write caused the tcp output buffer to
- * become empty. */
- /** socket still in socks4 negotiation mode */
- 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. */
- void SetSocks4Host(const std::string& );
- /** Socks4 server port to use. */
- void SetSocks4Port(port_t p);
- /** Provide a socks4 userid if required by the socks4 server. */
- void SetSocks4Userid(const std::string& x);
- /** Get the ip address of socks4 server to use.
- \return socks4 server host address */
- ipaddr_t GetSocks4Host();
- /** Get the socks4 server port to use.
- \return socks4 server port */
- port_t GetSocks4Port();
- /** Get socks4 userid.
- \return Socks4 userid */
- const std::string& GetSocks4Userid();
- //@}
+ /** \name Socks4 support */
+ //@{
+ /** Socks4 client support internal use. \sa TcpSocket */
+ virtual void OnSocks4Connect();
+ /** Socks4 client support internal use. \sa TcpSocket */
+ virtual void OnSocks4ConnectFailed();
+ /** Socks4 client support internal use. \sa TcpSocket */
+ virtual bool OnSocks4Read();
+ /** Called when the last write caused the tcp output buffer to
+ * become empty. */
+ /** socket still in socks4 negotiation mode */
+ 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. */
+ void SetSocks4Host(const std::string& );
+ /** Socks4 server port to use. */
+ void SetSocks4Port(port_t p);
+ /** Provide a socks4 userid if required by the socks4 server. */
+ void SetSocks4Userid(const std::string& x);
+ /** Get the ip address of socks4 server to use.
+ \return socks4 server host address */
+ ipaddr_t GetSocks4Host();
+ /** Get the socks4 server port to use.
+ \return socks4 server port */
+ port_t GetSocks4Port();
+ /** Get socks4 userid.
+ \return Socks4 userid */
+ const std::string& GetSocks4Userid();
+ //@}
#endif // ENABLE_SOCKS4
#ifdef ENABLE_RESOLVER
- /** \name Asynchronous Resolver */
- //@{
- /** Request an asynchronous dns resolution.
- \param host hostname to be resolved
- \param port port number passed along for the ride
- \return Resolve ID */
- int Resolve(const std::string& host,port_t port = 0);
+ /** \name Asynchronous Resolver */
+ //@{
+ /** Request an asynchronous dns resolution.
+ \param host hostname to be resolved
+ \param port port number passed along for the ride
+ \return Resolve ID */
+ int Resolve(const std::string& host,port_t port = 0);
#ifdef ENABLE_IPV6
- int Resolve6(const std::string& host, port_t port = 0);
+ int Resolve6(const std::string& host, port_t port = 0);
#endif
- /** Callback returning a resolved address.
- \param id Resolve ID from Resolve call
- \param a resolved ip address
- \param port port number passed to Resolve */
- virtual void OnResolved(int id,ipaddr_t a,port_t port);
+ /** Callback returning a resolved address.
+ \param id Resolve ID from Resolve call
+ \param a resolved ip address
+ \param port port number passed to Resolve */
+ virtual void OnResolved(int id,ipaddr_t a,port_t port);
#ifdef ENABLE_IPV6
- virtual void OnResolved(int id,in6_addr& a,port_t port);
+ virtual void OnResolved(int id,in6_addr& a,port_t port);
#endif
- /** Request asynchronous reverse dns lookup.
- \param a in_addr to be translated */
- int Resolve(ipaddr_t a);
+ /** Request asynchronous reverse dns lookup.
+ \param a in_addr to be translated */
+ int Resolve(ipaddr_t a);
#ifdef ENABLE_IPV6
- int Resolve(in6_addr& a);
-#endif
- /** Callback returning reverse resolve results.
- \param id Resolve ID
- \param name Resolved hostname */
- virtual void OnReverseResolved(int id,const std::string& name);
- /** Callback indicating failed dns lookup.
- \param id Resolve ID */
- virtual void OnResolveFailed(int id);
- //@}
+ int Resolve(in6_addr& a);
+#endif
+ /** Callback returning reverse resolve results.
+ \param id Resolve ID
+ \param name Resolved hostname */
+ virtual void OnReverseResolved(int id,const std::string& name);
+ /** Callback indicating failed dns lookup.
+ \param id Resolve ID */
+ virtual void OnResolveFailed(int id);
+ //@}
#endif // ENABLE_RESOLVER
#ifdef ENABLE_DETACH
- /** \name Thread Support */
- //@{
- /** Callback fires when a new socket thread has started and this
- 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.
- \return true if the socket runs in its own thread. */
- const bool IsDetached() const;
- /** Order this socket to start its own thread and call OnDetached
- when ready for operation. */
- bool Detach();
- /** Store the slave sockethandler pointer. */
- void SetSlaveHandler(ISocketHandler *);
- /** Create new thread for this socket to run detached in. */
- void DetachSocket();
- //@}
+ /** \name Thread Support */
+ //@{
+ /** Callback fires when a new socket thread has started and this
+ 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.
+ \return true if the socket runs in its own thread. */
+ const bool IsDetached() const;
+ /** Order this socket to start its own thread and call OnDetached
+ when ready for operation. */
+ bool Detach();
+ /** Store the slave sockethandler pointer. */
+ void SetSlaveHandler(ISocketHandler *);
+ /** Create new thread for this socket to run detached in. */
+ void DetachSocket();
+ //@}
#endif // ENABLE_DETACH
- /** Write traffic to an IFile. Socket will not delete this object. */
- void SetTrafficMonitor(IFile *p) { m_traffic_monitor = p; }
+ /** Write traffic to an IFile. Socket will not delete this object. */
+ void SetTrafficMonitor(IFile *p) { m_traffic_monitor = p; }
#ifdef ENABLE_TRIGGERS
- /** \name Triggers */
- //@{
- /** Subscribe to trigger id. */
- void Subscribe(int id);
- /** Unsubscribe from trigger id. */
- void Unsubscribe(int id);
- /** Trigger callback, with data passed from source to destination. */
- virtual void OnTrigger(int id, const TriggerData& data);
- /** Trigger cancelled because source has been deleted (as in delete). */
- virtual void OnCancelled(int id);
- //@}
+ /** \name Triggers */
+ //@{
+ /** Subscribe to trigger id. */
+ void Subscribe(int id);
+ /** Unsubscribe from trigger id. */
+ void Unsubscribe(int id);
+ /** Trigger callback, with data passed from source to destination. */
+ virtual void OnTrigger(int id, const TriggerData& data);
+ /** Trigger cancelled because source has been deleted (as in delete). */
+ 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) {}
+ /** 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; }
+ /** 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; }
+ /** 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
+// 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
- bool m_bDel; ///< Delete by handler flag
- bool m_bClose; ///< Close and delete flag
- time_t m_tCreate; ///< Time in seconds when this socket was created
- Socket *m_parent; ///< Pointer to ListenSocket class, valid for incoming sockets
- bool m_b_disable_read; ///< Disable checking for read events
- bool m_connected; ///< Socket is connected (tcp/udp)
- bool m_b_erased_by_handler; ///< Set by handler before delete
- time_t m_tClose; ///< Time in seconds when ordered to close
- std::auto_ptr<SocketAddress> m_client_remote_address; ///< Address of last connect()
- std::auto_ptr<SocketAddress> m_remote_address; ///< Remote end address
- IFile *m_traffic_monitor;
- time_t m_timeout_start; ///< Set by SetTimeout
- time_t m_timeout_limit; ///< Defined by SetTimeout
- bool m_bLost; ///< connection lost
+ ISocketHandler& m_handler; ///< Reference of ISocketHandler in control of this socket
+ SOCKET m_socket; ///< File descriptor
+ bool m_bDel; ///< Delete by handler flag
+ bool m_bClose; ///< Close and delete flag
+ time_t m_tCreate; ///< Time in seconds when this socket was created
+ Socket *m_parent; ///< Pointer to ListenSocket class, valid for incoming sockets
+ bool m_b_disable_read; ///< Disable checking for read events
+ bool m_connected; ///< Socket is connected (tcp/udp)
+ bool m_b_erased_by_handler; ///< Set by handler before delete
+ time_t m_tClose; ///< Time in seconds when ordered to close
+ std::auto_ptr<SocketAddress> m_client_remote_address; ///< Address of last connect()
+ std::auto_ptr<SocketAddress> m_remote_address; ///< Remote end address
+ IFile *m_traffic_monitor;
+ 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
+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
+ 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
+ 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
+ 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
+ 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
- SocketThread *m_pThread; ///< Detach socket thread class pointer
- ISocketHandler *m_slave_handler; ///< Actual sockethandler while detached
+ bool m_detach; ///< Socket ordered to detach flag
+ bool m_detached; ///< Socket has been detached
+ SocketThread *m_pThread; ///< Detach socket thread class pointer
+ ISocketHandler *m_slave_handler; ///< Actual sockethandler while detached
#endif
};
diff --git a/dep/include/sockets/SocketAddress.h b/dep/include/sockets/SocketAddress.h
index d5a56433ba7..c44ff450643 100644
--- a/dep/include/sockets/SocketAddress.h
+++ b/dep/include/sockets/SocketAddress.h
@@ -1,7 +1,7 @@
/**
- ** \file SocketAddress.h
- ** \date 2006-09-21
- ** \author grymse@alhem.net
+ ** \file SocketAddress.h
+ ** \date 2006-09-21
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2007 Anders Hedstrom
@@ -46,43 +46,43 @@ namespace SOCKETS_NAMESPACE {
class SocketAddress
{
public:
- virtual ~SocketAddress() {}
+ virtual ~SocketAddress() {}
- /** Get a pointer to the address struct. */
- virtual operator struct sockaddr *() = 0;
+ /** Get a pointer to the address struct. */
+ virtual operator struct sockaddr *() = 0;
- /** Get length of address struct. */
- virtual operator socklen_t() = 0;
+ /** Get length of address struct. */
+ virtual operator socklen_t() = 0;
- /** Compare two addresses. */
- virtual bool operator==(SocketAddress&) = 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;
+ /** 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;
+ /** 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;
+ /** 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;
+ /** Convert address to text. */
+ virtual std::string Convert(bool include_port) = 0;
- /** Reverse lookup of address. */
- virtual std::string Reverse() = 0;
+ /** Reverse lookup of address. */
+ virtual std::string Reverse() = 0;
- /** Get address family. */
- virtual int GetFamily() = 0;
+ /** Get address family. */
+ virtual int GetFamily() = 0;
- /** Address structure is valid. */
- virtual bool IsValid() = 0;
+ /** Address structure is valid. */
+ virtual bool IsValid() = 0;
- /** Get a copy of this SocketAddress object. */
- virtual std::auto_ptr<SocketAddress> GetCopy() = 0;
+ /** Get a copy of this SocketAddress object. */
+ virtual std::auto_ptr<SocketAddress> GetCopy() = 0;
};
diff --git a/dep/include/sockets/SocketHandler.h b/dep/include/sockets/SocketHandler.h
index c7e20dfde82..a28d2b5311a 100644
--- a/dep/include/sockets/SocketHandler.h
+++ b/dep/include/sockets/SocketHandler.h
@@ -1,6 +1,6 @@
/** \file SocketHandler.h
- ** \date 2004-02-13
- ** \author grymse@alhem.net
+ ** \date 2004-02-13
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -48,212 +48,212 @@ class ResolvServer;
#endif
class Mutex;
-/** Socket container class, event generator.
- \ingroup basic */
+/** Socket container class, event generator.
+ \ingroup basic */
class SocketHandler : public ISocketHandler
{
protected:
- /** Map type for holding file descriptors/socket object pointers. */
- typedef std::map<SOCKET,Socket *> socket_m;
+ /** 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 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 threadsafe constructor.
+ \param mutex Externally declared mutex variable
+ \param log Optional log class pointer */
+ SocketHandler(Mutex& mutex,StdLog *log = NULL);
- ~SocketHandler();
+ ~SocketHandler();
- /** Get mutex reference for threadsafe operations. */
- Mutex& GetMutex() const;
+ /** 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);
+ /** 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);
+ /** 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 *);
+ /** 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);
+ /** 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);
+ /** 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);
+ /** Wait for events, generate callbacks. */
+ int Select(long sec,long usec);
- /** This method will not return until an event has been detected. */
- int Select();
+ /** This method will not return until an event has been detected. */
+ int Select();
- /** Wait for events, generate callbacks. */
- int Select(struct timeval *tsel);
+ /** Wait for events, generate callbacks. */
+ int Select(struct timeval *tsel);
- /** Check that a socket really is handled by this socket handler. */
- bool Valid(Socket *);
+ /** 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();
+ /** 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);
+ /** 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);
+ /** Called by Socket when a socket changes state. */
+ void AddList(SOCKET s,list_t which_one,bool add);
- // Connection pool
+ // Connection pool
#ifdef ENABLE_POOL
- /** Find available open connection (used by connection pool). */
- ISocketHandler::PoolSocket *FindConnection(int type,const std::string& protocol,SocketAddress&);
- /** Enable connection pool (by default disabled). */
- void EnablePool(bool x = true);
- /** Check pool status.
- \return true if connection pool is enabled */
- bool PoolEnabled();
+ /** Find available open connection (used by connection pool). */
+ ISocketHandler::PoolSocket *FindConnection(int type,const std::string& protocol,SocketAddress&);
+ /** Enable connection pool (by default disabled). */
+ void EnablePool(bool x = true);
+ /** Check pool status.
+ \return true if connection pool is enabled */
+ bool PoolEnabled();
#endif // ENABLE_POOL
- // Socks4
+ // Socks4
#ifdef ENABLE_SOCKS4
- /** Set socks4 server ip that all new tcp sockets should use. */
- void SetSocks4Host(ipaddr_t);
- /** Set socks4 server hostname that all new tcp sockets should use. */
- void SetSocks4Host(const std::string& );
- /** Set socks4 server port number that all new tcp sockets should use. */
- void SetSocks4Port(port_t);
- /** Set optional socks4 userid. */
- void SetSocks4Userid(const std::string& );
- /** If connection to socks4 server fails, immediately try direct connection to final host. */
- void SetSocks4TryDirect(bool x = true);
- /** Get socks4 server ip.
- \return socks4 server ip */
- ipaddr_t GetSocks4Host();
- /** Get socks4 port number.
- \return socks4 port number */
- port_t GetSocks4Port();
- /** Get socks4 userid (optional).
- \return socks4 userid */
- const std::string& GetSocks4Userid();
- /** Check status of socks4 try direct flag.
- \return true if direct connection should be tried if connection to socks4 server fails */
- bool Socks4TryDirect();
+ /** Set socks4 server ip that all new tcp sockets should use. */
+ void SetSocks4Host(ipaddr_t);
+ /** Set socks4 server hostname that all new tcp sockets should use. */
+ void SetSocks4Host(const std::string& );
+ /** Set socks4 server port number that all new tcp sockets should use. */
+ void SetSocks4Port(port_t);
+ /** Set optional socks4 userid. */
+ void SetSocks4Userid(const std::string& );
+ /** If connection to socks4 server fails, immediately try direct connection to final host. */
+ void SetSocks4TryDirect(bool x = true);
+ /** Get socks4 server ip.
+ \return socks4 server ip */
+ ipaddr_t GetSocks4Host();
+ /** Get socks4 port number.
+ \return socks4 port number */
+ port_t GetSocks4Port();
+ /** Get socks4 userid (optional).
+ \return socks4 userid */
+ const std::string& GetSocks4Userid();
+ /** Check status of socks4 try direct flag.
+ \return true if direct connection should be tried if connection to socks4 server fails */
+ bool Socks4TryDirect();
#endif // ENABLE_SOCKS4
- // DNS resolve server
+ // DNS resolve server
#ifdef ENABLE_RESOLVER
- /** Enable asynchronous DNS.
- \param port Listen port of asynchronous dns server */
- void EnableResolver(port_t port = 16667);
- /** Check resolver status.
- \return true if resolver is enabled */
- bool ResolverEnabled();
- /** Queue a dns request.
- \param host Hostname to be resolved
- \param port Port number will be echoed in Socket::OnResolved callback */
- int Resolve(Socket *,const std::string& host,port_t port);
+ /** Enable asynchronous DNS.
+ \param port Listen port of asynchronous dns server */
+ void EnableResolver(port_t port = 16667);
+ /** Check resolver status.
+ \return true if resolver is enabled */
+ bool ResolverEnabled();
+ /** Queue a dns request.
+ \param host Hostname to be resolved
+ \param port Port number will be echoed in Socket::OnResolved callback */
+ int Resolve(Socket *,const std::string& host,port_t port);
#ifdef ENABLE_IPV6
- int Resolve6(Socket *,const std::string& host,port_t port);
+ int Resolve6(Socket *,const std::string& host,port_t port);
#endif
- /** Do a reverse dns lookup. */
- int Resolve(Socket *,ipaddr_t a);
+ /** Do a reverse dns lookup. */
+ int Resolve(Socket *,ipaddr_t a);
#ifdef ENABLE_IPV6
- int Resolve(Socket *,in6_addr& a);
+ int Resolve(Socket *,in6_addr& a);
#endif
- /** Get listen port of asynchronous dns server. */
- port_t GetResolverPort();
- /** Resolver thread ready for queries. */
- bool ResolverReady();
- /** Returns true if the socket is waiting for a resolve event. */
- bool Resolving(Socket *);
+ /** Get listen port of asynchronous dns server. */
+ port_t GetResolverPort();
+ /** Resolver thread ready for queries. */
+ bool ResolverReady();
+ /** 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);
- /** Subscribe socket to trigger id. */
- bool Subscribe(int id, Socket *dst);
- /** Unsubscribe socket from trigger id. */
- bool Unsubscribe(int id, Socket *dst);
- /** Execute OnTrigger for subscribed sockets.
- \param id Trigger ID
- \param data Data passed from source to destination
- \param erase Empty trigger id source and destination maps if 'true',
- Leave them in place if 'false' - if a trigger should be called many times */
- void Trigger(int id, Socket::TriggerData& data, bool erase = true);
+ /** Fetch unique trigger id. */
+ int TriggerID(Socket *src);
+ /** Subscribe socket to trigger id. */
+ bool Subscribe(int id, Socket *dst);
+ /** Unsubscribe socket from trigger id. */
+ bool Unsubscribe(int id, Socket *dst);
+ /** Execute OnTrigger for subscribed sockets.
+ \param id Trigger ID
+ \param data Data passed from source to destination
+ \param erase Empty trigger id source and destination maps if 'true',
+ 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();
+ /** 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();
+ /** 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)
+ 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
+ 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. */
- void Remove(Socket *);
- SOCKET m_maxsock; ///< Highest file descriptor + 1 in active sockets list
- fd_set m_rfds; ///< file descriptor set monitored for read events
- fd_set m_wfds; ///< file descriptor set monitored for write events
- fd_set m_efds; ///< file descriptor set monitored for exceptions
- 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
- socket_v m_fds_callonconnect; ///< checklist CallOnConnect
+ void CheckList(socket_v&,const std::string&); ///< Used by CheckSanity
+ /** Remove socket from socket map, used by Socket class. */
+ void Remove(Socket *);
+ SOCKET m_maxsock; ///< Highest file descriptor + 1 in active sockets list
+ fd_set m_rfds; ///< file descriptor set monitored for read events
+ fd_set m_wfds; ///< file descriptor set monitored for write events
+ fd_set m_efds; ///< file descriptor set monitored for exceptions
+ 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
+ socket_v m_fds_callonconnect; ///< checklist CallOnConnect
#ifdef ENABLE_DETACH
- socket_v m_fds_detach; ///< checklist Detach
+ socket_v m_fds_detach; ///< checklist Detach
#endif
- 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
+ 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
- std::string m_socks4_userid; ///< Socks4 userid
- bool m_bTryDirect; ///< Try direct connection if socks4 server fails
+ ipaddr_t m_socks4_host; ///< Socks4 server host ip
+ port_t m_socks4_port; ///< Socks4 server port number
+ std::string m_socks4_userid; ///< Socks4 userid
+ bool m_bTryDirect; ///< Try direct connection if socks4 server fails
#endif
#ifdef ENABLE_RESOLVER
- int m_resolv_id; ///< Resolver id counter
- ResolvServer *m_resolver; ///< Resolver thread pointer
- port_t m_resolver_port; ///< Resolver listen port
- std::map<Socket *, bool> m_resolve_q; ///< resolve queue
+ int m_resolv_id; ///< Resolver id counter
+ ResolvServer *m_resolver; ///< Resolver thread pointer
+ port_t m_resolver_port; ///< Resolver listen port
+ std::map<Socket *, bool> m_resolve_q; ///< resolve queue
#endif
#ifdef ENABLE_POOL
- bool m_b_enable_pool; ///< Connection pool enabled if true
+ bool m_b_enable_pool; ///< Connection pool enabled if true
#endif
#ifdef ENABLE_TRIGGERS
- int m_next_trigger_id; ///< Unique trigger id counter
- std::map<int, Socket *> m_trigger_src; ///< mapping trigger id to source socket
- std::map<int, std::map<Socket *, bool> > m_trigger_dst; ///< mapping trigger id to destination sockets
+ int m_next_trigger_id; ///< Unique trigger id counter
+ std::map<int, Socket *> m_trigger_src; ///< mapping trigger id to source socket
+ std::map<int, std::map<Socket *, bool> > m_trigger_dst; ///< mapping trigger id to destination sockets
#endif
#ifdef ENABLE_DETACH
- bool m_slave; ///< Indicates that this is a ISocketHandler run in SocketThread
+ bool m_slave; ///< Indicates that this is a ISocketHandler run in SocketThread
#endif
};
diff --git a/dep/include/sockets/StdLog.h b/dep/include/sockets/StdLog.h
index c07037bbd4f..2d2a6705ce0 100644
--- a/dep/include/sockets/StdLog.h
+++ b/dep/include/sockets/StdLog.h
@@ -1,6 +1,6 @@
/** \file StdLog.h
- ** \date 2004-06-01
- ** \author grymse@alhem.net
+ ** \date 2004-06-01
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -40,10 +40,10 @@ namespace SOCKETS_NAMESPACE {
/** error level enum. */
typedef enum
{
- LOG_LEVEL_WARNING = 0,
- LOG_LEVEL_ERROR,
- LOG_LEVEL_FATAL,
- LOG_LEVEL_INFO
+ LOG_LEVEL_WARNING = 0,
+ LOG_LEVEL_ERROR,
+ LOG_LEVEL_FATAL,
+ LOG_LEVEL_INFO
} loglevel_t;
@@ -51,18 +51,18 @@ class ISocketHandler;
class Socket;
/** \defgroup logging Log help classes */
-/** Log class interface.
- \ingroup logging */
+/** Log class interface.
+ \ingroup logging */
class StdLog
{
public:
- virtual ~StdLog() {}
+ virtual ~StdLog() {}
- virtual void error(ISocketHandler *,Socket *,
- const std::string& user_text,
- int err,
- const std::string& sys_err,
- loglevel_t = LOG_LEVEL_WARNING) = 0;
+ virtual void error(ISocketHandler *,Socket *,
+ const std::string& user_text,
+ int err,
+ const std::string& sys_err,
+ loglevel_t = LOG_LEVEL_WARNING) = 0;
};
diff --git a/dep/include/sockets/StdoutLog.h b/dep/include/sockets/StdoutLog.h
index 5f96b340dc2..3222892e4bf 100644
--- a/dep/include/sockets/StdoutLog.h
+++ b/dep/include/sockets/StdoutLog.h
@@ -1,6 +1,6 @@
/** \file StdoutLog.h
- ** \date 2004-06-01
- ** \author grymse@alhem.net
+ ** \date 2004-06-01
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -38,12 +38,12 @@ namespace SOCKETS_NAMESPACE {
#endif
-/** StdLog implementation, logs to stdout.
- \ingroup logging */
+/** StdLog implementation, logs to stdout.
+ \ingroup logging */
class StdoutLog : public StdLog
{
public:
- void error(ISocketHandler *,Socket *,const std::string& call,int err,const std::string& sys_err,loglevel_t);
+ void error(ISocketHandler *,Socket *,const std::string& call,int err,const std::string& sys_err,loglevel_t);
};
diff --git a/dep/include/sockets/StreamSocket.h b/dep/include/sockets/StreamSocket.h
index 3c248110b88..a22e2332bcb 100644
--- a/dep/include/sockets/StreamSocket.h
+++ b/dep/include/sockets/StreamSocket.h
@@ -10,111 +10,111 @@ namespace SOCKETS_NAMESPACE {
/** SOCK_STREAM Socket base class.
- \ingroup basic */
+ \ingroup basic */
class StreamSocket : public Socket
{
public:
- StreamSocket(ISocketHandler& );
- ~StreamSocket();
+ StreamSocket(ISocketHandler& );
+ ~StreamSocket();
- /** Socket should Check Connect on next write event from select(). */
- void SetConnecting(bool = true);
+ /** 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();
+ /** 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();
+ /** 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);
+ /** 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();
+ /** 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);
+ /** 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();
+ /** 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);
+ /** 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();
+ /** Get number of maximum connection retries (tcp only). */
+ int GetConnectionRetry();
- /** Increase number of actual connection retries (tcp only). */
- void IncreaseConnectionRetries();
+ /** Increase number of actual connection retries (tcp only). */
+ void IncreaseConnectionRetries();
- /** Get number of actual connection retries (tcp only). */
- int GetConnectionRetries();
+ /** Get number of actual connection retries (tcp only). */
+ int GetConnectionRetries();
- /** Reset actual connection retries (tcp only). */
- void ResetConnectionRetries();
+ /** Reset actual connection retries (tcp only). */
+ void ResetConnectionRetries();
- // LIST_CALLONCONNECT
+ // LIST_CALLONCONNECT
- /** Instruct socket to call OnConnect callback next sockethandler cycle. */
- void SetCallOnConnect(bool x = true);
+ /** 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();
+ /** Check call on connect flag.
+ \return true if OnConnect() should be called a.s.a.p */
+ bool CallOnConnect();
- // LIST_RETRY
+ // LIST_RETRY
- /** Set flag to initiate a connection attempt after a connection timeout. */
- void SetRetryClientConnect(bool x = true);
+ /** 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();
+ /** 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);
+ /** 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();
+ /** Check line protocol mode.
+ \return true if socket is in line protocol mode */
+ bool LineProtocol();
- /** Set shutdown status. */
- void SetShutdown(int);
+ /** Set shutdown status. */
+ void SetShutdown(int);
- /** Get shutdown status. */
- int GetShutdown();
+ /** Get shutdown status. */
+ int GetShutdown();
- /** Returns IPPROTO_TCP or IPPROTO_SCTP */
- virtual int Protocol() = 0;
+ /** Returns IPPROTO_TCP or IPPROTO_SCTP */
+ virtual int Protocol() = 0;
protected:
- StreamSocket(const StreamSocket& ) {} // copy constructor
+ 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)
- int m_connection_retry; ///< Maximum connection retries (tcp)
- int m_retries; ///< Actual number of connection retries (tcp)
- bool m_call_on_connect; ///< OnConnect will be called next ISocketHandler cycle if true
- bool m_b_retry_connect; ///< Try another connection attempt next ISocketHandler cycle
- bool m_line_protocol; ///< Line protocol mode flag
- int m_shutdown; ///< Shutdown status
+ 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)
+ int m_connection_retry; ///< Maximum connection retries (tcp)
+ int m_retries; ///< Actual number of connection retries (tcp)
+ bool m_call_on_connect; ///< OnConnect will be called next ISocketHandler cycle if true
+ bool m_b_retry_connect; ///< Try another connection attempt next ISocketHandler cycle
+ bool m_line_protocol; ///< Line protocol mode flag
+ int m_shutdown; ///< Shutdown status
};
diff --git a/dep/include/sockets/TcpSocket.h b/dep/include/sockets/TcpSocket.h
index 515f5aa6cc7..4a157db4df6 100644
--- a/dep/include/sockets/TcpSocket.h
+++ b/dep/include/sockets/TcpSocket.h
@@ -1,6 +1,6 @@
/** \file TcpSocket.h
- ** \date 2004-02-13
- ** \author grymse@alhem.net
+ ** \date 2004-02-13
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -49,302 +49,302 @@ namespace SOCKETS_NAMESPACE {
class SocketAddress;
-/** Socket implementation for TCP.
- \ingroup basic */
+/** Socket implementation for TCP.
+ \ingroup basic */
class TcpSocket : public StreamSocket
{
- /** \defgroup internal Internal utility */
+ /** \defgroup internal Internal utility */
protected:
- /** Buffer class containing one read/write circular buffer.
- \ingroup internal */
- class CircularBuffer
- {
- 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 */
- bool Read(char *dest,size_t l);
+ /** Buffer class containing one read/write circular buffer.
+ \ingroup internal */
+ class CircularBuffer
+ {
+ 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 */
+ bool Read(char *dest,size_t l);
/** copy l bytes from buffer to dest, dont touch buffer pointers */
bool SoftRead(char *dest, size_t l);
- /** skip l bytes from buffer */
- 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 */
- const char *GetStart();
- /** return number of bytes from circular buffer beginning to buffer physical end */
- 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; }
- char *buf;
- size_t m_max;
- size_t m_q;
- size_t m_b;
- size_t m_t;
- unsigned long m_count;
- };
- /** Output buffer struct.
- \ingroup internal */
- struct OUTPUT {
- OUTPUT() : _b(0), _t(0), _q(0) {}
- OUTPUT(const char *buf, size_t len) : _b(0), _t(len), _q(len) {
- memcpy(_buf, buf, len);
- }
- size_t Space() {
- return TCP_OUTPUT_CAPACITY - _t;
- }
- void Add(const char *buf, size_t len) {
- memcpy(_buf + _t, buf, len);
- _t += len;
- _q += len;
- }
- size_t Remove(size_t len) {
- _b += len;
- _q -= len;
- return _q;
- }
- const char *Buf() {
- return _buf + _b;
- }
- size_t Len() {
- return _q;
- }
- size_t _b;
- size_t _t;
- size_t _q;
- char _buf[TCP_OUTPUT_CAPACITY];
- };
- typedef std::list<OUTPUT *> output_l;
+ /** skip l bytes from buffer */
+ 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 */
+ const char *GetStart();
+ /** return number of bytes from circular buffer beginning to buffer physical end */
+ 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; }
+ char *buf;
+ size_t m_max;
+ size_t m_q;
+ size_t m_b;
+ size_t m_t;
+ unsigned long m_count;
+ };
+ /** Output buffer struct.
+ \ingroup internal */
+ struct OUTPUT {
+ OUTPUT() : _b(0), _t(0), _q(0) {}
+ OUTPUT(const char *buf, size_t len) : _b(0), _t(len), _q(len) {
+ memcpy(_buf, buf, len);
+ }
+ size_t Space() {
+ return TCP_OUTPUT_CAPACITY - _t;
+ }
+ void Add(const char *buf, size_t len) {
+ memcpy(_buf + _t, buf, len);
+ _t += len;
+ _q += len;
+ }
+ size_t Remove(size_t len) {
+ _b += len;
+ _q -= len;
+ return _q;
+ }
+ const char *Buf() {
+ return _buf + _b;
+ }
+ size_t Len() {
+ return _q;
+ }
+ size_t _b;
+ size_t _t;
+ size_t _q;
+ char _buf[TCP_OUTPUT_CAPACITY];
+ };
+ typedef std::list<OUTPUT *> output_l;
public:
- /** Constructor with standard values on input/output buffers. */
- TcpSocket(ISocketHandler& );
- /** Constructor with custom values for i/o buffer.
- \param h ISocketHandler reference
- \param isize Input buffer size
- \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.
- If not, the connection attempt will not be monitored by the
- socket handler...
- \param ip IP address
- \param port Port number
- \param skip_socks Do not use socks4 even if configured */
- bool Open(ipaddr_t ip,port_t port,bool skip_socks = false);
+ /** Constructor with standard values on input/output buffers. */
+ TcpSocket(ISocketHandler& );
+ /** Constructor with custom values for i/o buffer.
+ \param h ISocketHandler reference
+ \param isize Input buffer size
+ \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.
+ If not, the connection attempt will not be monitored by the
+ socket handler...
+ \param ip IP address
+ \param port Port number
+ \param skip_socks Do not use socks4 even if configured */
+ bool Open(ipaddr_t ip,port_t port,bool skip_socks = false);
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- /** Open connection.
- \param ip Ipv6 address
- \param port Port number
- \param skip_socks Do not use socks4 even if configured */
- bool Open(in6_addr ip,port_t port,bool skip_socks = false);
+ /** Open connection.
+ \param ip Ipv6 address
+ \param port Port number
+ \param skip_socks Do not use socks4 even if configured */
+ bool Open(in6_addr ip,port_t port,bool skip_socks = false);
#endif
#endif
- bool Open(SocketAddress&,bool skip_socks = false);
- bool Open(SocketAddress&,SocketAddress& bind_address,bool skip_socks = false);
- /** Open connection.
- \param host Hostname
- \param port Port number */
- bool Open(const std::string &host,port_t port);
-
- /** Connect timeout callback. */
- void OnConnectTimeout();
+ bool Open(SocketAddress&,bool skip_socks = false);
+ bool Open(SocketAddress&,SocketAddress& bind_address,bool skip_socks = false);
+ /** Open connection.
+ \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();
+ /** 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 */
- void Send(const std::string &s,int f = 0);
- /** Send string using printf formatting. */
- void Sendf(const char *format, ...);
- /** Send buffer of bytes.
- \param buf Buffer pointer
- \param len Length of data
- \param f Dummy flags -- not used */
- void SendBuf(const char *buf,size_t len,int f = 0);
- /** This callback is executed after a successful read from the socket.
- \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
- will not generate a call to this method. */
- virtual void OnWriteComplete();
- /** Number of bytes in input buffer. */
- 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);
- /** Get counter of number of bytes received. */
- 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. */
- void OnSocks4ConnectFailed();
- /** Socks4 specific callback.
- \return 'need_more' */
- bool OnSocks4Read();
+ /** Close file descriptor - internal use only.
+ \sa SetCloseAndDelete */
+ int Close();
+
+ /** Send a string.
+ \param s String to send
+ \param f Dummy flags -- not used */
+ void Send(const std::string &s,int f = 0);
+ /** Send string using printf formatting. */
+ void Sendf(const char *format, ...);
+ /** Send buffer of bytes.
+ \param buf Buffer pointer
+ \param len Length of data
+ \param f Dummy flags -- not used */
+ void SendBuf(const char *buf,size_t len,int f = 0);
+ /** This callback is executed after a successful read from the socket.
+ \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
+ will not generate a call to this method. */
+ virtual void OnWriteComplete();
+ /** Number of bytes in input buffer. */
+ 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);
+ /** Get counter of number of bytes received. */
+ 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. */
+ void OnSocks4ConnectFailed();
+ /** 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);
+ /** Callback executed when resolver thread has finished a resolve request. */
+ void OnResolved(int id,ipaddr_t a,port_t port);
#ifdef ENABLE_IPV6
- void OnResolved(int id,in6_addr& a,port_t port);
+ void OnResolved(int id,in6_addr& a,port_t port);
#endif
#endif
#ifdef HAVE_OPENSSL
- /** Callback for 'New' ssl support - replaces SSLSocket. Internal use. */
- void OnSSLConnect();
- /** Callback for 'New' ssl support - replaces SSLSocket. Internal use. */
- void OnSSLAccept();
- /** This method must be implemented to initialize
- the ssl context for an outgoing connection. */
- virtual void InitSSLClient();
- /** This method must be implemented to initialize
- the ssl context for an incoming connection. */
- virtual void InitSSLServer();
+ /** Callback for 'New' ssl support - replaces SSLSocket. Internal use. */
+ void OnSSLConnect();
+ /** Callback for 'New' ssl support - replaces SSLSocket. Internal use. */
+ void OnSSLAccept();
+ /** This method must be implemented to initialize
+ the ssl context for an outgoing connection. */
+ virtual void InitSSLClient();
+ /** This method must be implemented to initialize
+ 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);
- /** Check reconnect on lost connection flag status. */
- bool Reconnect();
- /** Flag to determine if a reconnect is in progress. */
- void SetIsReconnect(bool x = true);
- /** Socket is reconnecting. */
- bool IsReconnect();
+ /** Flag that says a broken connection will try to reconnect. */
+ void SetReconnect(bool = true);
+ /** Check reconnect on lost connection flag status. */
+ bool Reconnect();
+ /** Flag to determine if a reconnect is in progress. */
+ void SetIsReconnect(bool x = true);
+ /** Socket is reconnecting. */
+ bool IsReconnect();
#endif
- void DisableInputBuffer(bool = true);
+ void DisableInputBuffer(bool = true);
- void OnOptions(int,int,int,SOCKET);
+ void OnOptions(int,int,int,SOCKET);
- void SetLineProtocol(bool = true);
+ void SetLineProtocol(bool = true);
- // TCP options
- bool SetTcpNodelay(bool = true);
+ // TCP options
+ bool SetTcpNodelay(bool = true);
- virtual int Protocol();
+ 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();
+ /** 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();
- void OnRead( char *buf, size_t n );
- void OnWrite();
+ TcpSocket(const TcpSocket& );
+ void OnRead();
+ void OnRead( char *buf, size_t n );
+ void OnWrite();
#ifdef HAVE_OPENSSL
- /** SSL; Initialize ssl context for a client socket.
- \param meth_in SSL method */
- void InitializeContext(const std::string& context, SSL_METHOD *meth_in = NULL);
- /** SSL; Initialize ssl context for a server socket.
- \param keyfile Combined private key/certificate file
- \param password Password for private key
- \param meth_in SSL method */
- void InitializeContext(const std::string& context, const std::string& keyfile, const std::string& password, SSL_METHOD *meth_in = NULL);
- /** SSL; Initialize ssl context for a server socket.
- \param certfile Separate certificate file
- \param keyfile Combined private key/certificate file
- \param password Password for private key
- \param meth_in SSL method */
- void InitializeContext(const std::string& context, const std::string& certfile, const std::string& keyfile, const std::string& password, SSL_METHOD *meth_in = NULL);
- /** SSL; Password callback method. */
-static int SSL_password_cb(char *buf,int num,int rwflag,void *userdata);
- /** SSL; Get pointer to ssl context structure. */
- virtual SSL_CTX *GetSslContext();
- /** SSL; Get pointer to ssl structure. */
- virtual SSL *GetSsl();
- /** ssl; still negotiating connection. */
- bool SSLNegotiate();
- /** SSL; Get ssl password. */
- const std::string& GetPassword();
+ /** SSL; Initialize ssl context for a client socket.
+ \param meth_in SSL method */
+ void InitializeContext(const std::string& context, SSL_METHOD *meth_in = NULL);
+ /** SSL; Initialize ssl context for a server socket.
+ \param keyfile Combined private key/certificate file
+ \param password Password for private key
+ \param meth_in SSL method */
+ void InitializeContext(const std::string& context, const std::string& keyfile, const std::string& password, SSL_METHOD *meth_in = NULL);
+ /** SSL; Initialize ssl context for a server socket.
+ \param certfile Separate certificate file
+ \param keyfile Combined private key/certificate file
+ \param password Password for private key
+ \param meth_in SSL method */
+ void InitializeContext(const std::string& context, const std::string& certfile, const std::string& keyfile, const std::string& password, SSL_METHOD *meth_in = NULL);
+ /** SSL; Password callback method. */
+static int SSL_password_cb(char *buf,int num,int rwflag,void *userdata);
+ /** SSL; Get pointer to ssl context structure. */
+ virtual SSL_CTX *GetSslContext();
+ /** SSL; Get pointer to ssl structure. */
+ virtual SSL *GetSsl();
+ /** ssl; still negotiating connection. */
+ bool SSLNegotiate();
+ /** SSL; Get ssl password. */
+ const std::string& GetPassword();
#endif
- CircularBuffer ibuf; ///< Circular input buffer
+ 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;
- uint64_t m_bytes_received;
- bool m_skip_c; ///< Skip second char of CRLF or LFCR sequence in OnRead
- char m_c; ///< First char in CRLF or LFCR sequence
- std::string m_line; ///< Current line in line protocol mode
+ 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;
+ uint64_t m_bytes_received;
+ bool m_skip_c; ///< Skip second char of CRLF or LFCR sequence in OnRead
+ char m_c; ///< First char in CRLF or LFCR sequence
+ std::string m_line; ///< Current line in line protocol mode
#ifdef SOCKETS_DYNAMIC_TEMP
- char *m_buf; ///< temporary read buffer
+ char *m_buf; ///< temporary read buffer
#endif
- output_l m_obuf; ///< output buffer
- OUTPUT *m_obuf_top; ///< output buffer on top
- size_t m_transfer_limit;
- size_t m_output_length;
+ output_l m_obuf; ///< output buffer
+ 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
- SSL *m_ssl; ///< ssl 'socket'
- BIO *m_sbio; ///< ssl bio
- std::string m_password; ///< ssl password
+static SSLInitializer m_ssl_init;
+ SSL_CTX *m_ssl_ctx; ///< ssl context
+ SSL *m_ssl; ///< ssl 'socket'
+ 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
- char m_socks4_cd; ///< socks4 support, temporary variable
- unsigned short m_socks4_dstport; ///< socks4 support
- unsigned long m_socks4_dstip; ///< socks4 support
+ int m_socks4_state; ///< socks4 support
+ char m_socks4_vn; ///< socks4 support, temporary variable
+ char m_socks4_cd; ///< socks4 support, temporary variable
+ 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
+ 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
+ bool m_b_reconnect; ///< Reconnect on lost connection flag
+ bool m_b_is_reconnect; ///< Trying to reconnect
#endif
};
diff --git a/dep/include/sockets/Thread.h b/dep/include/sockets/Thread.h
index d784a1594f6..4e99664d579 100644
--- a/dep/include/sockets/Thread.h
+++ b/dep/include/sockets/Thread.h
@@ -1,6 +1,6 @@
/** \file Thread.h
- ** \date 2004-10-30
- ** \author grymse@alhem.net
+ ** \date 2004-10-30
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -52,43 +52,43 @@ typedef void * threadparam_t;
#endif
/** \defgroup threading Threading */
-/** Thread base class.
-The Thread class is used by the resolver (ResolvServer) and running a detached socket (SocketThread).
-When you know some processing will take a long time and will freeze up a socket, there is always the
+/** Thread base class.
+The Thread class is used by the resolver (ResolvServer) and running a detached socket (SocketThread).
+When you know some processing will take a long time and will freeze up a socket, there is always the
possibility to call Detach() on that socket before starting the processing.
When the OnDetached() callback is later called the processing can continue, now in its own thread.
- \ingroup threading */
+ \ingroup threading */
class Thread
{
public:
- Thread(bool release = true);
- virtual ~Thread();
+ Thread(bool release = true);
+ virtual ~Thread();
- static threadfunc_t STDPREFIX StartThread(threadparam_t);
+ static threadfunc_t STDPREFIX StartThread(threadparam_t);
- virtual void Run() = 0;
+ virtual void Run() = 0;
- bool IsRunning();
- void SetRunning(bool x);
- bool IsReleased();
- void SetRelease(bool x);
- bool DeleteOnExit();
- void SetDeleteOnExit(bool x = true);
- bool IsDestructor();
+ bool IsRunning();
+ void SetRunning(bool x);
+ bool IsReleased();
+ void SetRelease(bool x);
+ bool DeleteOnExit();
+ void SetDeleteOnExit(bool x = true);
+ bool IsDestructor();
private:
- Thread(const Thread& ) {}
- Thread& operator=(const Thread& ) { return *this; }
+ Thread(const Thread& ) {}
+ Thread& operator=(const Thread& ) { return *this; }
#ifdef _WIN32
- HANDLE m_thread;
- unsigned m_dwThreadId;
+ HANDLE m_thread;
+ unsigned m_dwThreadId;
#else
- pthread_t m_thread;
+ pthread_t m_thread;
#endif
- bool m_running;
- bool m_release;
- bool m_b_delete_on_exit;
- bool m_b_destructor;
+ bool m_running;
+ bool m_release;
+ bool m_b_delete_on_exit;
+ bool m_b_destructor;
};
diff --git a/dep/include/sockets/UdpSocket.h b/dep/include/sockets/UdpSocket.h
index d32aabf67aa..86f72e9ca16 100644
--- a/dep/include/sockets/UdpSocket.h
+++ b/dep/include/sockets/UdpSocket.h
@@ -1,6 +1,6 @@
/** \file UdpSocket.h
- ** \date 2004-02-13
- ** \author grymse@alhem.net
+ ** \date 2004-02-13
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -38,172 +38,172 @@ namespace SOCKETS_NAMESPACE {
#endif
/** Socket implementation for UDP.
- \ingroup basic */
+ \ingroup basic */
class UdpSocket : public Socket
{
public:
- /** Constructor.
- \param h ISocketHandler reference
- \param ibufsz Maximum size of receive message (extra bytes will be truncated)
- \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
- \param sa Pointer to sockaddr struct of sender
- \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
- \return 0 if bind succeeded */
- int Bind(port_t& port,int range = 1);
- /** To receive data on a specific interface:port, use this.
- \param intf Interface ip/hostname
- \param port Port number
- \param range Port range
- \return 0 if bind succeeded */
- int Bind(const std::string& intf,port_t& port,int range = 1);
- /** To receive data on a specific interface:port, use this.
- \param a Ip address
- \param port Port number
- \param range Port range
- \return 0 if bind succeeded */
- int Bind(ipaddr_t a,port_t& port,int range = 1);
+ /** Constructor.
+ \param h ISocketHandler reference
+ \param ibufsz Maximum size of receive message (extra bytes will be truncated)
+ \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
+ \param sa Pointer to sockaddr struct of sender
+ \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
+ \return 0 if bind succeeded */
+ int Bind(port_t& port,int range = 1);
+ /** To receive data on a specific interface:port, use this.
+ \param intf Interface ip/hostname
+ \param port Port number
+ \param range Port range
+ \return 0 if bind succeeded */
+ int Bind(const std::string& intf,port_t& port,int range = 1);
+ /** To receive data on a specific interface:port, use this.
+ \param a Ip address
+ \param port Port number
+ \param range Port range
+ \return 0 if bind succeeded */
+ int Bind(ipaddr_t a,port_t& port,int range = 1);
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- /** To receive data on a specific interface:port, use this.
- \param a Ipv6 address
- \param port Port number
- \param range Port range
- \return 0 if bind succeeded */
- int Bind(in6_addr a,port_t& port,int range = 1);
+ /** To receive data on a specific interface:port, use this.
+ \param a Ipv6 address
+ \param port Port number
+ \param range Port range
+ \return 0 if bind succeeded */
+ int Bind(in6_addr a,port_t& port,int range = 1);
#endif
#endif
- /** To receive data on a specific interface:port, use this.
- \param ad Socket address
- \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
- \return true if successful */
- bool Open(ipaddr_t l,port_t port);
- /** Define remote host.
- \param host Hostname
- \param port Port number
- \return true if successful */
- bool Open(const std::string& host,port_t port);
+ /** To receive data on a specific interface:port, use this.
+ \param ad Socket address
+ \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
+ \return true if successful */
+ bool Open(ipaddr_t l,port_t port);
+ /** Define remote host.
+ \param host Hostname
+ \param port Port number
+ \return true if successful */
+ bool Open(const std::string& host,port_t port);
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- /** Define remote host.
- \param a Address of remote host, ipv6
- \param port Port of remote host
- \return true if successful */
- bool Open(struct in6_addr& a,port_t port);
+ /** Define remote host.
+ \param a Address of remote host, ipv6
+ \param port Port of remote host
+ \return true if successful */
+ bool Open(struct in6_addr& a,port_t port);
#endif
#endif
- /** Define remote host.
- \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 */
- void SendToBuf(ipaddr_t,port_t,const char *data,int len,int flags = 0);
+ /** Define remote host.
+ \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 */
+ void SendToBuf(ipaddr_t,port_t,const char *data,int len,int flags = 0);
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- /** Send to specified ipv6 address */
- void SendToBuf(in6_addr,port_t,const char *data,int len,int flags = 0);
+ /** Send to specified ipv6 address */
+ void SendToBuf(in6_addr,port_t,const char *data,int len,int flags = 0);
#endif
#endif
- /** Send to specified socket address */
- void SendToBuf(SocketAddress& ad,const char *data,int len,int flags = 0);
+ /** 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 */
- void SendTo(ipaddr_t,port_t,const std::string&,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 */
+ void SendTo(ipaddr_t,port_t,const std::string&,int flags = 0);
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- /** Send string to specified ipv6 address */
- void SendTo(in6_addr,port_t,const std::string&,int flags = 0);
+ /** Send string to specified ipv6 address */
+ void SendTo(in6_addr,port_t,const std::string&,int flags = 0);
#endif
#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();
- void SetMulticastLoop(bool = true);
- bool IsMulticastLoop();
- void AddMulticastMembership(const std::string& group,const std::string& intf = "0.0.0.0",int if_index = 0);
- void DropMulticastMembership(const std::string& group,const std::string& intf = "0.0.0.0",int if_index = 0);
+ /** 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();
+ void SetMulticastLoop(bool = true);
+ bool IsMulticastLoop();
+ void AddMulticastMembership(const std::string& group,const std::string& intf = "0.0.0.0",int if_index = 0);
+ void DropMulticastMembership(const std::string& group,const std::string& intf = "0.0.0.0",int if_index = 0);
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- /** multicast, ipv6 only */
- void SetMulticastHops(int = -1);
- /** multicast, ipv6 only */
- int GetMulticastHops();
+ /** multicast, ipv6 only */
+ void SetMulticastHops(int = -1);
+ /** multicast, ipv6 only */
+ int GetMulticastHops();
#endif
#endif
- /** Returns true if Bind succeeded. */
- bool IsBound();
- /** Return Bind port number */
- port_t GetPort();
+ /** Returns true if Bind succeeded. */
+ bool IsBound();
+ /** Return Bind port number */
+ port_t GetPort();
- void OnOptions(int,int,int,SOCKET) {}
+ void OnOptions(int,int,int,SOCKET) {}
- int GetLastSizeWritten();
+ int GetLastSizeWritten();
- /** Also read timestamp information from incoming message */
- void SetTimestamp(bool = true);
+ /** Also read timestamp information from incoming message */
+ void SetTimestamp(bool = true);
protected:
- UdpSocket(const UdpSocket& s) : Socket(s) {}
- void OnRead();
+ UdpSocket(const UdpSocket& s) : Socket(s) {}
+ void OnRead();
#if defined(LINUX) || defined(MACOSX)
- /** 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);
+ /** 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 */
- void CreateConnection();
- char *m_ibuf; ///< Input buffer
- int m_ibufsz; ///< Size of input buffer
- bool m_bind_ok; ///< Bind completed successfully
- port_t m_port; ///< Bind port number
- int m_last_size_written;
- int m_retries;
- bool m_b_read_ts;
+ UdpSocket& operator=(const UdpSocket& ) { return *this; }
+ /** create before using sendto methods */
+ void CreateConnection();
+ char *m_ibuf; ///< Input buffer
+ int m_ibufsz; ///< Size of input buffer
+ bool m_bind_ok; ///< Bind completed successfully
+ port_t m_port; ///< Bind port number
+ int m_last_size_written;
+ int m_retries;
+ bool m_b_read_ts;
};
diff --git a/dep/include/sockets/Utility.h b/dep/include/sockets/Utility.h
index 0fbccd3dfa3..f940221e5ca 100644
--- a/dep/include/sockets/Utility.h
+++ b/dep/include/sockets/Utility.h
@@ -1,6 +1,6 @@
/** \file Utility.h
- ** \date 2004-02-13
- ** \author grymse@alhem.net
+ ** \date 2004-02-13
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -46,135 +46,135 @@ namespace SOCKETS_NAMESPACE {
class SocketAddress;
-/** Conversion utilities.
- \ingroup util */
+/** Conversion utilities.
+ \ingroup util */
class Utility
{
- /**
- The Mersenne Twister
- http://www.math.keio.ac.jp/~matumoto/emt.html
- */
- class Rng {
- public:
- Rng(unsigned long seed);
-
- unsigned long Get();
-
- private:
- int m_value;
- unsigned long m_tmp[TWIST_LEN];
- };
- class ncmap_compare {
- public:
- bool operator()(const std::string& x, const std::string& y) const {
- return strcasecmp(x.c_str(), y.c_str()) < 0;
- }
- };
+ /**
+ The Mersenne Twister
+ http://www.math.keio.ac.jp/~matumoto/emt.html
+ */
+ class Rng {
+ public:
+ Rng(unsigned long seed);
+
+ unsigned long Get();
+
+ private:
+ int m_value;
+ unsigned long m_tmp[TWIST_LEN];
+ };
+ class ncmap_compare {
+ public:
+ bool operator()(const std::string& x, const std::string& y) const {
+ return strcasecmp(x.c_str(), y.c_str()) < 0;
+ }
+ };
public:
- template<typename Y> class ncmap : public std::map<std::string, Y, ncmap_compare> {
- public:
- ncmap() {}
- };
+ template<typename Y> class ncmap : public std::map<std::string, Y, ncmap_compare> {
+ public:
+ ncmap() {}
+ };
public:
- static std::string base64(const std::string& str_in);
- static std::string base64d(const std::string& str_in);
- static std::string l2string(long l);
- static std::string bigint2string(uint64_t l);
- static uint64_t atoi64(const std::string& str);
- 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);
+ static std::string base64(const std::string& str_in);
+ static std::string base64d(const std::string& str_in);
+ static std::string l2string(long l);
+ static std::string bigint2string(uint64_t l);
+ static uint64_t atoi64(const std::string& str);
+ 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. */
- static bool u2ip(const std::string&, struct in6_addr&);
- static bool u2ip(const std::string&, struct sockaddr_in6& sa, int ai_flags = 0);
+ /** Hostname to ip resolution ipv6, not asynchronous. */
+ static bool u2ip(const std::string&, struct in6_addr&);
+ 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);
+ /** 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);
+ 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& );
+ /** Convert binary ip address to string: ipv4. */
+ static void l2ip(const ipaddr_t,std::string& );
+ static void l2ip(const in_addr&,std::string& );
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- /** Convert binary ip address to string: ipv6. */
- static void l2ip(const struct in6_addr&,std::string& ,bool mixed = false);
+ /** 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);
+ /** ipv6 address compare. */
+ static int in6_addr_compare(in6_addr,in6_addr);
#endif
#endif
- /** ResolveLocal (hostname) - call once before calling any GetLocal method. */
- static void ResolveLocal();
- /** Returns local hostname, ResolveLocal must be called once before using.
- \sa ResolveLocal */
- static const std::string& GetLocalHostname();
- /** Returns local ip, ResolveLocal must be called once before using.
- \sa ResolveLocal */
- static ipaddr_t GetLocalIP();
- /** Returns local ip number as string.
- \sa ResolveLocal */
- static const std::string& GetLocalAddress();
+ /** ResolveLocal (hostname) - call once before calling any GetLocal method. */
+ static void ResolveLocal();
+ /** Returns local hostname, ResolveLocal must be called once before using.
+ \sa ResolveLocal */
+ static const std::string& GetLocalHostname();
+ /** Returns local ip, ResolveLocal must be called once before using.
+ \sa ResolveLocal */
+ static ipaddr_t GetLocalIP();
+ /** Returns local ip number as string.
+ \sa ResolveLocal */
+ static const std::string& GetLocalAddress();
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- /** Returns local ipv6 ip.
- \sa ResolveLocal */
- static const struct in6_addr& GetLocalIP6();
- /** Returns local ipv6 address.
- \sa ResolveLocal */
- static const std::string& GetLocalAddress6();
+ /** Returns local ipv6 ip.
+ \sa ResolveLocal */
+ static const struct in6_addr& GetLocalIP6();
+ /** Returns local ipv6 address.
+ \sa ResolveLocal */
+ static const std::string& GetLocalAddress6();
#endif
#endif
- /** Set environment variable.
- \param var Name of variable to set
- \param value Value */
- static void SetEnv(const std::string& var,const std::string& value);
- /** Convert sockaddr struct to human readable string.
- \param sa Ptr to sockaddr struct */
- static std::string Sa2String(struct sockaddr *sa);
+ /** Set environment variable.
+ \param var Name of variable to set
+ \param value Value */
+ static void SetEnv(const std::string& var,const std::string& value);
+ /** 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 *);
+ /** Get current time in sec/microseconds. */
+ static void GetTime(struct timeval *);
- static std::auto_ptr<SocketAddress> CreateAddress(struct sockaddr *,socklen_t);
+ static std::auto_ptr<SocketAddress> CreateAddress(struct sockaddr *,socklen_t);
- static unsigned long ThreadID();
+ static unsigned long ThreadID();
- static std::string ToLower(const std::string& str);
- static std::string ToUpper(const std::string& str);
+ static std::string ToLower(const std::string& str);
+ static std::string ToUpper(const std::string& str);
- static std::string ToString(double d);
+ static std::string ToString(double d);
- /** Returns a random 32-bit integer */
- static unsigned long Rnd();
+ /** 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
- static std::string m_addr; ///< local ip address in string format
+ static std::string m_host; ///< local hostname
+ static ipaddr_t m_ip; ///< local ip address
+ static std::string m_addr; ///< local ip address in string format
#ifdef ENABLE_IPV6
#ifdef IPPROTO_IPV6
- static struct in6_addr m_local_ip6; ///< local ipv6 address
+ static struct in6_addr m_local_ip6; ///< local ipv6 address
#endif
- static std::string m_local_addr6; ///< local ipv6 address in string format
+ static std::string m_local_addr6; ///< local ipv6 address in string format
#endif
- static bool m_local_resolved; ///< ResolveLocal has been called if true
+ static bool m_local_resolved; ///< ResolveLocal has been called if true
};
diff --git a/dep/include/sockets/socket_include.h b/dep/include/sockets/socket_include.h
index 34e7a8ca5d1..1edac03be3a 100644
--- a/dep/include/sockets/socket_include.h
+++ b/dep/include/sockets/socket_include.h
@@ -1,6 +1,6 @@
/** \file socket_include.h
- ** \date 2005-04-12
- ** \author grymse@alhem.net
+ ** \date 2005-04-12
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
@@ -8,7 +8,7 @@ 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
+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.
@@ -60,7 +60,7 @@ typedef unsigned __int64 uint64_t;
#endif
#endif
-#ifndef _WIN32
+#ifndef _WIN32
// ----------------------------------------
// common unix includes / defines
#include <unistd.h>
@@ -108,7 +108,7 @@ namespace SOCKETS_NAMESPACE {
// ----------------------------------------
// OS specific adaptions
-#ifdef SOLARIS
+#ifdef SOLARIS
// ----------------------------------------
// Solaris
typedef unsigned short port_t;
@@ -133,8 +133,8 @@ namespace SOCKETS_NAMESPACE {
# define MSG_NOSIGNAL 0
# endif
# include <netinet/in.h>
-typedef in_addr_t ipaddr_t;
-typedef in_port_t port_t;
+typedef in_addr_t ipaddr_t;
+typedef in_port_t port_t;
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
@@ -150,14 +150,14 @@ namespace SOCKETS_NAMESPACE {
# error FreeBSD versions prior to 400014 does not support ipv6
# endif
-#elif defined __NetBSD__
-# 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
+#elif defined __NetBSD__
+# 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>
@@ -181,7 +181,7 @@ namespace SOCKETS_NAMESPACE {
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
-#elif defined _WIN32
+#elif defined _WIN32
// ----------------------------------------
// Win32
#ifdef _MSC_VER
@@ -238,26 +238,26 @@ namespace SOCKETS_NAMESPACE {
class WSAInitializer // Winsock Initializer
{
public:
- WSAInitializer() {
- if (WSAStartup(0x101,&m_wsadata))
- {
- exit(-1);
- }
- }
- ~WSAInitializer() {
- WSACleanup();
- }
+ WSAInitializer() {
+ if (WSAStartup(0x101,&m_wsadata))
+ {
+ exit(-1);
+ }
+ }
+ ~WSAInitializer() {
+ WSACleanup();
+ }
private:
- WSADATA m_wsadata;
+ WSADATA m_wsadata;
};
#ifdef SOCKETS_NAMESPACE
}
#endif
-#else
+#else
// ----------------------------------------
-// LINUX
+// LINUX
typedef unsigned long ipaddr_t;
typedef unsigned short port_t;
#ifdef SOCKETS_NAMESPACE
@@ -275,8 +275,8 @@ namespace SOCKETS_NAMESPACE {
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
- /** List type containing file descriptors. */
- typedef std::list<SOCKET> socket_v;
+ /** List type containing file descriptors. */
+ typedef std::list<SOCKET> socket_v;
#ifdef SOCKETS_NAMESPACE
diff --git a/dep/include/sockets/sockets-config.h b/dep/include/sockets/sockets-config.h
index fffc2bbe7f1..5b1ba2cbcb4 100644
--- a/dep/include/sockets/sockets-config.h
+++ b/dep/include/sockets/sockets-config.h
@@ -1,7 +1,7 @@
/**
- ** \file sockets-config.h
- ** \date 2007-04-14
- ** \author grymse@alhem.net
+ ** \file sockets-config.h
+ ** \date 2007-04-14
+ ** \author grymse@alhem.net
**/
/*
Copyright (C) 2007 Anders Hedstrom
@@ -73,8 +73,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/* Enable TCP reconnect on lost connection.
- Socket::OnReconnect
- Socket::OnDisconnect
+ Socket::OnReconnect
+ Socket::OnDisconnect
*/
#define ENABLE_RECONNECT