diff --git a/dep/CMakeLists.txt b/dep/CMakeLists.txt
index 4b11eda2fd..8332d1b154 100644
--- a/dep/CMakeLists.txt
+++ b/dep/CMakeLists.txt
@@ -35,7 +35,6 @@ endif()
add_subdirectory(g3dlite)
if(SERVERS)
- add_subdirectory(sockets)
add_subdirectory(gsoap)
endif()
diff --git a/dep/sockets/Base64.cpp b/dep/sockets/Base64.cpp
deleted file mode 100644
index f7f12f5edf..0000000000
--- a/dep/sockets/Base64.cpp
+++ /dev/null
@@ -1,262 +0,0 @@
-/** \file Base64.cpp
- ** \date 2004-02-13
- ** \author grymse@alhem.net
-**/
-/*
-Copyright (C) 2004-2007 Anders Hedstrom
-
-This library is made available under the terms of the GNU GPL.
-
-If you would like to use this library in a closed-source application,
-a separate license agreement is available. For information about
-the closed-source license agreement for the C++ sockets library,
-please visit http://www.alhem.net/Sockets/license.html and/or
-email license@alhem.net.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#include "Base64.h"
-
-#ifdef SOCKETS_NAMESPACE
-namespace SOCKETS_NAMESPACE {
-#endif
-
-const char *Base64::bstr =
- "ABCDEFGHIJKLMNOPQ"
- "RSTUVWXYZabcdefgh"
- "ijklmnopqrstuvwxy"
- "z0123456789+/";
-
-const char Base64::rstr[] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63,
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0,
- 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0,
- 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0};
-
-Base64::Base64()
-{
-}
-
-void Base64::encode(FILE *fil, std::string& output, bool add_crlf)
-{
- size_t remain;
- size_t i = 0;
- size_t o = 0;
- char input[4];
-
- output = "";
- remain = fread(input,1,3,fil);
- while (remain > 0)
- {
- if (add_crlf && o && o % 76 == 0)
- output += "\n";
- switch (remain)
- {
- case 1:
- output += bstr[ ((input[i] >> 2) & 0x3f) ];
- output += bstr[ ((input[i] << 4) & 0x30) ];
- output += "==";
- break;
- case 2:
- output += bstr[ ((input[i] >> 2) & 0x3f) ];
- output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ];
- output += bstr[ ((input[i + 1] << 2) & 0x3c) ];
- output += "=";
- break;
- default:
- output += bstr[ ((input[i] >> 2) & 0x3f) ];
- output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ];
- output += bstr[ ((input[i + 1] << 2) & 0x3c) + ((input[i + 2] >> 6) & 0x03) ];
- output += bstr[ (input[i + 2] & 0x3f) ];
- }
- o += 4;
- //
- remain = fread(input,1,3,fil);
- }
-}
-
-void Base64::encode(const std::string& str_in, std::string& str_out, bool add_crlf)
-{
- encode(str_in.c_str(), str_in.size(), str_out, add_crlf);
-}
-
-void Base64::encode(const char* input,size_t l,std::string& output, bool add_crlf)
-{
- size_t i = 0;
- size_t o = 0;
-
- output = "";
- while (i < l)
- {
- size_t remain = l - i;
- if (add_crlf && o && o % 76 == 0)
- output += "\n";
- switch (remain)
- {
- case 1:
- output += bstr[ ((input[i] >> 2) & 0x3f) ];
- output += bstr[ ((input[i] << 4) & 0x30) ];
- output += "==";
- break;
- case 2:
- output += bstr[ ((input[i] >> 2) & 0x3f) ];
- output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ];
- output += bstr[ ((input[i + 1] << 2) & 0x3c) ];
- output += "=";
- break;
- default:
- output += bstr[ ((input[i] >> 2) & 0x3f) ];
- output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ];
- output += bstr[ ((input[i + 1] << 2) & 0x3c) + ((input[i + 2] >> 6) & 0x03) ];
- output += bstr[ (input[i + 2] & 0x3f) ];
- }
- o += 4;
- i += 3;
- }
-}
-
-void Base64::encode(const unsigned char* input,size_t l,std::string& output,bool add_crlf)
-{
- size_t i = 0;
- size_t o = 0;
-
- output = "";
- while (i < l)
- {
- size_t remain = l - i;
- if (add_crlf && o && o % 76 == 0)
- output += "\n";
- switch (remain)
- {
- case 1:
- output += bstr[ ((input[i] >> 2) & 0x3f) ];
- output += bstr[ ((input[i] << 4) & 0x30) ];
- output += "==";
- break;
- case 2:
- output += bstr[ ((input[i] >> 2) & 0x3f) ];
- output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ];
- output += bstr[ ((input[i + 1] << 2) & 0x3c) ];
- output += "=";
- break;
- default:
- output += bstr[ ((input[i] >> 2) & 0x3f) ];
- output += bstr[ ((input[i] << 4) & 0x30) + ((input[i + 1] >> 4) & 0x0f) ];
- output += bstr[ ((input[i + 1] << 2) & 0x3c) + ((input[i + 2] >> 6) & 0x03) ];
- output += bstr[ (input[i + 2] & 0x3f) ];
- }
- o += 4;
- i += 3;
- }
-}
-
-void Base64::decode(const std::string& input,std::string& output)
-{
- size_t i = 0;
- size_t l = input.size();
-
- output = "";
- while (i < l)
- {
- while (i < l && (input[i] == 13 || input[i] == 10))
- i++;
- if (i < l)
- {
- char b1 = (char)((rstr[(int)input[i]] << 2 & 0xfc) +
- (rstr[(int)input[i + 1]] >> 4 & 0x03));
- output += b1;
- if (input[i + 2] != '=')
- {
- char b2 = (char)((rstr[(int)input[i + 1]] << 4 & 0xf0) +
- (rstr[(int)input[i + 2]] >> 2 & 0x0f));
- output += b2;
- }
- if (input[i + 3] != '=')
- {
- char b3 = (char)((rstr[(int)input[i + 2]] << 6 & 0xc0) +
- rstr[(int)input[i + 3]]);
- output += b3;
- }
- i += 4;
- }
- }
-}
-
-void Base64::decode(const std::string& input, unsigned char *output, size_t& sz)
-{
- size_t i = 0;
- size_t l = input.size();
- size_t j = 0;
-
- while (i < l)
- {
- while (i < l && (input[i] == 13 || input[i] == 10))
- i++;
- if (i < l)
- {
- unsigned char b1 = (unsigned char)((rstr[(int)input[i]] << 2 & 0xfc) +
- (rstr[(int)input[i + 1]] >> 4 & 0x03));
- if (output)
- {
- output[j] = b1;
- }
- j++;
- if (input[i + 2] != '=')
- {
- unsigned char b2 = (unsigned char)((rstr[(int)input[i + 1]] << 4 & 0xf0) +
- (rstr[(int)input[i + 2]] >> 2 & 0x0f));
- if (output)
- {
- output[j] = b2;
- }
- j++;
- }
- if (input[i + 3] != '=')
- {
- unsigned char b3 = (unsigned char)((rstr[(int)input[i + 2]] << 6 & 0xc0) +
- rstr[(int)input[i + 3]]);
- if (output)
- {
- output[j] = b3;
- }
- j++;
- }
- i += 4;
- }
- }
- sz = j;
-}
-
-size_t Base64::decode_length(const std::string& str64)
-{
- if (str64.empty() || str64.size() % 4)
- return 0;
- size_t l = 3 * (str64.size() / 4 - 1) + 1;
- if (str64[str64.size() - 2] != '=')
- l++;
- if (str64[str64.size() - 1] != '=')
- l++;
- return l;
-}
-
-#ifdef SOCKETS_NAMESPACE
-}
-#endif
-
-
diff --git a/dep/sockets/CMakeLists.txt b/dep/sockets/CMakeLists.txt
deleted file mode 100644
index a1756773c0..0000000000
--- a/dep/sockets/CMakeLists.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright (C) 2008-2010 Trinity
-#
-# This file is free software; as a special exception the author gives
-# unlimited permission to copy and/or distribute it, with or without
-# modifications, as long as this notice is preserved.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
-# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
-file(GLOB sources *.cpp)
-
-set(trinitysockets_STAT_SRCS
- ${sources}
-)
-
-include_directories(
- ${CMAKE_CURRENT_SOURCE_DIR}/include
-)
-
-add_library(trinitysockets STATIC ${trinitysockets_STAT_SRCS})
diff --git a/dep/sockets/Exception.cpp b/dep/sockets/Exception.cpp
deleted file mode 100644
index 4d79aeef81..0000000000
--- a/dep/sockets/Exception.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- ** \file Exception.cpp
- ** \date 2007-09-28
- ** \author grymse@alhem.net
-**/
-/*
-Copyright (C) 2007 Anders Hedstrom
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#ifdef _MSC_VER
-#pragma warning(disable:4786)
-#endif
-#include "Exception.h"
-
-#ifdef SOCKETS_NAMESPACE
-namespace SOCKETS_NAMESPACE {
-#endif
-
-Exception::Exception(const std::string& description) : m_description(description)
-{
-}
-
-const std::string Exception::ToString() const
-{
- return m_description;
-}
-
-#ifdef SOCKETS_NAMESPACE
-} // namespace SOCKETS_NAMESPACE {
-#endif
-
-
diff --git a/dep/sockets/Ipv4Address.cpp b/dep/sockets/Ipv4Address.cpp
deleted file mode 100644
index 0393503895..0000000000
--- a/dep/sockets/Ipv4Address.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-/**
- ** \file Ipv4Address.cpp
- ** \date 2006-09-21
- ** \author grymse@alhem.net
-**/
-/*
-Copyright (C) 2007 Anders Hedstrom
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#include "Ipv4Address.h"
-#include "Utility.h"
-#include "Parse.h"
-#ifndef _WIN32
-#include
-#endif
-
-#ifdef SOCKETS_NAMESPACE
-namespace SOCKETS_NAMESPACE {
-#endif
-
-Ipv4Address::Ipv4Address(port_t port) : m_valid(true)
-{
- memset(&m_addr, 0, sizeof(m_addr));
- m_addr.sin_family = AF_INET;
- m_addr.sin_port = htons( port );
-}
-
-Ipv4Address::Ipv4Address(ipaddr_t a,port_t port) : m_valid(true)
-{
- memset(&m_addr, 0, sizeof(m_addr));
- m_addr.sin_family = AF_INET;
- m_addr.sin_port = htons( port );
- memcpy(&m_addr.sin_addr, &a, sizeof(struct in_addr));
-}
-
-Ipv4Address::Ipv4Address(struct in_addr& a,port_t port) : m_valid(true)
-{
- memset(&m_addr, 0, sizeof(m_addr));
- m_addr.sin_family = AF_INET;
- m_addr.sin_port = htons( port );
- m_addr.sin_addr = a;
-}
-
-Ipv4Address::Ipv4Address(const std::string& host,port_t port) : m_valid(false)
-{
- memset(&m_addr, 0, sizeof(m_addr));
- m_addr.sin_family = AF_INET;
- m_addr.sin_port = htons( port );
- {
- ipaddr_t a;
- if (Utility::u2ip(host, a))
- {
- memcpy(&m_addr.sin_addr, &a, sizeof(struct in_addr));
- m_valid = true;
- }
- }
-}
-
-Ipv4Address::Ipv4Address(struct sockaddr_in& sa)
-{
- m_addr = sa;
- m_valid = sa.sin_family == AF_INET;
-}
-
-Ipv4Address::~Ipv4Address()
-{
-}
-
-Ipv4Address::operator struct sockaddr *()
-{
- return (struct sockaddr *)&m_addr;
-}
-
-Ipv4Address::operator socklen_t()
-{
- return sizeof(struct sockaddr_in);
-}
-
-void Ipv4Address::SetPort(port_t port)
-{
- m_addr.sin_port = htons( port );
-}
-
-port_t Ipv4Address::GetPort()
-{
- return ntohs( m_addr.sin_port );
-}
-
-bool Ipv4Address::Resolve(const std::string& hostname,struct in_addr& a)
-{
- struct sockaddr_in sa;
- memset(&a, 0, sizeof(a));
- if (Utility::isipv4(hostname))
- {
- if (!Utility::u2ip(hostname, sa, AI_NUMERICHOST))
- return false;
- a = sa.sin_addr;
- return true;
- }
- if (!Utility::u2ip(hostname, sa))
- return false;
- a = sa.sin_addr;
- return true;
-}
-
-bool Ipv4Address::Reverse(struct in_addr& a,std::string& name)
-{
- struct sockaddr_in sa;
- memset(&sa, 0, sizeof(sa));
- sa.sin_family = AF_INET;
- sa.sin_addr = a;
- return Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name);
-}
-
-std::string Ipv4Address::Convert(bool include_port)
-{
- if (include_port)
- return Convert(m_addr.sin_addr) + ":" + Utility::l2string(GetPort());
- return Convert(m_addr.sin_addr);
-}
-
-std::string Ipv4Address::Convert(struct in_addr& a)
-{
- struct sockaddr_in sa;
- memset(&sa, 0, sizeof(sa));
- sa.sin_family = AF_INET;
- sa.sin_addr = a;
- std::string name;
- Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name, NI_NUMERICHOST);
- return name;
-}
-
-void Ipv4Address::SetAddress(struct sockaddr *sa)
-{
- memcpy(&m_addr, sa, sizeof(struct sockaddr_in));
-}
-
-int Ipv4Address::GetFamily()
-{
- return m_addr.sin_family;
-}
-
-bool Ipv4Address::IsValid()
-{
- return m_valid;
-}
-
-bool Ipv4Address::operator==(SocketAddress& a)
-{
- if (a.GetFamily() != GetFamily())
- return false;
- if ((socklen_t)a != sizeof(m_addr))
- return false;
- struct sockaddr *sa = a;
- struct sockaddr_in *p = (struct sockaddr_in *)sa;
- if (p -> sin_port != m_addr.sin_port)
- return false;
- if (memcmp(&p -> sin_addr, &m_addr.sin_addr, 4))
- return false;
- return true;
-}
-
-std::auto_ptr Ipv4Address::GetCopy()
-{
- return std::auto_ptr(new Ipv4Address(m_addr));
-}
-
-std::string Ipv4Address::Reverse()
-{
- std::string tmp;
- Reverse(m_addr.sin_addr, tmp);
- return tmp;
-}
-
-#ifdef SOCKETS_NAMESPACE
-} // namespace SOCKETS_NAMESPACE {
-#endif
-
-
diff --git a/dep/sockets/Ipv6Address.cpp b/dep/sockets/Ipv6Address.cpp
deleted file mode 100644
index 3208b5098f..0000000000
--- a/dep/sockets/Ipv6Address.cpp
+++ /dev/null
@@ -1,247 +0,0 @@
-/**
- ** \file Ipv6Address.cpp
- ** \date 2006-09-21
- ** \author grymse@alhem.net
-**/
-/*
-Copyright (C) 2007 Anders Hedstrom
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#include "Ipv6Address.h"
-#ifdef ENABLE_IPV6
-
-#include "Utility.h"
-#include "Parse.h"
-#ifndef _WIN32
-#include
-#endif
-#ifdef IPPROTO_IPV6
-
-#ifdef SOCKETS_NAMESPACE
-namespace SOCKETS_NAMESPACE {
-#endif
-
-Ipv6Address::Ipv6Address(port_t port) : m_valid(true)
-{
- memset(&m_addr, 0, sizeof(m_addr));
- m_addr.sin6_family = AF_INET6;
- m_addr.sin6_port = htons( port );
-}
-
-Ipv6Address::Ipv6Address(struct in6_addr& a,port_t port) : m_valid(true)
-{
- memset(&m_addr, 0, sizeof(m_addr));
- m_addr.sin6_family = AF_INET6;
- m_addr.sin6_port = htons( port );
- m_addr.sin6_addr = a;
-}
-
-Ipv6Address::Ipv6Address(const std::string& host,port_t port) : m_valid(false)
-{
- memset(&m_addr, 0, sizeof(m_addr));
- m_addr.sin6_family = AF_INET6;
- m_addr.sin6_port = htons( port );
- {
- struct in6_addr a;
- if (Utility::u2ip(host, a))
- {
- m_addr.sin6_addr = a;
- m_valid = true;
- }
- }
-}
-
-Ipv6Address::Ipv6Address(struct sockaddr_in6& sa)
-{
- m_addr = sa;
- m_valid = sa.sin6_family == AF_INET6;
-}
-
-Ipv6Address::~Ipv6Address()
-{
-}
-
-Ipv6Address::operator struct sockaddr *()
-{
- return (struct sockaddr *)&m_addr;
-}
-
-Ipv6Address::operator socklen_t()
-{
- return sizeof(struct sockaddr_in6);
-}
-
-void Ipv6Address::SetPort(port_t port)
-{
- m_addr.sin6_port = htons( port );
-}
-
-port_t Ipv6Address::GetPort()
-{
- return ntohs( m_addr.sin6_port );
-}
-
-bool Ipv6Address::Resolve(const std::string& hostname,struct in6_addr& a)
-{
- struct sockaddr_in6 sa;
- memset(&a, 0, sizeof(a));
- if (Utility::isipv6(hostname))
- {
- if (!Utility::u2ip(hostname, sa, AI_NUMERICHOST))
- return false;
- a = sa.sin6_addr;
- return true;
- }
- if (!Utility::u2ip(hostname, sa))
- return false;
- a = sa.sin6_addr;
- return true;
-}
-
-bool Ipv6Address::Reverse(struct in6_addr& a,std::string& name)
-{
- struct sockaddr_in6 sa;
- memset(&sa, 0, sizeof(sa));
- sa.sin6_family = AF_INET6;
- sa.sin6_addr = a;
- return Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name);
-}
-
-std::string Ipv6Address::Convert(bool include_port)
-{
- if (include_port)
- return Convert(m_addr.sin6_addr) + ":" + Utility::l2string(GetPort());
- return Convert(m_addr.sin6_addr);
-}
-
-std::string Ipv6Address::Convert(struct in6_addr& a,bool mixed)
-{
- char slask[100]; // l2ip temporary
- *slask = 0;
- unsigned int prev = 0;
- bool skipped = false;
- bool ok_to_skip = true;
- if (mixed)
- {
- unsigned short x;
- unsigned short addr16[8];
- memcpy(addr16, &a, sizeof(addr16));
- for (size_t i = 0; i < 6; i++)
- {
- x = ntohs(addr16[i]);
- if (*slask && (x || !ok_to_skip || prev))
- strcat(slask,":");
- if (x || !ok_to_skip)
- {
- sprintf(slask + strlen(slask),"%x", x);
- if (x && skipped)
- ok_to_skip = false;
- }
- else
- {
- skipped = true;
- }
- prev = x;
- }
- x = ntohs(addr16[6]);
- sprintf(slask + strlen(slask),":%u.%u",x / 256,x & 255);
- x = ntohs(addr16[7]);
- sprintf(slask + strlen(slask),".%u.%u",x / 256,x & 255);
- }
- else
- {
- struct sockaddr_in6 sa;
- memset(&sa, 0, sizeof(sa));
- sa.sin6_family = AF_INET6;
- sa.sin6_addr = a;
- std::string name;
- Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name, NI_NUMERICHOST);
- return name;
- }
- return slask;
-}
-
-void Ipv6Address::SetAddress(struct sockaddr *sa)
-{
- memcpy(&m_addr, sa, sizeof(struct sockaddr_in6));
-}
-
-int Ipv6Address::GetFamily()
-{
- return m_addr.sin6_family;
-}
-
-void Ipv6Address::SetFlowinfo(uint32_t x)
-{
- m_addr.sin6_flowinfo = x;
-}
-
-uint32_t Ipv6Address::GetFlowinfo()
-{
- return m_addr.sin6_flowinfo;
-}
-
-#ifndef _WIN32
-void Ipv6Address::SetScopeId(uint32_t x)
-{
- m_addr.sin6_scope_id = x;
-}
-
-uint32_t Ipv6Address::GetScopeId()
-{
- return m_addr.sin6_scope_id;
-}
-#endif
-
-bool Ipv6Address::IsValid()
-{
- return m_valid;
-}
-
-bool Ipv6Address::operator==(SocketAddress& a)
-{
- if (a.GetFamily() != GetFamily())
- return false;
- if ((socklen_t)a != sizeof(m_addr))
- return false;
- struct sockaddr *sa = a;
- struct sockaddr_in6 *p = (struct sockaddr_in6 *)sa;
- if (p -> sin6_port != m_addr.sin6_port)
- return false;
- if (memcmp(&p -> sin6_addr, &m_addr.sin6_addr, sizeof(struct in6_addr)))
- return false;
- return true;
-}
-
-std::auto_ptr Ipv6Address::GetCopy()
-{
- return std::auto_ptr(new Ipv6Address(m_addr));
-}
-
-std::string Ipv6Address::Reverse()
-{
- std::string tmp;
- Reverse(m_addr.sin6_addr, tmp);
- return tmp;
-}
-
-#ifdef SOCKETS_NAMESPACE
-} // namespace SOCKETS_NAMESPACE {
-#endif
-#endif // IPPROTO_IPV6
-#endif // ENABLE_IPV6
-
-
diff --git a/dep/sockets/Lock.cpp b/dep/sockets/Lock.cpp
deleted file mode 100644
index b75664cfbd..0000000000
--- a/dep/sockets/Lock.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/** \file Lock.cpp
- ** \date 2005-08-22
- ** \author grymse@alhem.net
-**/
-/*
-Copyright (C) 2005,2007 Anders Hedstrom
-
-This library is made available under the terms of the GNU GPL.
-
-If you would like to use this library in a closed-source application,
-a separate license agreement is available. For information about
-the closed-source license agreement for the C++ sockets library,
-please visit http://www.alhem.net/Sockets/license.html and/or
-email license@alhem.net.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#include "Mutex.h"
-#include "Lock.h"
-
-#ifdef SOCKETS_NAMESPACE
-namespace SOCKETS_NAMESPACE {
-#endif
-
-Lock::Lock(Mutex& m) : m_mutex(m)
-{
- m_mutex.Lock();
-}
-
-Lock::~Lock()
-{
- m_mutex.Unlock();
-}
-
-
-#ifdef SOCKETS_NAMESPACE
-}
-#endif
-
-
diff --git a/dep/sockets/Makefile b/dep/sockets/Makefile
deleted file mode 100644
index 88b6199788..0000000000
--- a/dep/sockets/Makefile
+++ /dev/null
@@ -1,136 +0,0 @@
-# CMAKE generated file: DO NOT EDIT!
-# Generated by "Unix Makefiles" Generator, CMake Version 2.6
-
-# Default target executed when no arguments are given to make.
-default_target: all
-.PHONY : default_target
-
-#=============================================================================
-# Special targets provided by cmake.
-
-# Disable implicit rules so canoncical targets will work.
-.SUFFIXES:
-
-# Remove some rules from gmake that .SUFFIXES does not remove.
-SUFFIXES =
-
-.SUFFIXES: .hpux_make_needs_suffix_list
-
-# Suppress display of executed commands.
-$(VERBOSE).SILENT:
-
-# A target that is always out of date.
-cmake_force:
-.PHONY : cmake_force
-
-#=============================================================================
-# Set environment variables for the build.
-
-# The shell in which to execute make rules.
-SHELL = /bin/sh
-
-# The CMake executable.
-CMAKE_COMMAND = /usr/bin/cmake
-
-# The command to remove a file.
-RM = /usr/bin/cmake -E remove -f
-
-# The program to use to edit the cache.
-CMAKE_EDIT_COMMAND = /usr/bin/ccmake
-
-# The top-level source directory on which CMake was run.
-CMAKE_SOURCE_DIR = /home/trinity/dev/trinitycore/dep/sockets
-
-# The top-level build directory on which CMake was run.
-CMAKE_BINARY_DIR = /home/trinity/dev/trinitycore/dep/sockets
-
-#=============================================================================
-# Targets provided globally by CMake.
-
-# Special rule for the target edit_cache
-edit_cache:
- @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
- /usr/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
-.PHONY : edit_cache
-
-# Special rule for the target edit_cache
-edit_cache/fast: edit_cache
-.PHONY : edit_cache/fast
-
-# Special rule for the target rebuild_cache
-rebuild_cache:
- @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
- /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
-.PHONY : rebuild_cache
-
-# Special rule for the target rebuild_cache
-rebuild_cache/fast: rebuild_cache
-.PHONY : rebuild_cache/fast
-
-# The main all target
-all: cmake_check_build_system
- $(CMAKE_COMMAND) -E cmake_progress_start /home/trinity/dev/trinitycore/dep/sockets/CMakeFiles /home/trinity/dev/trinitycore/dep/sockets/CMakeFiles/progress.make
- $(MAKE) -f CMakeFiles/Makefile2 all
- $(CMAKE_COMMAND) -E cmake_progress_start /home/trinity/dev/trinitycore/dep/sockets/CMakeFiles 0
-.PHONY : all
-
-# The main clean target
-clean:
- $(MAKE) -f CMakeFiles/Makefile2 clean
-.PHONY : clean
-
-# The main clean target
-clean/fast: clean
-.PHONY : clean/fast
-
-# Prepare targets for installation.
-preinstall: all
- $(MAKE) -f CMakeFiles/Makefile2 preinstall
-.PHONY : preinstall
-
-# Prepare targets for installation.
-preinstall/fast:
- $(MAKE) -f CMakeFiles/Makefile2 preinstall
-.PHONY : preinstall/fast
-
-# clear depends
-depend:
- $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
-.PHONY : depend
-
-#=============================================================================
-# Target rules for targets named trinitysockets
-
-# Build rule for target.
-trinitysockets: cmake_check_build_system
- $(MAKE) -f CMakeFiles/Makefile2 trinitysockets
-.PHONY : trinitysockets
-
-# fast build rule for target.
-trinitysockets/fast:
- $(MAKE) -f CMakeFiles/trinitysockets.dir/build.make CMakeFiles/trinitysockets.dir/build
-.PHONY : trinitysockets/fast
-
-# Help Target
-help:
- @echo "The following are some of the valid targets for this Makefile:"
- @echo "... all (the default if no target is provided)"
- @echo "... clean"
- @echo "... depend"
- @echo "... edit_cache"
- @echo "... rebuild_cache"
- @echo "... trinitysockets"
-.PHONY : help
-
-
-
-#=============================================================================
-# Special targets to cleanup operation of make.
-
-# Special rule to run CMake to check the build system integrity.
-# No rule that depends on this can have commands that come from listfiles
-# because they might be regenerated.
-cmake_check_build_system:
- $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
-.PHONY : cmake_check_build_system
-
diff --git a/dep/sockets/Mutex.cpp b/dep/sockets/Mutex.cpp
deleted file mode 100644
index 681e85cee5..0000000000
--- a/dep/sockets/Mutex.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/** \file Mutex.cpp
- ** \date 2004-10-30
- ** \author grymse@alhem.net
-**/
-/*
-Copyright (C) 2004-2007 Anders Hedstrom
-
-This library is made available under the terms of the GNU GPL.
-
-If you would like to use this library in a closed-source application,
-a separate license agreement is available. For information about
-the closed-source license agreement for the C++ sockets library,
-please visit http://www.alhem.net/Sockets/license.html and/or
-email license@alhem.net.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#include "Mutex.h"
-
-#ifdef SOCKETS_NAMESPACE
-namespace SOCKETS_NAMESPACE {
-#endif
-
-Mutex::Mutex()
-{
-#ifdef _WIN32
- m_mutex = ::CreateMutex(NULL, FALSE, NULL);
-#else
- pthread_mutex_init(&m_mutex, NULL);
-#endif
-}
-
-Mutex::~Mutex()
-{
-#ifdef _WIN32
- ::CloseHandle(m_mutex);
-#else
- pthread_mutex_destroy(&m_mutex);
-#endif
-}
-
-void Mutex::Lock()
-{
-#ifdef _WIN32
- /*DWORD d =*/ WaitForSingleObject(m_mutex, INFINITE);
- /// \todo check 'd' for result
-#else
- pthread_mutex_lock(&m_mutex);
-#endif
-}
-
-void Mutex::Unlock()
-{
-#ifdef _WIN32
- ::ReleaseMutex(m_mutex);
-#else
- pthread_mutex_unlock(&m_mutex);
-#endif
-}
-
-#ifdef SOCKETS_NAMESPACE
-}
-#endif
-
-
diff --git a/dep/sockets/Parse.cpp b/dep/sockets/Parse.cpp
deleted file mode 100644
index 2967859f23..0000000000
--- a/dep/sockets/Parse.cpp
+++ /dev/null
@@ -1,318 +0,0 @@
-/** \file Parse.cpp - parse a string
- **
- ** Written: 1999-Feb-10 grymse@alhem.net
- **/
-
-/*
-Copyright (C) 1999-2007 Anders Hedstrom
-
-This library is made available under the terms of the GNU GPL.
-
-If you would like to use this library in a closed-source application,
-a separate license agreement is available. For information about
-the closed-source license agreement for the C++ sockets library,
-please visit http://www.alhem.net/Sockets/license.html and/or
-email license@alhem.net.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#include
-#include
-
-#include "Parse.h"
-
-#ifdef SOCKETS_NAMESPACE
-namespace SOCKETS_NAMESPACE {
-#endif
-
-/* implementation of class Parse */
-
-Parse::Parse()
-:pa_the_str("")
-,pa_splits("")
-,pa_ord("")
-,pa_the_ptr(0)
-,pa_breakchar(0)
-,pa_enable(0)
-,pa_disable(0)
-,pa_nospace(0)
-,pa_quote(false)
-{
-}
-
-Parse::Parse(const std::string&s)
-:pa_the_str(s)
-,pa_splits("")
-,pa_ord("")
-,pa_the_ptr(0)
-,pa_breakchar(0)
-,pa_enable(0)
-,pa_disable(0)
-,pa_nospace(0)
-,pa_quote(false)
-{
-}
-
-Parse::Parse(const std::string&s,const std::string&sp)
-:pa_the_str(s)
-,pa_splits(sp)
-,pa_ord("")
-,pa_the_ptr(0)
-,pa_breakchar(0)
-,pa_enable(0)
-,pa_disable(0)
-,pa_nospace(0)
-,pa_quote(false)
-{
-}
-
-Parse::Parse(const std::string&s,const std::string&sp,short /*nospace*/)
-:pa_the_str(s)
-,pa_splits(sp)
-,pa_ord("")
-,pa_the_ptr(0)
-,pa_breakchar(0)
-,pa_enable(0)
-,pa_disable(0)
-,pa_nospace(1)
-,pa_quote(false)
-{
-}
-
-Parse::~Parse()
-{
-}
-
-#define C ((pa_the_ptr l(h);
-
- if (l.Bind("127.0.0.1", m_port))
- {
- return;
- }
- h.Add(&l);
-
- m_ready = true;
- while (!m_quit && IsRunning() )
- {
- h.Select(0, 500000);
- }
- SetRunning(false);
-}
-
-void ResolvServer::Quit()
-{
- m_quit = true;
-}
-
-bool ResolvServer::Ready()
-{
- return m_ready;
-}
-
-#ifdef SOCKETS_NAMESPACE
-}
-#endif
-
-#endif // ENABLE_RESOLVER
-
-
diff --git a/dep/sockets/ResolvSocket.cpp b/dep/sockets/ResolvSocket.cpp
deleted file mode 100644
index 636de27642..0000000000
--- a/dep/sockets/ResolvSocket.cpp
+++ /dev/null
@@ -1,426 +0,0 @@
-/** \file ResolvSocket.cpp
- ** \date 2005-03-24
- ** \author grymse@alhem.net
-**/
-/*
-Copyright (C) 2004-2007 Anders Hedstrom
-
-This library is made available under the terms of the GNU GPL.
-
-If you would like to use this library in a closed-source application,
-a separate license agreement is available. For information about
-the closed-source license agreement for the C++ sockets library,
-please visit http://www.alhem.net/Sockets/license.html and/or
-email license@alhem.net.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#ifdef _WIN32
-#ifdef _MSC_VER
-#pragma warning(disable:4786)
-#pragma warning(disable:4503)
-#endif
-#else
-#include
-#endif
-#include "ResolvSocket.h"
-#ifdef ENABLE_RESOLVER
-#include "Utility.h"
-#include "Parse.h"
-#include "ISocketHandler.h"
-#include "Lock.h"
-#include "Mutex.h"
-
-#ifdef SOCKETS_NAMESPACE
-namespace SOCKETS_NAMESPACE {
-#endif
-
-//#ifdef _DEBUG
-//#define DEB(x) x
-//#else
-#define DEB(x)
-//#endif
-
-// static
-ResolvSocket::cache_t ResolvSocket::m_cache;
-ResolvSocket::timeout_t ResolvSocket::m_cache_to;
-Mutex ResolvSocket::m_cache_mutex;
-
-ResolvSocket::ResolvSocket(ISocketHandler& h)
-:TcpSocket(h)
-,m_bServer(false)
-,m_parent(NULL)
-#ifdef ENABLE_IPV6
-,m_resolve_ipv6(false)
-#endif
-,m_cached(false)
-{
- SetLineProtocol();
-}
-
-ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, const std::string& host, port_t port, bool ipv6)
-:TcpSocket(h)
-,m_bServer(false)
-,m_parent(parent)
-,m_resolv_host(host)
-,m_resolv_port(port)
-#ifdef ENABLE_IPV6
-,m_resolve_ipv6(ipv6)
-#endif
-,m_cached(false)
-{
- SetLineProtocol();
-}
-
-ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, ipaddr_t a)
-:TcpSocket(h)
-,m_bServer(false)
-,m_parent(parent)
-,m_resolv_port(0)
-,m_resolv_address(a)
-#ifdef ENABLE_IPV6
-,m_resolve_ipv6(false)
-#endif
-,m_cached(false)
-{
- SetLineProtocol();
-}
-
-#ifdef ENABLE_IPV6
-ResolvSocket::ResolvSocket(ISocketHandler& h, Socket *parent, in6_addr& a)
-:TcpSocket(h)
-,m_bServer(false)
-,m_parent(parent)
-,m_resolv_port(0)
-,m_resolve_ipv6(true)
-,m_resolv_address6(a)
-,m_cached(false)
-{
- SetLineProtocol();
-}
-#endif
-
-ResolvSocket::~ResolvSocket()
-{
-}
-
-void ResolvSocket::OnLine(const std::string& line)
-{
- Parse pa(line, ":");
- if (m_bServer)
- {
- m_query = pa.getword();
- m_data = pa.getrest();
-DEB( fprintf(stderr, " *** ResolvSocket server; query=%s, data=%s\n", m_query.c_str(), m_data.c_str());)
- // %! check cache
- {
- Lock lock(m_cache_mutex);
- if (m_cache[m_query].find(m_data) != m_cache[m_query].end())
- {
- if (time(NULL) - m_cache_to[m_query][m_data] < 3600) // ttl
- {
- std::string result = m_cache[m_query][m_data];
-DEB(fprintf(stderr, " *** Returning cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), result.c_str());)
- Send("Cached\n");
- if (!result.size()) /* failed */
- {
- Send("Failed\n\n");
- SetCloseAndDelete();
- return;
- }
- else
- if (m_query == "gethostbyname")
- {
- Send("A: " + result + "\n\n");
- SetCloseAndDelete();
- return;
- }
- else
-#ifdef ENABLE_IPV6
-#ifdef IPPROTO_IPV6
- if (m_query == "gethostbyname2")
- {
- Send("AAAA: " + result + "\n\n");
- SetCloseAndDelete();
- return;
- }
- else
-#endif
-#endif
- if (m_query == "gethostbyaddr")
- {
- Send("Name: " + result + "\n\n");
- SetCloseAndDelete();
- return;
- }
- }
- }
- }
- if (!Detach()) // detach failed?
- {
- SetCloseAndDelete();
- }
- return;
- }
- std::string key = pa.getword();
- std::string value = pa.getrest();
-DEB( fprintf(stderr, " *** ResolvSocket response; %s: %s\n", key.c_str(), value.c_str());)
-
- if (key == "Cached")
- {
- m_cached = true;
- }
- else
- if (key == "Failed" && m_parent)
- {
-DEB( fprintf(stderr, " ************ Resolve failed\n");)
- if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
- {
- m_parent -> OnResolveFailed(m_resolv_id);
- }
- // update cache
- if (!m_cached)
- {
- Lock lock(m_cache_mutex);
-DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());)
- m_cache[m_query][m_data] = value;
- m_cache_to[m_query][m_data] = time(NULL);
- }
- m_parent = NULL;
- }
- else
- if (key == "Name" && !m_resolv_host.size() && m_parent)
- {
- if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
- {
- m_parent -> OnReverseResolved(m_resolv_id, value);
- }
- // update cache
- if (!m_cached)
- {
- Lock lock(m_cache_mutex);
-DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());)
- m_cache[m_query][m_data] = value;
- m_cache_to[m_query][m_data] = time(NULL);
- }
- m_parent = NULL;
- }
- else
- if (key == "A" && m_parent)
- {
- if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
- {
- ipaddr_t l;
- Utility::u2ip(value, l); // ip2ipaddr_t
- m_parent -> OnResolved(m_resolv_id, l, m_resolv_port);
- }
- // update cache
- if (!m_cached)
- {
- Lock lock(m_cache_mutex);
-DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());)
- m_cache[m_query][m_data] = value;
- m_cache_to[m_query][m_data] = time(NULL);
- }
- m_parent = NULL; // always use first ip in case there are several
- }
-#ifdef ENABLE_IPV6
-#ifdef IPPROTO_IPV6
- else
- if (key == "AAAA" && m_parent)
- {
- if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
- {
- in6_addr a;
- Utility::u2ip(value, a);
- m_parent -> OnResolved(m_resolv_id, a, m_resolv_port);
- }
- // update cache
- if (!m_cached)
- {
- Lock lock(m_cache_mutex);
-DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());)
- m_cache[m_query][m_data] = value;
- m_cache_to[m_query][m_data] = time(NULL);
- }
- m_parent = NULL;
- }
-#endif
-#endif
-}
-
-void ResolvSocket::OnDetached()
-{
-DEB( fprintf(stderr, " *** ResolvSocket::OnDetached(); query=%s, data=%s\n", m_query.c_str(), m_data.c_str());)
- if (m_query == "gethostbyname")
- {
- struct sockaddr_in sa;
- if (Utility::u2ip(m_data, sa))
- {
- std::string ip;
- Utility::l2ip(sa.sin_addr, ip);
- Send("A: " + ip + "\n");
- }
- else
- {
- Send("Failed\n");
- }
- Send("\n");
- }
- else
-#ifdef ENABLE_IPV6
-#ifdef IPPROTO_IPV6
- if (m_query == "gethostbyname2")
- {
- struct sockaddr_in6 sa;
- if (Utility::u2ip(m_data, sa))
- {
- std::string ip;
- Utility::l2ip(sa.sin6_addr, ip);
- Send("AAAA: " + ip + "\n");
- }
- else
- {
- Send("Failed\n");
- }
- Send("\n");
- }
- else
-#endif
-#endif
- if (m_query == "gethostbyaddr")
- {
- if (Utility::isipv4( m_data ))
- {
- struct sockaddr_in sa;
- if (!Utility::u2ip(m_data, sa, AI_NUMERICHOST))
- {
- Send("Failed: convert to sockaddr_in failed\n");
- }
- else
- {
- std::string name;
- if (!Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), name))
- {
- Send("Failed: ipv4 reverse lookup of " + m_data + "\n");
- }
- else
- {
- Send("Name: " + name + "\n");
- }
- }
- }
- else
-#ifdef ENABLE_IPV6
-#ifdef IPPROTO_IPV6
- if (Utility::isipv6( m_data ))
- {
- struct sockaddr_in6 sa;
- if (!Utility::u2ip(m_data, sa, AI_NUMERICHOST))
- {
- Send("Failed: convert to sockaddr_in6 failed\n");
- }
- else
- {
- std::string name;
- if (!Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), name))
- {
- Send("Failed: ipv6 reverse lookup of " + m_data + "\n");
- }
- else
- {
- Send("Name: " + name + "\n");
- }
- }
- }
- else
-#endif
-#endif
- {
- Send("Failed: malformed address\n");
- }
- Send("\n");
- }
- else
- {
- std::string msg = "Unknown query type: " + m_query;
- Handler().LogError(this, "OnDetached", 0, msg);
- Send("Unknown\n\n");
- }
- SetCloseAndDelete();
-}
-
-void ResolvSocket::OnConnect()
-{
- if (!m_resolv_host.empty())
- {
-#ifdef ENABLE_IPV6
- std::string msg = (m_resolve_ipv6 ? "gethostbyname2 " : "gethostbyname ") + m_resolv_host + "\n";
- m_query = m_resolve_ipv6 ? "gethostbyname2" : "gethostbyname";
-#else
- std::string msg = "gethostbyname " + m_resolv_host + "\n";
- m_query = "gethostbyname";
-#endif
- m_data = m_resolv_host;
- Send( msg );
- return;
- }
-#ifdef ENABLE_IPV6
- if (m_resolve_ipv6)
- {
- std::string tmp;
- Utility::l2ip(m_resolv_address6, tmp);
- m_query = "gethostbyaddr";
- m_data = tmp;
- std::string msg = "gethostbyaddr " + tmp + "\n";
- Send( msg );
- }
-#endif
- std::string tmp;
- Utility::l2ip(m_resolv_address, tmp);
- m_query = "gethostbyaddr";
- m_data = tmp;
- std::string msg = "gethostbyaddr " + tmp + "\n";
- Send( msg );
-}
-
-void ResolvSocket::OnDelete()
-{
- if (m_parent)
- {
- if (Handler().Resolving(m_parent) || Handler().Valid(m_parent))
- {
- m_parent -> OnResolveFailed(m_resolv_id);
- }
- // update cache
- if (!m_cached)
- {
- Lock lock(m_cache_mutex);
- std::string value;
-DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(), m_data.c_str(), value.c_str());)
- m_cache[m_query][m_data] = value;
- m_cache_to[m_query][m_data] = time(NULL);
- }
- m_parent = NULL;
- }
-}
-
-#ifdef SOCKETS_NAMESPACE
-}
-#endif
-
-#endif // ENABLE_RESOLVER
-
-
diff --git a/dep/sockets/Socket.cpp b/dep/sockets/Socket.cpp
deleted file mode 100644
index f53cd27621..0000000000
--- a/dep/sockets/Socket.cpp
+++ /dev/null
@@ -1,1726 +0,0 @@
-/** \file Socket.cpp
- ** \date 2004-02-13
- ** \author grymse@alhem.net
-**/
-/*
-Copyright (C) 2004-2007 Anders Hedstrom
-
-This library is made available under the terms of the GNU GPL.
-
-If you would like to use this library in a closed-source application,
-a separate license agreement is available. For information about
-the closed-source license agreement for the C++ sockets library,
-please visit http://www.alhem.net/Sockets/license.html and/or
-email license@alhem.net.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#include "Socket.h"
-#ifdef _WIN32
-#ifdef _MSC_VER
-#pragma warning(disable:4786)
-#endif
-#include
-#else
-#include
-#include
-#endif
-#include
-#include
-
-#include "ISocketHandler.h"
-#include "Utility.h"
-
-#include "SocketAddress.h"
-#include "SocketHandler.h"
-#ifdef ENABLE_EXCEPTIONS
-#include "Exception.h"
-#endif
-#include "Ipv4Address.h"
-
-//#ifdef _DEBUG
-//#define DEB(x) x; fflush(stderr);
-//#else
-#define DEB(x)
-//#endif
-
-#ifdef SOCKETS_NAMESPACE
-namespace SOCKETS_NAMESPACE {
-#endif
-
-// statics
-#ifdef _WIN32
-WSAInitializer Socket::m_winsock_init;
-#endif
-
-Socket::Socket(ISocketHandler& h)
-//:m_flags(0)
-:m_handler(h)
-,m_socket( INVALID_SOCKET )
-,m_bDel(false)
-,m_bClose(false)
-,m_tCreate(time(NULL))
-,m_parent(NULL)
-,m_b_disable_read(false)
-,m_connected(false)
-,m_b_erased_by_handler(false)
-,m_tClose(0)
-,m_client_remote_address(NULL)
-,m_remote_address(NULL)
-,m_traffic_monitor(NULL)
-,m_bLost(false)
-#ifdef HAVE_OPENSSL
-,m_b_enable_ssl(false)
-,m_b_ssl(false)
-,m_b_ssl_server(false)
-#endif
-#ifdef ENABLE_IPV6
-,m_ipv6(false)
-#endif
-#ifdef ENABLE_POOL
-,m_socket_type(0)
-,m_bClient(false)
-,m_bRetain(false)
-#endif
-#ifdef ENABLE_SOCKS4
-,m_bSocks4(false)
-,m_socks4_host(h.GetSocks4Host())
-,m_socks4_port(h.GetSocks4Port())
-,m_socks4_userid(h.GetSocks4Userid())
-#endif
-#ifdef ENABLE_DETACH
-,m_detach(false)
-,m_detached(false)
-,m_pThread(NULL)
-,m_slave_handler(NULL)
-#endif
-{
-}
-
-Socket::~Socket()
-{
- Handler().Remove(this);
- if (m_socket != INVALID_SOCKET
-#ifdef ENABLE_POOL
- && !m_bRetain
-#endif
- )
- {
- Close();
- }
-}
-
-void Socket::Init()
-{
-}
-
-void Socket::OnRead()
-{
-}
-
-void Socket::OnWrite()
-{
-}
-
-void Socket::OnException()
-{
- // %! exception doesn't always mean something bad happened, this code should be reworked
- // errno valid here?
- int err = SoError();
- Handler().LogError(this, "exception on select", err, StrError(err), LOG_LEVEL_FATAL);
- SetCloseAndDelete();
-}
-
-void Socket::OnDelete()
-{
-}
-
-void Socket::OnConnect()
-{
-}
-
-void Socket::OnAccept()
-{
-}
-
-int Socket::Close()
-{
- if (m_socket == INVALID_SOCKET) // this could happen
- {
- Handler().LogError(this, "Socket::Close", 0, "file descriptor invalid", LOG_LEVEL_WARNING);
- return 0;
- }
- int n;
- if ((n = closesocket(m_socket)) == -1)
- {
- // failed...
- Handler().LogError(this, "close", Errno, StrError(Errno), LOG_LEVEL_ERROR);
- }
- Handler().Set(m_socket, false, false, false); // remove from fd_set's
- Handler().AddList(m_socket, LIST_CALLONCONNECT, false);
-#ifdef ENABLE_DETACH
- Handler().AddList(m_socket, LIST_DETACH, false);
-#endif
- Handler().AddList(m_socket, LIST_TIMEOUT, false);
- Handler().AddList(m_socket, LIST_RETRY, false);
- Handler().AddList(m_socket, LIST_CLOSE, false);
- m_socket = INVALID_SOCKET;
- return n;
-}
-
-SOCKET Socket::CreateSocket(int af,int type, const std::string& protocol)
-{
- struct protoent *p = NULL;
- SOCKET s;
-
-#ifdef ENABLE_POOL
- m_socket_type = type;
- m_socket_protocol = protocol;
-#endif
- if (!protocol.empty())
- {
- p = getprotobyname( protocol.c_str() );
- if (!p)
- {
- Handler().LogError(this, "getprotobyname", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- SetCloseAndDelete();
-#ifdef ENABLE_EXCEPTIONS
- throw Exception(std::string("getprotobyname() failed: ") + StrError(Errno));
-#endif
- return INVALID_SOCKET;
- }
- }
- int protno = p ? p -> p_proto : 0;
-
- s = socket(af, type, protno);
- if (s == INVALID_SOCKET)
- {
- Handler().LogError(this, "socket", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- SetCloseAndDelete();
-#ifdef ENABLE_EXCEPTIONS
- throw Exception(std::string("socket() failed: ") + StrError(Errno));
-#endif
- return INVALID_SOCKET;
- }
- Attach(s);
- OnOptions(af, type, protno, s);
- Attach(INVALID_SOCKET);
- return s;
-}
-
-void Socket::Attach(SOCKET s)
-{
- m_socket = s;
-}
-
-SOCKET Socket::GetSocket()
-{
- return m_socket;
-}
-
-void Socket::SetDeleteByHandler(bool x)
-{
- m_bDel = x;
-}
-
-bool Socket::DeleteByHandler()
-{
- return m_bDel;
-}
-
-void Socket::SetCloseAndDelete(bool x)
-{
- if (x != m_bClose)
- {
- Handler().AddList(m_socket, LIST_CLOSE, x);
- m_bClose = x;
- if (x)
- {
- m_tClose = time(NULL);
- }
- }
-}
-
-bool Socket::CloseAndDelete()
-{
- return m_bClose;
-}
-
-void Socket::SetRemoteAddress(SocketAddress& ad) //struct sockaddr* sa, socklen_t l)
-{
- m_remote_address = ad.GetCopy();
-}
-
-std::auto_ptr Socket::GetRemoteSocketAddress()
-{
- return m_remote_address -> GetCopy();
-}
-
-ISocketHandler& Socket::Handler() const
-{
-#ifdef ENABLE_DETACH
- if (IsDetached())
- return *m_slave_handler;
-#endif
- return m_handler;
-}
-
-ISocketHandler& Socket::MasterHandler() const
-{
- return m_handler;
-}
-
-ipaddr_t Socket::GetRemoteIP4()
-{
- ipaddr_t l = 0;
-#ifdef ENABLE_IPV6
- if (m_ipv6)
- {
- Handler().LogError(this, "GetRemoteIP4", 0, "get ipv4 address for ipv6 socket", LOG_LEVEL_WARNING);
- }
-#endif
- if (m_remote_address.get() != NULL)
- {
- struct sockaddr *p = *m_remote_address;
- struct sockaddr_in *sa = (struct sockaddr_in *)p;
- memcpy(&l, &sa -> sin_addr, sizeof(struct in_addr));
- }
- return l;
-}
-
-#ifdef ENABLE_IPV6
-#ifdef IPPROTO_IPV6
-struct in6_addr Socket::GetRemoteIP6()
-{
- if (!m_ipv6)
- {
- Handler().LogError(this, "GetRemoteIP6", 0, "get ipv6 address for ipv4 socket", LOG_LEVEL_WARNING);
- }
- struct sockaddr_in6 fail;
- if (m_remote_address.get() != NULL)
- {
- struct sockaddr *p = *m_remote_address;
- memcpy(&fail, p, sizeof(struct sockaddr_in6));
- }
- else
- {
- memset(&fail, 0, sizeof(struct sockaddr_in6));
- }
- return fail.sin6_addr;
-}
-#endif
-#endif
-
-port_t Socket::GetRemotePort()
-{
- if (!m_remote_address.get())
- {
- return 0;
- }
- return m_remote_address -> GetPort();
-}
-
-std::string Socket::GetRemoteAddress()
-{
- if (!m_remote_address.get())
- {
- return "";
- }
- return m_remote_address -> Convert(false);
-}
-
-std::string Socket::GetRemoteHostname()
-{
- if (!m_remote_address.get())
- {
- return "";
- }
- return m_remote_address -> Reverse();
-}
-
-bool Socket::SetNonblocking(bool bNb)
-{
-#ifdef _WIN32
- unsigned long l = bNb ? 1 : 0;
- int n = ioctlsocket(m_socket, FIONBIO, &l);
- if (n != 0)
- {
- Handler().LogError(this, "ioctlsocket(FIONBIO)", Errno, "");
- return false;
- }
- return true;
-#else
- if (bNb)
- {
- if (fcntl(m_socket, F_SETFL, O_NONBLOCK) == -1)
- {
- Handler().LogError(this, "fcntl(F_SETFL, O_NONBLOCK)", Errno, StrError(Errno), LOG_LEVEL_ERROR);
- return false;
- }
- }
- else
- {
- if (fcntl(m_socket, F_SETFL, 0) == -1)
- {
- Handler().LogError(this, "fcntl(F_SETFL, 0)", Errno, StrError(Errno), LOG_LEVEL_ERROR);
- return false;
- }
- }
- return true;
-#endif
-}
-
-bool Socket::SetNonblocking(bool bNb, SOCKET s)
-{
-#ifdef _WIN32
- unsigned long l = bNb ? 1 : 0;
- int n = ioctlsocket(s, FIONBIO, &l);
- if (n != 0)
- {
- Handler().LogError(this, "ioctlsocket(FIONBIO)", Errno, "");
- return false;
- }
- return true;
-#else
- if (bNb)
- {
- if (fcntl(s, F_SETFL, O_NONBLOCK) == -1)
- {
- Handler().LogError(this, "fcntl(F_SETFL, O_NONBLOCK)", Errno, StrError(Errno), LOG_LEVEL_ERROR);
- return false;
- }
- }
- else
- {
- if (fcntl(s, F_SETFL, 0) == -1)
- {
- Handler().LogError(this, "fcntl(F_SETFL, 0)", Errno, StrError(Errno), LOG_LEVEL_ERROR);
- return false;
- }
- }
- return true;
-#endif
-}
-
-void Socket::Set(bool bRead, bool bWrite, bool bException)
-{
- Handler().Set(m_socket, bRead, bWrite, bException);
-}
-
-bool Socket::Ready()
-{
- if (m_socket != INVALID_SOCKET && !CloseAndDelete())
- return true;
- return false;
-}
-
-void Socket::OnLine(const std::string& )
-{
-}
-
-void Socket::OnConnectFailed()
-{
-}
-
-Socket *Socket::GetParent()
-{
- return m_parent;
-}
-
-void Socket::SetParent(Socket *x)
-{
- m_parent = x;
-}
-
-port_t Socket::GetPort()
-{
- Handler().LogError(this, "GetPort", 0, "GetPort only implemented for ListenSocket", LOG_LEVEL_WARNING);
- return 0;
-}
-
-bool Socket::OnConnectRetry()
-{
- return true;
-}
-
-#ifdef ENABLE_RECONNECT
-void Socket::OnReconnect()
-{
-}
-#endif
-
-time_t Socket::Uptime()
-{
- return time(NULL) - m_tCreate;
-}
-
-#ifdef ENABLE_IPV6
-void Socket::SetIpv6(bool x)
-{
- m_ipv6 = x;
-}
-
-bool Socket::IsIpv6()
-{
- return m_ipv6;
-}
-#endif
-
-void Socket::DisableRead(bool x)
-{
- m_b_disable_read = x;
-}
-
-bool Socket::IsDisableRead()
-{
- return m_b_disable_read;
-}
-
-void Socket::SendBuf(const char *,size_t,int)
-{
-}
-
-void Socket::Send(const std::string&,int)
-{
-}
-
-void Socket::SetConnected(bool x)
-{
- m_connected = x;
-}
-
-bool Socket::IsConnected()
-{
- return m_connected;
-}
-
-void Socket::OnDisconnect()
-{
-}
-
-void Socket::SetLost()
-{
- m_bLost = true;
-}
-
-bool Socket::Lost()
-{
- return m_bLost;
-}
-
-void Socket::SetErasedByHandler(bool x)
-{
- m_b_erased_by_handler = x;
-}
-
-bool Socket::ErasedByHandler()
-{
- return m_b_erased_by_handler;
-}
-
-time_t Socket::TimeSinceClose()
-{
- return time(NULL) - m_tClose;
-}
-
-void Socket::SetClientRemoteAddress(SocketAddress& ad)
-{
- if (!ad.IsValid())
- {
- Handler().LogError(this, "SetClientRemoteAddress", 0, "remote address not valid", LOG_LEVEL_ERROR);
- }
- m_client_remote_address = ad.GetCopy();
-}
-
-std::auto_ptr Socket::GetClientRemoteAddress()
-{
- if (!m_client_remote_address.get())
- {
- Handler().LogError(this, "GetClientRemoteAddress", 0, "remote address not yet set", LOG_LEVEL_ERROR);
- }
- return m_client_remote_address -> GetCopy();
-}
-
-uint64_t Socket::GetBytesSent(bool)
-{
- return 0;
-}
-
-uint64_t Socket::GetBytesReceived(bool)
-{
- return 0;
-}
-
-#ifdef HAVE_OPENSSL
-void Socket::OnSSLConnect()
-{
-}
-
-void Socket::OnSSLAccept()
-{
-}
-
-bool Socket::SSLNegotiate()
-{
- return false;
-}
-
-bool Socket::IsSSL()
-{
- return m_b_enable_ssl;
-}
-
-void Socket::EnableSSL(bool x)
-{
- m_b_enable_ssl = x;
-}
-
-bool Socket::IsSSLNegotiate()
-{
- return m_b_ssl;
-}
-
-void Socket::SetSSLNegotiate(bool x)
-{
- m_b_ssl = x;
-}
-
-bool Socket::IsSSLServer()
-{
- return m_b_ssl_server;
-}
-
-void Socket::SetSSLServer(bool x)
-{
- m_b_ssl_server = x;
-}
-
-void Socket::OnSSLConnectFailed()
-{
-}
-
-void Socket::OnSSLAcceptFailed()
-{
-}
-#endif // HAVE_OPENSSL
-
-#ifdef ENABLE_POOL
-void Socket::CopyConnection(Socket *sock)
-{
- Attach( sock -> GetSocket() );
-#ifdef ENABLE_IPV6
- SetIpv6( sock -> IsIpv6() );
-#endif
- SetSocketType( sock -> GetSocketType() );
- SetSocketProtocol( sock -> GetSocketProtocol() );
-
- SetClientRemoteAddress( *sock -> GetClientRemoteAddress() );
- SetRemoteAddress( *sock -> GetRemoteSocketAddress() );
-}
-
-void Socket::SetIsClient()
-{
- m_bClient = true;
-}
-
-void Socket::SetSocketType(int x)
-{
- m_socket_type = x;
-}
-
-int Socket::GetSocketType()
-{
- return m_socket_type;
-}
-
-void Socket::SetSocketProtocol(const std::string& x)
-{
- m_socket_protocol = x;
-}
-
-const std::string& Socket::GetSocketProtocol()
-{
- return m_socket_protocol;
-}
-
-void Socket::SetRetain()
-{
- if (m_bClient) m_bRetain = true;
-}
-
-bool Socket::Retain()
-{
- return m_bRetain;
-}
-
-#endif // ENABLE_POOL
-
-#ifdef ENABLE_SOCKS4
-void Socket::OnSocks4Connect()
-{
- Handler().LogError(this, "OnSocks4Connect", 0, "Use with TcpSocket only");
-}
-
-void Socket::OnSocks4ConnectFailed()
-{
- Handler().LogError(this, "OnSocks4ConnectFailed", 0, "Use with TcpSocket only");
-}
-
-bool Socket::OnSocks4Read()
-{
- Handler().LogError(this, "OnSocks4Read", 0, "Use with TcpSocket only");
- return true;
-}
-
-void Socket::SetSocks4Host(const std::string& host)
-{
- Utility::u2ip(host, m_socks4_host);
-}
-
-bool Socket::Socks4()
-{
- return m_bSocks4;
-}
-
-void Socket::SetSocks4(bool x)
-{
- m_bSocks4 = x;
-}
-
-void Socket::SetSocks4Host(ipaddr_t a)
-{
- m_socks4_host = a;
-}
-
-void Socket::SetSocks4Port(port_t p)
-{
- m_socks4_port = p;
-}
-
-void Socket::SetSocks4Userid(const std::string& x)
-{
- m_socks4_userid = x;
-}
-
-ipaddr_t Socket::GetSocks4Host()
-{
- return m_socks4_host;
-}
-
-port_t Socket::GetSocks4Port()
-{
- return m_socks4_port;
-}
-
-const std::string& Socket::GetSocks4Userid()
-{
- return m_socks4_userid;
-}
-#endif // ENABLE_SOCKS4
-
-#ifdef ENABLE_DETACH
-bool Socket::Detach()
-{
- if (!DeleteByHandler())
- return false;
- if (m_pThread)
- return false;
- if (m_detached)
- return false;
- SetDetach();
- return true;
-}
-
-void Socket::DetachSocket()
-{
- SetDetached();
- m_pThread = new SocketThread(this);
- m_pThread -> SetRelease(true);
-}
-
-void Socket::OnDetached()
-{
-}
-
-void Socket::SetDetach(bool x)
-{
- Handler().AddList(m_socket, LIST_DETACH, x);
- m_detach = x;
-}
-
-bool Socket::IsDetach()
-{
- return m_detach;
-}
-
-void Socket::SetDetached(bool x)
-{
- m_detached = x;
-}
-
-const bool Socket::IsDetached() const
-{
- return m_detached;
-}
-
-void Socket::SetSlaveHandler(ISocketHandler *p)
-{
- m_slave_handler = p;
-}
-
-Socket::SocketThread::SocketThread(Socket *p)
-:Thread(false)
-,m_socket(p)
-{
- // Creator will release
-}
-
-Socket::SocketThread::~SocketThread()
-{
- if (IsRunning())
- {
- SetRelease(true);
- SetRunning(false);
-#ifdef _WIN32
- Sleep(1000);
-#else
- sleep(1);
-#endif
- }
-}
-
-void Socket::SocketThread::Run()
-{
- SocketHandler h;
- h.SetSlave();
- h.Add(m_socket);
- m_socket -> SetSlaveHandler(&h);
- m_socket -> OnDetached();
- while (h.GetCount() && IsRunning())
- {
- h.Select(0, 500000);
- }
- // m_socket now deleted oops
- // yeah oops m_socket delete its socket thread, that means this
- // so Socket will no longer delete its socket thread, instead we do this:
- SetDeleteOnExit();
-}
-#endif // ENABLE_DETACH
-
-#ifdef ENABLE_RESOLVER
-int Socket::Resolve(const std::string& host,port_t port)
-{
- return Handler().Resolve(this, host, port);
-}
-
-#ifdef ENABLE_IPV6
-int Socket::Resolve6(const std::string& host,port_t port)
-{
- return Handler().Resolve6(this, host, port);
-}
-#endif
-
-int Socket::Resolve(ipaddr_t a)
-{
- return Handler().Resolve(this, a);
-}
-
-#ifdef ENABLE_IPV6
-int Socket::Resolve(in6_addr& a)
-{
- return Handler().Resolve(this, a);
-}
-#endif
-
-void Socket::OnResolved(int,ipaddr_t,port_t)
-{
-}
-
-#ifdef ENABLE_IPV6
-void Socket::OnResolved(int,in6_addr&,port_t)
-{
-}
-#endif
-
-void Socket::OnReverseResolved(int,const std::string&)
-{
-}
-
-void Socket::OnResolveFailed(int)
-{
-}
-#endif // ENABLE_RESOLVER
-
-/* IP options */
-
-bool Socket::SetIpOptions(const void *p, socklen_t len)
-{
-#ifdef IP_OPTIONS
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_OPTIONS, (char *)p, len) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_OPTIONS)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "ip option not available", 0, "IP_OPTIONS", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-#ifdef IP_PKTINFO
-bool Socket::SetIpPktinfo(bool x)
-{
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_PKTINFO, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_PKTINFO)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-#ifdef IP_RECVTOS
-bool Socket::SetIpRecvTOS(bool x)
-{
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_RECVTOS, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RECVTOS)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-#ifdef IP_RECVTTL
-bool Socket::SetIpRecvTTL(bool x)
-{
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_RECVTTL, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RECVTTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-#ifdef IP_RECVOPTS
-bool Socket::SetIpRecvopts(bool x)
-{
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_RECVOPTS, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RECVOPTS)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-#ifdef IP_RETOPTS
-bool Socket::SetIpRetopts(bool x)
-{
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_RETOPTS, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RETOPTS)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-bool Socket::SetIpTOS(unsigned char tos)
-{
-#ifdef IP_TOS
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(tos)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TOS)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "ip option not available", 0, "IP_TOS", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-unsigned char Socket::IpTOS()
-{
- unsigned char tos = 0;
-#ifdef IP_TOS
- socklen_t len = sizeof(tos);
- if (getsockopt(GetSocket(), IPPROTO_IP, IP_TOS, (char *)&tos, &len) == -1)
- {
- Handler().LogError(this, "getsockopt(IPPROTO_IP, IP_TOS)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- }
-#else
- Handler().LogError(this, "ip option not available", 0, "IP_TOS", LOG_LEVEL_INFO);
-#endif
- return tos;
-}
-
-bool Socket::SetIpTTL(int ttl)
-{
-#ifdef IP_TTL
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_TTL, (char *)&ttl, sizeof(ttl)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "ip option not available", 0, "IP_TTL", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-int Socket::IpTTL()
-{
- int ttl = 0;
-#ifdef IP_TTL
- socklen_t len = sizeof(ttl);
- if (getsockopt(GetSocket(), IPPROTO_IP, IP_TTL, (char *)&ttl, &len) == -1)
- {
- Handler().LogError(this, "getsockopt(IPPROTO_IP, IP_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- }
-#else
- Handler().LogError(this, "ip option not available", 0, "IP_TTL", LOG_LEVEL_INFO);
-#endif
- return ttl;
-}
-
-bool Socket::SetIpHdrincl(bool x)
-{
-#ifdef IP_HDRINCL
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_HDRINCL, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_HDRINCL)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "ip option not available", 0, "IP_HDRINCL", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-#ifdef IP_RECVERR
-bool Socket::SetIpRecverr(bool x)
-{
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_RECVERR, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RECVERR)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-#ifdef IP_MTU_DISCOVER
-bool Socket::SetIpMtudiscover(bool x)
-{
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_MTU_DISCOVER, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MTU_DISCOVER)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-#ifdef IP_MTU
-int Socket::IpMtu()
-{
- int mtu = 0;
- socklen_t len = sizeof(mtu);
- if (getsockopt(GetSocket(), IPPROTO_IP, IP_MTU, (char *)&mtu, &len) == -1)
- {
- Handler().LogError(this, "getsockopt(IPPROTO_IP, IP_MTU)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- }
- return mtu;
-}
-#endif
-
-#ifdef IP_ROUTER_ALERT
-bool Socket::SetIpRouterAlert(bool x)
-{
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_ROUTER_ALERT, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_ROUTER_ALERT)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-bool Socket::SetIpMulticastTTL(int ttl)
-{
-#ifdef IP_MULTICAST_TTL
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, sizeof(ttl)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MULTICAST_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "ip option not available", 0, "IP_MULTICAST_TTL", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-int Socket::IpMulticastTTL()
-{
- int ttl = 0;
-#ifdef IP_MULTICAST_TTL
- socklen_t len = sizeof(ttl);
- if (getsockopt(GetSocket(), IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, &len) == -1)
- {
- Handler().LogError(this, "getsockopt(IPPROTO_IP, IP_MULTICAST_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- }
-#else
- Handler().LogError(this, "ip option not available", 0, "IP_MULTICAST_TTL", LOG_LEVEL_INFO);
-#endif
- return ttl;
-}
-
-bool Socket::SetMulticastLoop(bool x)
-{
-#ifdef IP_MULTICAST_LOOP
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MULTICAST_LOOP)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "ip option not available", 0, "IP_MULTICAST_LOOP", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-#ifdef LINUX
-bool Socket::IpAddMembership(struct ip_mreqn& ref)
-{
-#ifdef IP_ADD_MEMBERSHIP
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreqn)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "ip option not available", 0, "IP_ADD_MEMBERSHIP", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-#endif
-
-bool Socket::IpAddMembership(struct ip_mreq& ref)
-{
-#ifdef IP_ADD_MEMBERSHIP
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreq)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "ip option not available", 0, "IP_ADD_MEMBERSHIP", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-#ifdef LINUX
-bool Socket::IpDropMembership(struct ip_mreqn& ref)
-{
-#ifdef IP_DROP_MEMBERSHIP
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreqn)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_DROP_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "ip option not available", 0, "IP_DROP_MEMBERSHIP", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-#endif
-
-bool Socket::IpDropMembership(struct ip_mreq& ref)
-{
-#ifdef IP_DROP_MEMBERSHIP
- if (setsockopt(GetSocket(), IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreq)) == -1)
- {
- Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_DROP_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "ip option not available", 0, "IP_DROP_MEMBERSHIP", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-/* SOCKET options */
-
-bool Socket::SetSoReuseaddr(bool x)
-{
-#ifdef SO_REUSEADDR
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_REUSEADDR, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_REUSEADDR)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_REUSEADDR", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-bool Socket::SetSoKeepalive(bool x)
-{
-#ifdef SO_KEEPALIVE
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_KEEPALIVE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_KEEPALIVE", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-#ifdef SO_NOSIGPIPE
-bool Socket::SetSoNosigpipe(bool x)
-{
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_NOSIGPIPE, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_NOSIGPIPE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-bool Socket::SoAcceptconn()
-{
- int value = 0;
-#ifdef SO_ACCEPTCONN
- socklen_t len = sizeof(value);
- if (getsockopt(GetSocket(), SOL_SOCKET, SO_ACCEPTCONN, (char *)&value, &len) == -1)
- {
- Handler().LogError(this, "getsockopt(SOL_SOCKET, SO_ACCEPTCONN)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- }
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_ACCEPTCONN", LOG_LEVEL_INFO);
-#endif
- return value ? true : false;
-}
-
-#ifdef SO_BSDCOMPAT
-bool Socket::SetSoBsdcompat(bool x)
-{
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_BSDCOMPAT, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_BSDCOMPAT)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-#ifdef SO_BINDTODEVICE
-bool Socket::SetSoBindtodevice(const std::string& intf)
-{
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_BINDTODEVICE, (char *)intf.c_str(), intf.size()) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_BINDTODEVICE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-bool Socket::SetSoBroadcast(bool x)
-{
-#ifdef SO_BROADCAST
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_BROADCAST, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_BROADCAST)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_BROADCAST", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-bool Socket::SetSoDebug(bool x)
-{
-#ifdef SO_DEBUG
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_DEBUG, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_DEBUG)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_DEBUG", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-int Socket::SoError()
-{
- int value = 0;
-#ifdef SO_ERROR
- socklen_t len = sizeof(value);
- if (getsockopt(GetSocket(), SOL_SOCKET, SO_ERROR, (char *)&value, &len) == -1)
- {
- Handler().LogError(this, "getsockopt(SOL_SOCKET, SO_ERROR)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- }
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_ERROR", LOG_LEVEL_INFO);
-#endif
- return value;
-}
-
-bool Socket::SetSoDontroute(bool x)
-{
-#ifdef SO_DONTROUTE
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_DONTROUTE, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_DONTROUTE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_DONTROUTE", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-bool Socket::SetSoLinger(int onoff, int linger)
-{
-#ifdef SO_LINGER
- struct linger stl;
- stl.l_onoff = onoff;
- stl.l_linger = linger;
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_LINGER, (char *)&stl, sizeof(stl)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_LINGER)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_LINGER", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-bool Socket::SetSoOobinline(bool x)
-{
-#ifdef SO_OOBINLINE
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_OOBINLINE, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_OOBINLINE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_OOBINLINE", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-#ifdef SO_PASSCRED
-bool Socket::SetSoPasscred(bool x)
-{
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_PASSCRED, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_PASSCRED)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-#ifdef SO_PEERCRED
-bool Socket::SoPeercred(struct ucred& ucr)
-{
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_PEERCRED, (char *)&ucr, sizeof(ucr)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_PEERCRED)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-#ifdef SO_PRIORITY
-bool Socket::SetSoPriority(int x)
-{
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_PRIORITY, (char *)&x, sizeof(x)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_PRIORITY)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-bool Socket::SetSoRcvlowat(int x)
-{
-#ifdef SO_RCVLOWAT
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVLOWAT, (char *)&x, sizeof(x)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVLOWAT)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_RCVLOWAT", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-bool Socket::SetSoSndlowat(int x)
-{
-#ifdef SO_SNDLOWAT
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDLOWAT, (char *)&x, sizeof(x)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDLOWAT)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_SNDLOWAT", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-bool Socket::SetSoRcvtimeo(struct timeval& tv)
-{
-#ifdef SO_RCVTIMEO
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVTIMEO)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_RCVTIMEO", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-bool Socket::SetSoSndtimeo(struct timeval& tv)
-{
-#ifdef SO_SNDTIMEO
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(tv)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDTIMEO)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_SNDTIMEO", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-bool Socket::SetSoRcvbuf(int x)
-{
-#ifdef SO_RCVBUF
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVBUF, (char *)&x, sizeof(x)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_RCVBUF", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-int Socket::SoRcvbuf()
-{
- int value = 0;
-#ifdef SO_RCVBUF
- socklen_t len = sizeof(value);
- if (getsockopt(GetSocket(), SOL_SOCKET, SO_RCVBUF, (char *)&value, &len) == -1)
- {
- Handler().LogError(this, "getsockopt(SOL_SOCKET, SO_RCVBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- }
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_RCVBUF", LOG_LEVEL_INFO);
-#endif
- return value;
-}
-
-#ifdef SO_RCVBUFFORCE
-bool Socket::SetSoRcvbufforce(int x)
-{
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVBUFFORCE, (char *)&x, sizeof(x)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVBUFFORCE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-bool Socket::SetSoSndbuf(int x)
-{
-#ifdef SO_SNDBUF
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDBUF, (char *)&x, sizeof(x)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_SNDBUF", LOG_LEVEL_INFO);
- return false;
-#endif
-}
-
-int Socket::SoSndbuf()
-{
- int value = 0;
-#ifdef SO_SNDBUF
- socklen_t len = sizeof(value);
- if (getsockopt(GetSocket(), SOL_SOCKET, SO_SNDBUF, (char *)&value, &len) == -1)
- {
- Handler().LogError(this, "getsockopt(SOL_SOCKET, SO_SNDBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- }
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_SNDBUF", LOG_LEVEL_INFO);
-#endif
- return value;
-}
-
-#ifdef SO_SNDBUFFORCE
-bool Socket::SetSoSndbufforce(int x)
-{
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDBUFFORCE, (char *)&x, sizeof(x)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDBUFFORCE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-#ifdef SO_TIMESTAMP
-bool Socket::SetSoTimestamp(bool x)
-{
- int optval = x ? 1 : 0;
- if (setsockopt(GetSocket(), SOL_SOCKET, SO_TIMESTAMP, (char *)&optval, sizeof(optval)) == -1)
- {
- Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_TIMESTAMP)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- return false;
- }
- return true;
-}
-#endif
-
-int Socket::SoType()
-{
- int value = 0;
-#ifdef SO_TYPE
- socklen_t len = sizeof(value);
- if (getsockopt(GetSocket(), SOL_SOCKET, SO_TYPE, (char *)&value, &len) == -1)
- {
- Handler().LogError(this, "getsockopt(SOL_SOCKET, SO_TYPE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
- }
-#else
- Handler().LogError(this, "socket option not available", 0, "SO_TYPE", LOG_LEVEL_INFO);
-#endif
- return value;
-}
-
-#ifdef ENABLE_TRIGGERS
-void Socket::Subscribe(int id)
-{
- Handler().Subscribe(id, this);
-}
-
-void Socket::Unsubscribe(int id)
-{
- Handler().Unsubscribe(id, this);
-}
-
-void Socket::OnTrigger(int, const TriggerData&)
-{
-}
-
-void Socket::OnCancelled(int)
-{
-}
-#endif
-
-void Socket::SetTimeout(time_t secs)
-{
- if (!secs)
- {
- Handler().AddList(m_socket, LIST_TIMEOUT, false);
- return;
- }
- Handler().AddList(m_socket, LIST_TIMEOUT, true);
- m_timeout_start = time(NULL);
- m_timeout_limit = secs;
-}
-
-void Socket::OnTimeout()
-{
-}
-
-void Socket::OnConnectTimeout()
-{
-}
-
-bool Socket::Timeout(time_t tnow)
-{
- if (tnow - m_timeout_start > m_timeout_limit)
- return true;
- return false;
-}
-
-/** Returns local port number for bound socket file descriptor. */
-port_t Socket::GetSockPort()
-{
-#ifdef ENABLE_IPV6
-#ifdef IPPROTO_IPV6
- if (IsIpv6())
- {
- struct sockaddr_in6 sa;
- socklen_t sockaddr_length = sizeof(struct sockaddr_in6);
- if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1)
- memset(&sa, 0, sizeof(sa));
- return ntohs(sa.sin6_port);
- }
-#endif
-#endif
- struct sockaddr_in sa;
- socklen_t sockaddr_length = sizeof(struct sockaddr_in);
- if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1)
- memset(&sa, 0, sizeof(sa));
- return ntohs(sa.sin_port);
-}
-
-/** Returns local ipv4 address for bound socket file descriptor. */
-ipaddr_t Socket::GetSockIP4()
-{
-#ifdef ENABLE_IPV6
-#ifdef IPPROTO_IPV6
- if (IsIpv6())
- {
- return 0;
- }
-#endif
-#endif
- struct sockaddr_in sa;
- socklen_t sockaddr_length = sizeof(struct sockaddr_in);
- if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1)
- memset(&sa, 0, sizeof(sa));
- ipaddr_t a;
- memcpy(&a, &sa.sin_addr, 4);
- return a;
-}
-
-/** Returns local ipv4 address as text for bound socket file descriptor. */
-std::string Socket::GetSockAddress()
-{
-#ifdef ENABLE_IPV6
-#ifdef IPPROTO_IPV6
- if (IsIpv6())
- {
- return "";
- }
-#endif
-#endif
- struct sockaddr_in sa;
- socklen_t sockaddr_length = sizeof(struct sockaddr_in);
- if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1)
- memset(&sa, 0, sizeof(sa));
- Ipv4Address addr( sa );
- return addr.Convert();
-}
-
-#ifdef ENABLE_IPV6
-#ifdef IPPROTO_IPV6
-/** Returns local ipv6 address for bound socket file descriptor. */
-struct in6_addr Socket::GetSockIP6()
-{
- if (IsIpv6())
- {
- struct sockaddr_in6 sa;
- socklen_t sockaddr_length = sizeof(struct sockaddr_in6);
- if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1)
- memset(&sa, 0, sizeof(sa));
- return sa.sin6_addr;
- }
- struct in6_addr a;
- memset(&a, 0, sizeof(a));
- return a;
-}
-
-/** Returns local ipv6 address as text for bound socket file descriptor. */
-std::string Socket::GetSockAddress6()
-{
- if (IsIpv6())
- {
- struct sockaddr_in6 sa;
- socklen_t sockaddr_length = sizeof(struct sockaddr_in6);
- if (getsockname(GetSocket(), (struct sockaddr *)&sa, (socklen_t*)&sockaddr_length) == -1)
- memset(&sa, 0, sizeof(sa));
- Ipv6Address addr( sa );
- return addr.Convert();
- }
- return "";
-}
-#endif
-#endif
-
-#ifdef SOCKETS_NAMESPACE
-}
-#endif
-
-
diff --git a/dep/sockets/SocketHandler.cpp b/dep/sockets/SocketHandler.cpp
deleted file mode 100644
index acf71fb2ef..0000000000
--- a/dep/sockets/SocketHandler.cpp
+++ /dev/null
@@ -1,1377 +0,0 @@
-/** \file SocketHandler.cpp
- ** \date 2004-02-13
- ** \author grymse@alhem.net
-**/
-/*
-Copyright (C) 2004-2007 Anders Hedstrom
-
-This library is made available under the terms of the GNU GPL.
-
-If you would like to use this library in a closed-source application,
-a separate license agreement is available. For information about
-the closed-source license agreement for the C++ sockets library,
-please visit http://www.alhem.net/Sockets/license.html and/or
-email license@alhem.net.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#ifdef _WIN32
-#ifdef _MSC_VER
-#pragma warning(disable:4786)
-#endif
-#endif
-#include
-#include
-#include
-#include
-
-#include "SocketHandler.h"
-#include "UdpSocket.h"
-#include "ResolvSocket.h"
-#include "ResolvServer.h"
-#include "TcpSocket.h"
-#include "Mutex.h"
-#include "Utility.h"
-#include "SocketAddress.h"
-
-#ifdef SOCKETS_NAMESPACE
-namespace SOCKETS_NAMESPACE {
-#endif
-
-//#ifdef _DEBUG
-//#define DEB(x) x; fflush(stderr);
-//#else
-#define DEB(x)
-//#endif
-
-SocketHandler::SocketHandler(StdLog *p)
-:m_stdlog(p)
-,m_mutex(m_mutex)
-,m_b_use_mutex(false)
-,m_maxsock(0)
-,m_preverror(-1)
-,m_errcnt(0)
-,m_tlast(0)
-#ifdef ENABLE_SOCKS4
-,m_socks4_host(0)
-,m_socks4_port(0)
-,m_bTryDirect(false)
-#endif
-#ifdef ENABLE_RESOLVER
-,m_resolv_id(0)
-,m_resolver(NULL)
-#endif
-#ifdef ENABLE_POOL
-,m_b_enable_pool(false)
-#endif
-#ifdef ENABLE_TRIGGERS
-,m_next_trigger_id(0)
-#endif
-#ifdef ENABLE_DETACH
-,m_slave(false)
-#endif
-{
- FD_ZERO(&m_rfds);
- FD_ZERO(&m_wfds);
- FD_ZERO(&m_efds);
-}
-
-SocketHandler::SocketHandler(Mutex& mutex,StdLog *p)
-:m_stdlog(p)
-,m_mutex(mutex)
-,m_b_use_mutex(true)
-,m_maxsock(0)
-,m_preverror(-1)
-,m_errcnt(0)
-,m_tlast(0)
-#ifdef ENABLE_SOCKS4
-,m_socks4_host(0)
-,m_socks4_port(0)
-,m_bTryDirect(false)
-#endif
-#ifdef ENABLE_RESOLVER
-,m_resolv_id(0)
-,m_resolver(NULL)
-#endif
-#ifdef ENABLE_POOL
-,m_b_enable_pool(false)
-#endif
-#ifdef ENABLE_TRIGGERS
-,m_next_trigger_id(0)
-#endif
-#ifdef ENABLE_DETACH
-,m_slave(false)
-#endif
-{
- m_mutex.Lock();
- FD_ZERO(&m_rfds);
- FD_ZERO(&m_wfds);
- FD_ZERO(&m_efds);
-}
-
-SocketHandler::~SocketHandler()
-{
-#ifdef ENABLE_RESOLVER
- if (m_resolver)
- {
- m_resolver -> Quit();
- }
-#endif
- {
- while (m_sockets.size())
- {
-DEB( fprintf(stderr, "Emptying sockets list in SocketHandler destructor, %d instances\n", (int)m_sockets.size());)
- socket_m::iterator it = m_sockets.begin();
- Socket *p = it -> second;
- if (p)
- {
-DEB( fprintf(stderr, " fd %d\n", p -> GetSocket());)
- p -> Close();
-DEB( fprintf(stderr, " fd closed %d\n", p -> GetSocket());)
-// p -> OnDelete(); // hey, I turn this back on. what's the worst that could happen??!!
- // MinionSocket breaks, calling MinderHandler methods in OnDelete -
- // MinderHandler is already gone when that happens...
-
- // only delete socket when controlled
- // ie master sockethandler can delete non-detached sockets
- // and a slave sockethandler can only delete a detach socket
- if (p -> DeleteByHandler()
-#ifdef ENABLE_DETACH
- && !(m_slave ^ p -> IsDetached())
-#endif
- )
- {
- p -> SetErasedByHandler();
- delete p;
- }
- m_sockets.erase(it);
- }
- else
- {
- m_sockets.erase(it);
- }
-DEB( fprintf(stderr, "next\n");)
- }
-DEB( fprintf(stderr, "/Emptying sockets list in SocketHandler destructor, %d instances\n", (int)m_sockets.size());)
- }
-#ifdef ENABLE_RESOLVER
- if (m_resolver)
- {
- delete m_resolver;
- }
-#endif
- if (m_b_use_mutex)
- {
- m_mutex.Unlock();
- }
-}
-
-Mutex& SocketHandler::GetMutex() const
-{
- return m_mutex;
-}
-
-#ifdef ENABLE_DETACH
-void SocketHandler::SetSlave(bool x)
-{
- m_slave = x;
-}
-
-bool SocketHandler::IsSlave()
-{
- return m_slave;
-}
-#endif
-
-void SocketHandler::RegStdLog(StdLog *log)
-{
- m_stdlog = log;
-}
-
-void SocketHandler::LogError(Socket *p,const std::string& user_text,int err,const std::string& sys_err,loglevel_t t)
-{
- if (m_stdlog)
- {
- m_stdlog -> error(this, p, user_text, err, sys_err, t);
- }
-}
-
-void SocketHandler::Add(Socket *p)
-{
- if (p -> GetSocket() == INVALID_SOCKET)
- {
- LogError(p, "Add", -1, "Invalid socket", LOG_LEVEL_WARNING);
- if (p -> CloseAndDelete())
- {
- m_delete.push_back(p);
- }
- return;
- }
- if (m_add.find(p -> GetSocket()) != m_add.end())
- {
- LogError(p, "Add", (int)p -> GetSocket(), "Attempt to add socket already in add queue", LOG_LEVEL_FATAL);
- m_delete.push_back(p);
- return;
- }
- m_add[p -> GetSocket()] = p;
-}
-
-void SocketHandler::Get(SOCKET s,bool& r,bool& w,bool& e)
-{
- if (s >= 0)
- {
- r = FD_ISSET(s, &m_rfds) ? true : false;
- w = FD_ISSET(s, &m_wfds) ? true : false;
- e = FD_ISSET(s, &m_efds) ? true : false;
- }
-}
-
-void SocketHandler::Set(SOCKET s,bool bRead,bool bWrite,bool bException)
-{
-DEB( fprintf(stderr, "Set(%d, %s, %s, %s)\n", s, bRead ? "true" : "false", bWrite ? "true" : "false", bException ? "true" : "false");)
- if (s >= 0)
- {
- if (bRead)
- {
- if (!FD_ISSET(s, &m_rfds))
- {
- FD_SET(s, &m_rfds);
- }
- }
- else
- {
- FD_CLR(s, &m_rfds);
- }
- if (bWrite)
- {
- if (!FD_ISSET(s, &m_wfds))
- {
- FD_SET(s, &m_wfds);
- }
- }
- else
- {
- FD_CLR(s, &m_wfds);
- }
- if (bException)
- {
- if (!FD_ISSET(s, &m_efds))
- {
- FD_SET(s, &m_efds);
- }
- }
- else
- {
- FD_CLR(s, &m_efds);
- }
- }
-}
-
-int SocketHandler::Select(long sec,long usec)
-{
- struct timeval tv;
- tv.tv_sec = sec;
- tv.tv_usec = usec;
- return Select(&tv);
-}
-
-int SocketHandler::Select()
-{
- if (!m_fds_callonconnect.empty() ||
-#ifdef ENABLE_DETACH
- (!m_slave && !m_fds_detach.empty()) ||
-#endif
- !m_fds_timeout.empty() ||
- !m_fds_retry.empty() ||
- !m_fds_close.empty() ||
- !m_fds_erase.empty())
- {
- return Select(0, 200000);
- }
- return Select(NULL);
-}
-
-int SocketHandler::Select(struct timeval *tsel)
-{
- size_t ignore = 0;
- while (m_add.size() > ignore)
- {
- if (m_sockets.size() >= FD_SETSIZE)
- {
- LogError(NULL, "Select", (int)m_sockets.size(), "FD_SETSIZE reached", LOG_LEVEL_WARNING);
- break;
- }
- socket_m::iterator it = m_add.begin();
- SOCKET s = it -> first;
- Socket *p = it -> second;
-DEB( fprintf(stderr, "Trying to add fd %d, m_add.size() %d, ignore %d\n", (int)s, (int)m_add.size(), (int)ignore);)
- //
- if (m_sockets.find(p -> GetSocket()) != m_sockets.end())
- {
- LogError(p, "Add", (int)p -> GetSocket(), "Attempt to add socket already in controlled queue", LOG_LEVEL_FATAL);
- // %! it's a dup, don't add to delete queue, just ignore it
- m_delete.push_back(p);
- m_add.erase(it);
-// ignore++;
- continue;
- }
- if (!p -> CloseAndDelete())
- {
- StreamSocket *scp = dynamic_cast(p);
- if (scp && scp -> Connecting()) // 'Open' called before adding socket
- {
- Set(s,false,true);
- }
- else
- {
- TcpSocket *tcp = dynamic_cast(p);
- bool bWrite = tcp ? tcp -> GetOutputLength() != 0 : false;
- if (p -> IsDisableRead())
- {
- Set(s, false, bWrite);
- }
- else
- {
- Set(s, true, bWrite);
- }
- }
- m_maxsock = (s > m_maxsock) ? s : m_maxsock;
- }
- else
- {
- LogError(p, "Add", (int)p -> GetSocket(), "Trying to add socket with SetCloseAndDelete() true", LOG_LEVEL_WARNING);
- }
- // only add to m_fds (process fd_set events) if
- // slave handler and detached/detaching socket
- // master handler and non-detached socket
-#ifdef ENABLE_DETACH
- if (!(m_slave ^ p -> IsDetach()))
-#endif
- {
- m_fds.push_back(s);
- }
- m_sockets[s] = p;
- //
- m_add.erase(it);
- }
-#ifdef MACOSX
- fd_set rfds;
- fd_set wfds;
- fd_set efds;
- FD_COPY(&m_rfds, &rfds);
- FD_COPY(&m_wfds, &wfds);
- FD_COPY(&m_efds, &efds);
-#else
- fd_set rfds = m_rfds;
- fd_set wfds = m_wfds;
- fd_set efds = m_efds;
-#endif
- int n;
- if (m_b_use_mutex)
- {
- m_mutex.Unlock();
- n = select( (int)(m_maxsock + 1),&rfds,&wfds,&efds,tsel);
- m_mutex.Lock();
- }
- else
- {
- n = select( (int)(m_maxsock + 1),&rfds,&wfds,&efds,tsel);
- }
- if (n == -1)
- {
- /*
- EBADF An invalid file descriptor was given in one of the sets.
- EINTR A non blocked signal was caught.
- EINVAL n is negative. Or struct timeval contains bad time values (<0).
- ENOMEM select was unable to allocate memory for internal tables.
- */
- if (Errno != m_preverror || m_errcnt++ % 10000 == 0)
- {
- LogError(NULL, "select", Errno, StrError(Errno));
-DEB( fprintf(stderr, "m_maxsock: %d\n", m_maxsock);
- fprintf(stderr, "%s\n", Errno == EINVAL ? "EINVAL" :
- Errno == EINTR ? "EINTR" :
- Errno == EBADF ? "EBADF" :
- Errno == ENOMEM ? "ENOMEM" : "");
- // test bad fd
- for (SOCKET i = 0; i <= m_maxsock; i++)
- {
- bool t = false;
- FD_ZERO(&rfds);
- FD_ZERO(&wfds);
- FD_ZERO(&efds);
- if (FD_ISSET(i, &m_rfds))
- {
- FD_SET(i, &rfds);
- t = true;
- }
- if (FD_ISSET(i, &m_wfds))
- {
- FD_SET(i, &wfds);
- t = true;
- }
- if (FD_ISSET(i, &m_efds))
- {
- FD_SET(i, &efds);
- t = true;
- }
- if (t && m_sockets.find(i) == m_sockets.end())
- {
- fprintf(stderr, "Bad fd in fd_set: %d\n", i);
- }
- }
-) // DEB
- m_preverror = Errno;
- }
- /// \todo rebuild fd_set's from active sockets list (m_sockets) here
- }
- else
- if (!n)
- {
- m_preverror = -1;
- }
- else
- if (n > 0)
- {
- for (socket_v::iterator it2 = m_fds.begin(); it2 != m_fds.end() && n; it2++)
- {
- SOCKET i = *it2;
- if (FD_ISSET(i, &rfds))
- {
- socket_m::iterator itmp = m_sockets.find(i);
- if (itmp != m_sockets.end()) // found
- {
- Socket *p = itmp -> second;
- // new SSL negotiate method
-#ifdef HAVE_OPENSSL
- if (p -> IsSSLNegotiate())
- {
- p -> SSLNegotiate();
- }
- else
-#endif
- {
- p -> OnRead();
- }
- }
- else
- {
- LogError(NULL, "GetSocket/handler/1", (int)i, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING);
- }
- n--;
- }
- if (FD_ISSET(i, &wfds))
- {
- socket_m::iterator itmp = m_sockets.find(i);
- if (itmp != m_sockets.end()) // found
- {
- Socket *p = itmp -> second;
- // new SSL negotiate method
-#ifdef HAVE_OPENSSL
- if (p -> IsSSLNegotiate())
- {
- p -> SSLNegotiate();
- }
- else
-#endif
- {
- p -> OnWrite();
- }
- }
- else
- {
- LogError(NULL, "GetSocket/handler/2", (int)i, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING);
- }
- n--;
- }
- if (FD_ISSET(i, &efds))
- {
- socket_m::iterator itmp = m_sockets.find(i);
- if (itmp != m_sockets.end()) // found
- {
- Socket *p = itmp -> second;
- p -> OnException();
- }
- else
- {
- LogError(NULL, "GetSocket/handler/3", (int)i, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING);
- }
- n--;
- }
- } // m_fds loop
- m_preverror = -1;
- } // if (n > 0)
-
- // check CallOnConnect - EVENT
- if (!m_fds_callonconnect.empty())
- {
- socket_v tmp = m_fds_callonconnect;
- for (socket_v::iterator it = tmp.begin(); it != tmp.end(); it++)
- {
- Socket *p = NULL;
- {
- socket_m::iterator itmp = m_sockets.find(*it);
- if (itmp != m_sockets.end()) // found
- {
- p = itmp -> second;
- }
- else
- {
- LogError(NULL, "GetSocket/handler/4", (int)*it, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING);
- }
- }
- if (p)
- {
-// if (p -> CallOnConnect() && p -> Ready() )
- {
- p -> SetConnected(); // moved here from inside if (tcp) check below
-#ifdef HAVE_OPENSSL
- if (p -> IsSSL()) // SSL Enabled socket
- p -> OnSSLConnect();
- else
-#endif
-#ifdef ENABLE_SOCKS4
- if (p -> Socks4())
- p -> OnSocks4Connect();
- else
-#endif
- {
- TcpSocket *tcp = dynamic_cast(p);
- if (tcp)
- {
- if (tcp -> GetOutputLength())
- {
- p -> OnWrite();
- }
- }
-#ifdef ENABLE_RECONNECT
- if (tcp && tcp -> IsReconnect())
- p -> OnReconnect();
- else
-#endif
- {
-// LogError(p, "Calling OnConnect", 0, "Because CallOnConnect", LOG_LEVEL_INFO);
- p -> OnConnect();
- }
- }
-// p -> SetCallOnConnect( false );
- AddList(p -> GetSocket(), LIST_CALLONCONNECT, false);
- }
- }
- }
- }
-#ifdef ENABLE_DETACH
- // check detach of socket if master handler - EVENT
- if (!m_slave && !m_fds_detach.empty())
- {
- // %! why not using tmp list here??!?
- for (socket_v::iterator it = m_fds_detach.begin(); it != m_fds_detach.end(); it++)
- {
- Socket *p = NULL;
- {
- socket_m::iterator itmp = m_sockets.find(*it);
- if (itmp != m_sockets.end()) // found
- {
- p = itmp -> second;
- }
- else
- {
- LogError(NULL, "GetSocket/handler/5", (int)*it, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING);
- }
- }
- if (p)
- {
-// if (p -> IsDetach())
- {
- Set(p -> GetSocket(), false, false, false);
- // After DetachSocket(), all calls to Handler() will return a reference
- // to the new slave SocketHandler running in the new thread.
- p -> DetachSocket();
- // Adding the file descriptor to m_fds_erase will now also remove the
- // socket from the detach queue - tnx knightmad
- m_fds_erase.push_back(p -> GetSocket());
- }
- }
- }
- }
-#endif
- // check Connecting - connection timeout - conditional event
- if (m_fds_timeout.size())
- {
- time_t tnow = time(NULL);
- if (tnow != m_tlast)
- {
- socket_v tmp = m_fds_timeout;
-DEB( fprintf(stderr, "Checking %d socket(s) for timeout\n", tmp.size());)
- for (socket_v::iterator it = tmp.begin(); it != tmp.end(); it++)
- {
- Socket *p = NULL;
- {
- socket_m::iterator itmp = m_sockets.find(*it);
- if (itmp != m_sockets.end()) // found
- {
- p = itmp -> second;
- }
- else
- {
- itmp = m_add.find(*it);
- if (itmp != m_add.end())
- {
- p = itmp -> second;
- }
- else
- {
- LogError(NULL, "GetSocket/handler/6", (int)*it, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING);
- }
- }
- }
- if (p)
- {
- if (p -> Timeout(tnow))
- {
- StreamSocket *scp = dynamic_cast(p);
- if (scp && scp -> Connecting())
- p -> OnConnectTimeout();
- else
- p -> OnTimeout();
- p -> SetTimeout(0);
- }
- }
- }
- m_tlast = tnow;
- } // tnow != tlast
- }
- // check retry client connect - EVENT
- if (!m_fds_retry.empty())
- {
- socket_v tmp = m_fds_retry;
- for (socket_v::iterator it = tmp.begin(); it != tmp.end(); it++)
- {
- Socket *p = NULL;
- {
- socket_m::iterator itmp = m_sockets.find(*it);
- if (itmp != m_sockets.end()) // found
- {
- p = itmp -> second;
- }
- else
- {
- LogError(NULL, "GetSocket/handler/7", (int)*it, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING);
- }
- }
- if (p)
- {
-// if (p -> RetryClientConnect())
- {
- TcpSocket *tcp = dynamic_cast(p);
- SOCKET nn = *it; //(*it3).first;
- tcp -> SetRetryClientConnect(false);
-DEB( fprintf(stderr, "Close() before retry client connect\n");)
- p -> Close(); // removes from m_fds_retry
- std::auto_ptr ad = p -> GetClientRemoteAddress();
- if (ad.get())
- {
- tcp -> Open(*ad);
- }
- else
- {
- LogError(p, "RetryClientConnect", 0, "no address", LOG_LEVEL_ERROR);
- }
- Add(p);
- m_fds_erase.push_back(nn);
- }
- }
- }
- }
- // check close and delete - conditional event
- if (!m_fds_close.empty())
- {
- socket_v tmp = m_fds_close;
-DEB( fprintf(stderr, "m_fds_close.size() == %d\n", (int)m_fds_close.size());)
- for (socket_v::iterator it = tmp.begin(); it != tmp.end(); it++)
- {
- Socket *p = NULL;
- {
- socket_m::iterator itmp = m_sockets.find(*it);
- if (itmp != m_sockets.end()) // found
- {
- p = itmp -> second;
- }
- else
- {
- itmp = m_add.find(*it);
- if (itmp != m_add.end())
- {
- p = itmp -> second;
- }
- else
- {
- LogError(NULL, "GetSocket/handler/8", (int)*it, "Did not find expected socket using file descriptor", LOG_LEVEL_WARNING);
- }
- }
- }
- if (p)
- {
-// if (p -> CloseAndDelete() )
- {
- TcpSocket *tcp = dynamic_cast(p);
- // new graceful tcp - flush and close timeout 5s
- if (tcp && p -> IsConnected() && tcp -> GetFlushBeforeClose() &&
-#ifdef HAVE_OPENSSL
- !tcp -> IsSSL() &&
-#endif
- p -> TimeSinceClose() < 5)
- {
-DEB( fprintf(stderr, " close(1)\n");)
- if (tcp -> GetOutputLength())
- {
- LogError(p, "Closing", (int)tcp -> GetOutputLength(), "Sending all data before closing", LOG_LEVEL_INFO);
- }
- else // shutdown write when output buffer is empty
- if (!(tcp -> GetShutdown() & SHUT_WR))
- {
- SOCKET nn = *it;
- if (nn != INVALID_SOCKET && shutdown(nn, SHUT_WR) == -1)
- {
- LogError(p, "graceful shutdown", Errno, StrError(Errno), LOG_LEVEL_ERROR);
- }
- tcp -> SetShutdown(SHUT_WR);
- }
- }
- else
-#ifdef ENABLE_RECONNECT
- if (tcp && p -> IsConnected() && tcp -> Reconnect())
- {
- SOCKET nn = *it; //(*it3).first;
-DEB( fprintf(stderr, " close(2) fd %d\n", nn);)
- p -> SetCloseAndDelete(false);
- tcp -> SetIsReconnect();
- p -> SetConnected(false);
-DEB( fprintf(stderr, "Close() before reconnect\n");)
- p -> Close(); // dispose of old file descriptor (Open creates a new)
- p -> OnDisconnect();
- std::auto_ptr ad = p -> GetClientRemoteAddress();
- if (ad.get())
- {
- tcp -> Open(*ad);
- }
- else
- {
- LogError(p, "Reconnect", 0, "no address", LOG_LEVEL_ERROR);
- }
- tcp -> ResetConnectionRetries();
- Add(p);
- m_fds_erase.push_back(nn);
- }
- else
-#endif
- {
- SOCKET nn = *it; //(*it3).first;
-DEB( fprintf(stderr, " close(3) fd %d GetSocket() %d\n", nn, p -> GetSocket());)
- if (tcp && p -> IsConnected() && tcp -> GetOutputLength())
- {
- LogError(p, "Closing", (int)tcp -> GetOutputLength(), "Closing socket while data still left to send", LOG_LEVEL_WARNING);
- }
-#ifdef ENABLE_POOL
- if (p -> Retain() && !p -> Lost())
- {
- PoolSocket *p2 = new PoolSocket(*this, p);
- p2 -> SetDeleteByHandler();
- Add(p2);
- //
- p -> SetCloseAndDelete(false); // added - remove from m_fds_close
- }
- else
-#endif // ENABLE_POOL
- {
- Set(p -> GetSocket(),false,false,false);
-DEB( fprintf(stderr, "Close() before OnDelete\n");)
- p -> Close();
- }
- p -> OnDelete();
- if (p -> DeleteByHandler())
- {
- p -> SetErasedByHandler();
- }
- m_fds_erase.push_back(nn);
- }
- }
- }
- }
- }
-
- // check erased sockets
- bool check_max_fd = false;
- while (!m_fds_erase.empty())
- {
- socket_v::iterator it = m_fds_erase.begin();
- SOCKET nn = *it;
-#ifdef ENABLE_DETACH
- {
- for (socket_v::iterator it = m_fds_detach.begin(); it != m_fds_detach.end(); it++)
- {
- if (*it == nn)
- {
- m_fds_detach.erase(it);
- break;
- }
- }
- }
-#endif
- {
- for (socket_v::iterator it = m_fds.begin(); it != m_fds.end(); it++)
- {
- if (*it == nn)
- {
- m_fds.erase(it);
- break;
- }
- }
- }
- {
- socket_m::iterator it = m_sockets.find(nn);
- if (it != m_sockets.end())
- {
- Socket *p = it -> second;
- /* Sometimes a SocketThread class can finish its run before the master
- sockethandler gets here. In that case, the SocketThread has set the
- 'ErasedByHandler' flag on the socket which will make us end up with a
- double delete on the socket instance.
- The fix is to make sure that the master sockethandler only can delete
- non-detached sockets, and a slave sockethandler only can delete
- detach sockets. */
- if (p -> ErasedByHandler()
-#ifdef ENABLE_DETACH
- && !(m_slave ^ p -> IsDetached())
-#endif
- )
- {
-#ifdef ENABLE_TRIGGERS
- bool again = false;
- do
- {
- again = false;
- for (std::map::iterator it = m_trigger_src.begin(); it != m_trigger_src.end(); it++)
- {
- int id = it -> first;
- Socket *src = it -> second;
- if (src == p)
- {
- for (std::map::iterator it = m_trigger_dst[id].begin(); it != m_trigger_dst[id].end(); it++)
- {
- Socket *dst = it -> first;
- if (Valid(dst))
- {
- dst -> OnCancelled(id);
- }
- }
- m_trigger_src.erase(m_trigger_src.find(id));
- m_trigger_dst.erase(m_trigger_dst.find(id));
- again = true;
- break;
- }
- }
- } while (again);
-#endif
- delete p;
- }
- m_sockets.erase(it);
- }
- }
- m_fds_erase.erase(it);
- check_max_fd = true;
- }
- // calculate max file descriptor for select() call
- if (check_max_fd)
- {
- m_maxsock = 0;
- for (socket_v::iterator it = m_fds.begin(); it != m_fds.end(); it++)
- {
- SOCKET s = *it;
- m_maxsock = s > m_maxsock ? s : m_maxsock;
- }
- }
- // remove Add's that fizzed
- while (!m_delete.empty())
- {
- std::list::iterator it = m_delete.begin();
- Socket *p = *it;
- p -> OnDelete();
- m_delete.erase(it);
- if (p -> DeleteByHandler()
-#ifdef ENABLE_DETACH
- && !(m_slave ^ p -> IsDetached())
-#endif
- )
- {
- p -> SetErasedByHandler();
-#ifdef ENABLE_TRIGGERS
- bool again = false;
- do
- {
- again = false;
- for (std::map::iterator it = m_trigger_src.begin(); it != m_trigger_src.end(); it++)
- {
- int id = it -> first;
- Socket *src = it -> second;
- if (src == p)
- {
- for (std::map::iterator it = m_trigger_dst[id].begin(); it != m_trigger_dst[id].end(); it++)
- {
- Socket *dst = it -> first;
- if (Valid(dst))
- {
- dst -> OnCancelled(id);
- }
- }
- m_trigger_src.erase(m_trigger_src.find(id));
- m_trigger_dst.erase(m_trigger_dst.find(id));
- again = true;
- break;
- }
- }
- } while (again);
-#endif
- delete p;
- }
- }
- return n;
-}
-
-#ifdef ENABLE_RESOLVER
-bool SocketHandler::Resolving(Socket *p0)
-{
- std::map::iterator it = m_resolve_q.find(p0);
- return it != m_resolve_q.end();
-}
-#endif
-
-bool SocketHandler::Valid(Socket *p0)
-{
- for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++)
- {
- Socket *p = it -> second;
- if (p0 == p)
- return true;
- }
- return false;
-}
-
-bool SocketHandler::OkToAccept(Socket *)
-{
- return true;
-}
-
-size_t SocketHandler::GetCount()
-{
-/*
-printf(" m_sockets : %d\n", m_sockets.size());
-printf(" m_add : %d\n", m_add.size());
-printf(" m_delete : %d\n", m_delete.size());
-*/
- return m_sockets.size() + m_add.size() + m_delete.size();
-}
-
-#ifdef ENABLE_SOCKS4
-void SocketHandler::SetSocks4Host(ipaddr_t a)
-{
- m_socks4_host = a;
-}
-
-void SocketHandler::SetSocks4Host(const std::string& host)
-{
- Utility::u2ip(host, m_socks4_host);
-}
-
-void SocketHandler::SetSocks4Port(port_t port)
-{
- m_socks4_port = port;
-}
-
-void SocketHandler::SetSocks4Userid(const std::string& id)
-{
- m_socks4_userid = id;
-}
-#endif
-
-#ifdef ENABLE_RESOLVER
-int SocketHandler::Resolve(Socket *p,const std::string& host,port_t port)
-{
- // check cache
- ResolvSocket *resolv = new ResolvSocket(*this, p, host, port);
- resolv -> SetId(++m_resolv_id);
- resolv -> SetDeleteByHandler();
- ipaddr_t local;
- Utility::u2ip("127.0.0.1", local);
- if (!resolv -> Open(local, m_resolver_port))
- {
- LogError(resolv, "Resolve", -1, "Can't connect to local resolve server", LOG_LEVEL_FATAL);
- }
- Add(resolv);
- m_resolve_q[p] = true;
-DEB( fprintf(stderr, " *** Resolve '%s:%d' id#%d m_resolve_q size: %d p: %p\n", host.c_str(), port, resolv -> GetId(), m_resolve_q.size(), p);)
- return resolv -> GetId();
-}
-
-#ifdef ENABLE_IPV6
-int SocketHandler::Resolve6(Socket *p,const std::string& host,port_t port)
-{
- // check cache
- ResolvSocket *resolv = new ResolvSocket(*this, p, host, port, true);
- resolv -> SetId(++m_resolv_id);
- resolv -> SetDeleteByHandler();
- ipaddr_t local;
- Utility::u2ip("127.0.0.1", local);
- if (!resolv -> Open(local, m_resolver_port))
- {
- LogError(resolv, "Resolve", -1, "Can't connect to local resolve server", LOG_LEVEL_FATAL);
- }
- Add(resolv);
- m_resolve_q[p] = true;
- return resolv -> GetId();
-}
-#endif
-
-int SocketHandler::Resolve(Socket *p,ipaddr_t a)
-{
- // check cache
- ResolvSocket *resolv = new ResolvSocket(*this, p, a);
- resolv -> SetId(++m_resolv_id);
- resolv -> SetDeleteByHandler();
- ipaddr_t local;
- Utility::u2ip("127.0.0.1", local);
- if (!resolv -> Open(local, m_resolver_port))
- {
- LogError(resolv, "Resolve", -1, "Can't connect to local resolve server", LOG_LEVEL_FATAL);
- }
- Add(resolv);
- m_resolve_q[p] = true;
- return resolv -> GetId();
-}
-
-#ifdef ENABLE_IPV6
-int SocketHandler::Resolve(Socket *p,in6_addr& a)
-{
- // check cache
- ResolvSocket *resolv = new ResolvSocket(*this, p, a);
- resolv -> SetId(++m_resolv_id);
- resolv -> SetDeleteByHandler();
- ipaddr_t local;
- Utility::u2ip("127.0.0.1", local);
- if (!resolv -> Open(local, m_resolver_port))
- {
- LogError(resolv, "Resolve", -1, "Can't connect to local resolve server", LOG_LEVEL_FATAL);
- }
- Add(resolv);
- m_resolve_q[p] = true;
- return resolv -> GetId();
-}
-#endif
-
-void SocketHandler::EnableResolver(port_t port)
-{
- if (!m_resolver)
- {
- m_resolver_port = port;
- m_resolver = new ResolvServer(port);
- }
-}
-
-bool SocketHandler::ResolverReady()
-{
- return m_resolver ? m_resolver -> Ready() : false;
-}
-#endif // ENABLE_RESOLVER
-
-#ifdef ENABLE_SOCKS4
-void SocketHandler::SetSocks4TryDirect(bool x)
-{
- m_bTryDirect = x;
-}
-
-ipaddr_t SocketHandler::GetSocks4Host()
-{
- return m_socks4_host;
-}
-
-port_t SocketHandler::GetSocks4Port()
-{
- return m_socks4_port;
-}
-
-const std::string& SocketHandler::GetSocks4Userid()
-{
- return m_socks4_userid;
-}
-
-bool SocketHandler::Socks4TryDirect()
-{
- return m_bTryDirect;
-}
-#endif
-
-#ifdef ENABLE_RESOLVER
-bool SocketHandler::ResolverEnabled()
-{
- return m_resolver ? true : false;
-}
-
-port_t SocketHandler::GetResolverPort()
-{
- return m_resolver_port;
-}
-#endif // ENABLE_RESOLVER
-
-#ifdef ENABLE_POOL
-ISocketHandler::PoolSocket *SocketHandler::FindConnection(int type,const std::string& protocol,SocketAddress& ad)
-{
- for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end() && !m_sockets.empty(); it++)
- {
- PoolSocket *pools = dynamic_cast(it -> second);
- if (pools)
- {
- if (pools -> GetSocketType() == type &&
- pools -> GetSocketProtocol() == protocol &&
-// %! pools -> GetClientRemoteAddress() &&
- *pools -> GetClientRemoteAddress() == ad)
- {
- m_sockets.erase(it);
- pools -> SetRetain(); // avoid Close in Socket destructor
- return pools; // Caller is responsible that this socket is deleted
- }
- }
- }
- return NULL;
-}
-
-void SocketHandler::EnablePool(bool x)
-{
- m_b_enable_pool = x;
-}
-
-bool SocketHandler::PoolEnabled()
-{
- return m_b_enable_pool;
-}
-#endif
-
-void SocketHandler::Remove(Socket *p)
-{
-#ifdef ENABLE_RESOLVER
- std::map::iterator it4 = m_resolve_q.find(p);
- if (it4 != m_resolve_q.end())
- m_resolve_q.erase(it4);
-#endif
- if (p -> ErasedByHandler())
- {
- return;
- }
- for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++)
- {
- if (it -> second == p)
- {
- LogError(p, "Remove", -1, "Socket destructor called while still in use", LOG_LEVEL_WARNING);
- m_sockets.erase(it);
- return;
- }
- }
- for (socket_m::iterator it2 = m_add.begin(); it2 != m_add.end(); it2++)
- {
- if ((*it2).second == p)
- {
- LogError(p, "Remove", -2, "Socket destructor called while still in use", LOG_LEVEL_WARNING);
- m_add.erase(it2);
- return;
- }
- }
- for (std::list::iterator it3 = m_delete.begin(); it3 != m_delete.end(); it3++)
- {
- if (*it3 == p)
- {
- LogError(p, "Remove", -3, "Socket destructor called while still in use", LOG_LEVEL_WARNING);
- m_delete.erase(it3);
- return;
- }
- }
-}
-
-void SocketHandler::CheckSanity()
-{
- CheckList(m_fds, "active sockets"); // active sockets
- CheckList(m_fds_erase, "sockets to be erased"); // should always be empty anyway
- CheckList(m_fds_callonconnect, "checklist CallOnConnect");
-#ifdef ENABLE_DETACH
- CheckList(m_fds_detach, "checklist Detach");
-#endif
- CheckList(m_fds_timeout, "checklist Timeout");
- CheckList(m_fds_retry, "checklist retry client connect");
- CheckList(m_fds_close, "checklist close and delete");
-}
-
-void SocketHandler::CheckList(socket_v& ref,const std::string& listname)
-{
- for (socket_v::iterator it = ref.begin(); it != ref.end(); it++)
- {
- SOCKET s = *it;
- if (m_sockets.find(s) != m_sockets.end())
- continue;
- if (m_add.find(s) != m_add.end())
- continue;
- bool found = false;
- for (std::list::iterator it = m_delete.begin(); it != m_delete.end(); it++)
- {
- Socket *p = *it;
- if (p -> GetSocket() == s)
- {
- found = true;
- break;
- }
- }
- if (!found)
- {
- fprintf(stderr, "CheckList failed for \"%s\": fd %d\n", listname.c_str(), s);
- }
- }
-}
-
-void SocketHandler::AddList(SOCKET s,list_t which_one,bool add)
-{
- if (s == INVALID_SOCKET)
- {
-DEB( fprintf(stderr, "AddList: invalid_socket\n");)
- return;
- }
- socket_v& ref =
- (which_one == LIST_CALLONCONNECT) ? m_fds_callonconnect :
-#ifdef ENABLE_DETACH
- (which_one == LIST_DETACH) ? m_fds_detach :
-#endif
- (which_one == LIST_TIMEOUT) ? m_fds_timeout :
- (which_one == LIST_RETRY) ? m_fds_retry :
- (which_one == LIST_CLOSE) ? m_fds_close : m_fds_close;
- if (add)
- {
-#ifdef ENABLE_DETACH
-DEB( fprintf(stderr, "AddList; %5d: %s: %s\n", s, (which_one == LIST_CALLONCONNECT) ? "CallOnConnect" :
- (which_one == LIST_DETACH) ? "Detach" :
- (which_one == LIST_TIMEOUT) ? "Timeout" :
- (which_one == LIST_RETRY) ? "Retry" :
- (which_one == LIST_CLOSE) ? "Close" : "",
- add ? "Add" : "Remove");)
-#else
-DEB( fprintf(stderr, "AddList; %5d: %s: %s\n", s, (which_one == LIST_CALLONCONNECT) ? "CallOnConnect" :
- (which_one == LIST_TIMEOUT) ? "Timeout" :
- (which_one == LIST_RETRY) ? "Retry" :
- (which_one == LIST_CLOSE) ? "Close" : "",
- add ? "Add" : "Remove");)
-#endif
- }
- if (add)
- {
- for (socket_v::iterator it = ref.begin(); it != ref.end(); it++)
- {
- if (*it == s) // already there
- {
- return;
- }
- }
- ref.push_back(s);
- return;
- }
- // remove
- for (socket_v::iterator it = ref.begin(); it != ref.end(); it++)
- {
- if (*it == s)
- {
- ref.erase(it);
- break;
- }
- }
-//DEB( fprintf(stderr, "/AddList\n");)
-}
-
-#ifdef ENABLE_TRIGGERS
-int SocketHandler::TriggerID(Socket *src)
-{
- int id = m_next_trigger_id++;
- m_trigger_src[id] = src;
- return id;
-}
-
-bool SocketHandler::Subscribe(int id, Socket *dst)
-{
- if (m_trigger_src.find(id) != m_trigger_src.end())
- {
- std::map::iterator it = m_trigger_dst[id].find(dst);
- if (it != m_trigger_dst[id].end())
- {
- m_trigger_dst[id][dst] = true;
- return true;
- }
- LogError(dst, "Subscribe", id, "Already subscribed", LOG_LEVEL_INFO);
- return false;
- }
- LogError(dst, "Subscribe", id, "Trigger id not found", LOG_LEVEL_INFO);
- return false;
-}
-
-bool SocketHandler::Unsubscribe(int id, Socket *dst)
-{
- if (m_trigger_src.find(id) != m_trigger_src.end())
- {
- std::map::iterator it = m_trigger_dst[id].find(dst);
- if (it != m_trigger_dst[id].end())
- {
- m_trigger_dst[id].erase(it);
- return true;
- }
- LogError(dst, "Unsubscribe", id, "Not subscribed", LOG_LEVEL_INFO);
- return false;
- }
- LogError(dst, "Unsubscribe", id, "Trigger id not found", LOG_LEVEL_INFO);
- return false;
-}
-
-void SocketHandler::Trigger(int id, Socket::TriggerData& data, bool erase)
-{
- if (m_trigger_src.find(id) != m_trigger_src.end())
- {
- data.SetSource( m_trigger_src[id] );
- for (std::map::iterator it = m_trigger_dst[id].begin(); it != m_trigger_dst[id].end(); it++)
- {
- Socket *dst = it -> first;
- if (Valid(dst))
- {
- dst -> OnTrigger(id, data);
- }
- }
- if (erase)
- {
- m_trigger_src.erase(m_trigger_src.find(id));
- m_trigger_dst.erase(m_trigger_dst.find(id));
- }
- }
- else
- {
- LogError(NULL, "Trigger", id, "Trigger id not found", LOG_LEVEL_INFO);
- }
-}
-#endif // ENABLE_TRIGGERS
-
-#ifdef SOCKETS_NAMESPACE
-}
-#endif
-
-
diff --git a/dep/sockets/StdoutLog.cpp b/dep/sockets/StdoutLog.cpp
deleted file mode 100644
index e745a6d335..0000000000
--- a/dep/sockets/StdoutLog.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/** \file StdoutLog.cpp
- ** \date 2004-06-01
- ** \author grymse@alhem.net
-**/
-/*
-Copyright (C) 2004-2007 Anders Hedstrom
-
-This library is made available under the terms of the GNU GPL.
-
-If you would like to use this library in a closed-source application,
-a separate license agreement is available. For information about
-the closed-source license agreement for the C++ sockets library,
-please visit http://www.alhem.net/Sockets/license.html and/or
-email license@alhem.net.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#include
-
-#ifdef _MSC_VER
-#pragma warning(disable:4786)
-#endif
-
-#include
-
-#include "ISocketHandler.h"
-#include "Socket.h"
-#include "StdoutLog.h"
-
-#ifdef SOCKETS_NAMESPACE
-namespace SOCKETS_NAMESPACE {
-#endif
-
-
-void StdoutLog::error(ISocketHandler *,Socket *sock,const std::string& call,int err,const std::string& sys_err,loglevel_t lvl)
-{
- time_t t = time(NULL);
- struct tm tp;
-#ifdef _WIN32
- memcpy(&tp, localtime(&t), sizeof(tp));
-#else
- localtime_r(&t, &tp);
-#endif
- std::string level;
-
- switch (lvl)
- {
- case LOG_LEVEL_WARNING:
- level = "Warning";
- break;
- case LOG_LEVEL_ERROR:
- level = "Error";
- break;
- case LOG_LEVEL_FATAL:
- level = "Fatal";
- break;
- case LOG_LEVEL_INFO:
- level = "Info";
- break;
- }
- if (sock)
- {
- printf("%d-%02d-%02d %02d:%02d:%02d :: fd %d :: %s: %d %s (%s)\n",
- tp.tm_year + 1900,
- tp.tm_mon + 1,
- tp.tm_mday,
- tp.tm_hour,tp.tm_min,tp.tm_sec,
- sock -> GetSocket(),
- call.c_str(),err,sys_err.c_str(),level.c_str());
- }
- else
- {
- printf("%d-%02d-%02d %02d:%02d:%02d :: %s: %d %s (%s)\n",
- tp.tm_year + 1900,
- tp.tm_mon + 1,
- tp.tm_mday,
- tp.tm_hour,tp.tm_min,tp.tm_sec,
- call.c_str(),err,sys_err.c_str(),level.c_str());
- }
-}
-
-#ifdef SOCKETS_NAMESPACE
-}
-#endif
-
-
diff --git a/dep/sockets/StreamSocket.cpp b/dep/sockets/StreamSocket.cpp
deleted file mode 100644
index 009abadad8..0000000000
--- a/dep/sockets/StreamSocket.cpp
+++ /dev/null
@@ -1,145 +0,0 @@
-#include "StreamSocket.h"
-#include "ISocketHandler.h"
-
-#ifdef SOCKETS_NAMESPACE
-namespace SOCKETS_NAMESPACE {
-#endif
-
-StreamSocket::StreamSocket(ISocketHandler& h) : Socket(h)
-,m_bConnecting(false)
-,m_connect_timeout(5)
-,m_flush_before_close(true)
-,m_connection_retry(0)
-,m_retries(0)
-,m_call_on_connect(false)
-,m_b_retry_connect(false)
-,m_line_protocol(false)
-,m_shutdown(0)
-{
-}
-
-StreamSocket::~StreamSocket()
-{
-}
-
-void StreamSocket::SetConnecting(bool x)
-{
- if (x != m_bConnecting)
- {
- m_bConnecting = x;
- if (x)
- {
- SetTimeout( GetConnectTimeout() );
- }
- else
- {
- SetTimeout( 0 );
- }
- }
-}
-
-bool StreamSocket::Connecting()
-{
- return m_bConnecting;
-}
-
-bool StreamSocket::Ready()
-{
- if (GetSocket() != INVALID_SOCKET && !Connecting() && !CloseAndDelete())
- return true;
- return false;
-}
-
-void StreamSocket::SetConnectTimeout(int x)
-{
- m_connect_timeout = x;
-}
-
-int StreamSocket::GetConnectTimeout()
-{
- return m_connect_timeout;
-}
-
-void StreamSocket::SetFlushBeforeClose(bool x)
-{
- m_flush_before_close = x;
-}
-
-bool StreamSocket::GetFlushBeforeClose()
-{
- return m_flush_before_close;
-}
-
-int StreamSocket::GetConnectionRetry()
-{
- return m_connection_retry;
-}
-
-void StreamSocket::SetConnectionRetry(int x)
-{
- m_connection_retry = x;
-}
-
-int StreamSocket::GetConnectionRetries()
-{
- return m_retries;
-}
-
-void StreamSocket::IncreaseConnectionRetries()
-{
- m_retries++;
-}
-
-void StreamSocket::ResetConnectionRetries()
-{
- m_retries = 0;
-}
-
-void StreamSocket::SetCallOnConnect(bool x)
-{
- Handler().AddList(GetSocket(), LIST_CALLONCONNECT, x);
- m_call_on_connect = x;
-}
-
-bool StreamSocket::CallOnConnect()
-{
- return m_call_on_connect;
-}
-
-void StreamSocket::SetRetryClientConnect(bool x)
-{
- Handler().AddList(GetSocket(), LIST_RETRY, x);
- m_b_retry_connect = x;
-}
-
-bool StreamSocket::RetryClientConnect()
-{
- return m_b_retry_connect;
-}
-
-void StreamSocket::SetLineProtocol(bool x)
-{
- m_line_protocol = x;
-}
-
-bool StreamSocket::LineProtocol()
-{
- return m_line_protocol;
-}
-
-void StreamSocket::SetShutdown(int x)
-{
- m_shutdown = x;
-}
-
-int StreamSocket::GetShutdown()
-{
- return m_shutdown;
-}
-
-
-#ifdef SOCKETS_NAMESPACE
-} // namespace SOCKETS_NAMESPACE {
-#endif
-
-
diff --git a/dep/sockets/TcpSocket.cpp b/dep/sockets/TcpSocket.cpp
deleted file mode 100644
index 5f067b5312..0000000000
--- a/dep/sockets/TcpSocket.cpp
+++ /dev/null
@@ -1,1681 +0,0 @@
-/** \file TcpSocket.cpp
- ** \date 2004-02-13
- ** \author grymse@alhem.net
-**/
-/*
-Copyright (C) 2004-2007 Anders Hedstrom
-
-This library is made available under the terms of the GNU GPL.
-
-If you would like to use this library in a closed-source application,
-a separate license agreement is available. For information about
-the closed-source license agreement for the C++ sockets library,
-please visit http://www.alhem.net/Sockets/license.html and/or
-email license@alhem.net.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#ifdef _WIN32
-#ifdef _MSC_VER
-#pragma warning(disable:4786)
-#endif
-#include
-#else
-#include
-#endif
-#include "ISocketHandler.h"
-#include
-#include
-#include
-#include
-#ifdef HAVE_OPENSSL
-#include
-#include
-#endif
-#include