aboutsummaryrefslogtreecommitdiff
path: root/dep/src/sockets
diff options
context:
space:
mode:
Diffstat (limited to 'dep/src/sockets')
-rw-r--r--dep/src/sockets/Base64.cpp12
-rw-r--r--dep/src/sockets/Exception.cpp5
-rw-r--r--dep/src/sockets/Ipv4Address.cpp4
-rw-r--r--dep/src/sockets/Ipv6Address.cpp6
-rw-r--r--dep/src/sockets/Lock.cpp7
-rw-r--r--dep/src/sockets/Mutex.cpp7
-rw-r--r--dep/src/sockets/Parse.cpp32
-rw-r--r--dep/src/sockets/ResolvServer.cpp10
-rw-r--r--dep/src/sockets/ResolvSocket.cpp10
-rw-r--r--dep/src/sockets/Socket.cpp13
-rw-r--r--dep/src/sockets/SocketHandler.cpp11
-rw-r--r--dep/src/sockets/StdoutLog.cpp10
-rw-r--r--dep/src/sockets/StreamSocket.cpp1
-rw-r--r--dep/src/sockets/TcpSocket.cpp24
-rw-r--r--dep/src/sockets/Thread.cpp8
-rw-r--r--dep/src/sockets/UdpSocket.cpp16
-rw-r--r--dep/src/sockets/Utility.cpp10
-rw-r--r--dep/src/sockets/socket_include.cpp7
18 files changed, 193 insertions, 0 deletions
diff --git a/dep/src/sockets/Base64.cpp b/dep/src/sockets/Base64.cpp
index a6a6992798c..f7f12f5edff 100644
--- a/dep/src/sockets/Base64.cpp
+++ b/dep/src/sockets/Base64.cpp
@@ -4,25 +4,31 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
+
This library is made available under the terms of the GNU GPL.
+
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
+
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
+
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Base64.h"
+
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
@@ -32,6 +38,7 @@ const char *Base64::bstr =
"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,
@@ -52,6 +59,7 @@ void Base64::encode(FILE *fil, std::string& output, bool add_crlf)
size_t i = 0;
size_t o = 0;
char input[4];
+
output = "";
remain = fread(input,1,3,fil);
while (remain > 0)
@@ -92,6 +100,7 @@ void Base64::encode(const char* input,size_t l,std::string& output, bool add_crl
{
size_t i = 0;
size_t o = 0;
+
output = "";
while (i < l)
{
@@ -126,6 +135,7 @@ void Base64::encode(const unsigned char* input,size_t l,std::string& output,bool
{
size_t i = 0;
size_t o = 0;
+
output = "";
while (i < l)
{
@@ -160,6 +170,7 @@ void Base64::decode(const std::string& input,std::string& output)
{
size_t i = 0;
size_t l = input.size();
+
output = "";
while (i < l)
{
@@ -192,6 +203,7 @@ 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))
diff --git a/dep/src/sockets/Exception.cpp b/dep/src/sockets/Exception.cpp
index 9c8a7fe3b58..4d79aeef813 100644
--- a/dep/src/sockets/Exception.cpp
+++ b/dep/src/sockets/Exception.cpp
@@ -5,14 +5,17 @@
**/
/*
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.
@@ -21,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#pragma warning(disable:4786)
#endif
#include "Exception.h"
+
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
@@ -38,3 +42,4 @@ const std::string Exception::ToString() const
} // namespace SOCKETS_NAMESPACE {
#endif
+
diff --git a/dep/src/sockets/Ipv4Address.cpp b/dep/src/sockets/Ipv4Address.cpp
index edd56ece048..03935038951 100644
--- a/dep/src/sockets/Ipv4Address.cpp
+++ b/dep/src/sockets/Ipv4Address.cpp
@@ -5,14 +5,17 @@
**/
/*
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.
@@ -186,3 +189,4 @@ std::string Ipv4Address::Reverse()
} // namespace SOCKETS_NAMESPACE {
#endif
+
diff --git a/dep/src/sockets/Ipv6Address.cpp b/dep/src/sockets/Ipv6Address.cpp
index 3e6d4b09805..3208b5098fa 100644
--- a/dep/src/sockets/Ipv6Address.cpp
+++ b/dep/src/sockets/Ipv6Address.cpp
@@ -5,26 +5,31 @@
**/
/*
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 <netdb.h>
#endif
#ifdef IPPROTO_IPV6
+
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
@@ -239,3 +244,4 @@ std::string Ipv6Address::Reverse()
#endif // IPPROTO_IPV6
#endif // ENABLE_IPV6
+
diff --git a/dep/src/sockets/Lock.cpp b/dep/src/sockets/Lock.cpp
index 1abda3bebeb..b75664cfbdc 100644
--- a/dep/src/sockets/Lock.cpp
+++ b/dep/src/sockets/Lock.cpp
@@ -4,26 +4,32 @@
**/
/*
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
@@ -43,3 +49,4 @@ Lock::~Lock()
}
#endif
+
diff --git a/dep/src/sockets/Mutex.cpp b/dep/src/sockets/Mutex.cpp
index 4f6ec98b5e1..681e85cee5b 100644
--- a/dep/src/sockets/Mutex.cpp
+++ b/dep/src/sockets/Mutex.cpp
@@ -4,25 +4,31 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
+
This library is made available under the terms of the GNU GPL.
+
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
+
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
+
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Mutex.h"
+
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
@@ -68,3 +74,4 @@ void Mutex::Unlock()
}
#endif
+
diff --git a/dep/src/sockets/Parse.cpp b/dep/src/sockets/Parse.cpp
index b0d51e187c8..2967859f23d 100644
--- a/dep/src/sockets/Parse.cpp
+++ b/dep/src/sockets/Parse.cpp
@@ -2,28 +2,35 @@
**
** 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 <stdlib.h>
#include <string.h>
+
#include "Parse.h"
#ifdef SOCKETS_NAMESPACE
@@ -31,6 +38,7 @@ namespace SOCKETS_NAMESPACE {
#endif
/* implementation of class Parse */
+
Parse::Parse()
:pa_the_str("")
,pa_splits("")
@@ -43,6 +51,7 @@ Parse::Parse()
,pa_quote(false)
{
}
+
Parse::Parse(const std::string&s)
:pa_the_str(s)
,pa_splits("")
@@ -55,6 +64,7 @@ Parse::Parse(const std::string&s)
,pa_quote(false)
{
}
+
Parse::Parse(const std::string&s,const std::string&sp)
:pa_the_str(s)
,pa_splits(sp)
@@ -67,6 +77,7 @@ Parse::Parse(const std::string&s,const std::string&sp)
,pa_quote(false)
{
}
+
Parse::Parse(const std::string&s,const std::string&sp,short /*nospace*/)
:pa_the_str(s)
,pa_splits(sp)
@@ -83,7 +94,9 @@ Parse::Parse(const std::string&s,const std::string&sp,short /*nospace*/)
Parse::~Parse()
{
}
+
#define C ((pa_the_ptr<pa_the_str.size()) ? pa_the_str[pa_the_ptr] : 0)
+
short Parse::issplit(const char c)
{
for (size_t i = 0; i < pa_splits.size(); i++)
@@ -91,9 +104,11 @@ short Parse::issplit(const char c)
return 1;
return 0;
}
+
void Parse::getsplit()
{
size_t x;
+
if (C == '=')
{
x = pa_the_ptr++;
@@ -109,12 +124,14 @@ void Parse::getsplit()
pa_the_ptr++;
pa_ord = (x < pa_the_str.size()) ? pa_the_str.substr(x,pa_the_ptr - x) : "";
}
+
std::string Parse::getword()
{
size_t x;
int disabled = 0;
int quote = 0;
int rem = 0;
+
if (pa_nospace)
{
while (C && issplit(C))
@@ -190,15 +207,18 @@ std::string Parse::getword()
}
return pa_ord;
}
+
void Parse::getword(std::string&s)
{
s = Parse::getword();
}
+
void Parse::getsplit(std::string&s)
{
Parse::getsplit();
s = pa_ord;
}
+
void Parse::getword(std::string&s,std::string&fill,int l)
{
Parse::getword();
@@ -207,6 +227,7 @@ void Parse::getword(std::string&s,std::string&fill,int l)
s += fill;
s += pa_ord;
}
+
std::string Parse::getrest()
{
std::string s;
@@ -215,24 +236,29 @@ std::string Parse::getrest()
s = (pa_the_ptr < pa_the_str.size()) ? pa_the_str.substr(pa_the_ptr) : "";
return s;
}
+
void Parse::getrest(std::string&s)
{
while (C && (C == ' ' || C == 9 || issplit(C)))
pa_the_ptr++;
s = (pa_the_ptr < pa_the_str.size()) ? pa_the_str.substr(pa_the_ptr) : "";
}
+
long Parse::getvalue()
{
Parse::getword();
return atol(pa_ord.c_str());
}
+
void Parse::setbreak(const char c)
{
pa_breakchar = c;
}
+
int Parse::getwordlen()
{
size_t x,y = pa_the_ptr,len;
+
if (C == pa_breakchar && pa_breakchar)
{
x = pa_the_ptr++;
@@ -250,19 +276,23 @@ int Parse::getwordlen()
pa_the_ptr = y;
return (int)len;
}
+
int Parse::getrestlen()
{
size_t y = pa_the_ptr;
size_t len;
+
while (C && (C == ' ' || C == 9 || issplit(C)))
pa_the_ptr++;
len = strlen(pa_the_str.c_str() + pa_the_ptr);
pa_the_ptr = y;
return (int)len;
}
+
void Parse::getline()
{
size_t x;
+
x = pa_the_ptr;
while (C && C != 13 && C != 10)
pa_the_ptr++;
@@ -272,11 +302,13 @@ void Parse::getline()
if (C == 10)
pa_the_ptr++;
}
+
void Parse::getline(std::string&s)
{
getline();
s = pa_ord;
}
+
/* end of implementation of class Parse */
/***************************************************/
#ifdef SOCKETS_NAMESPACE
diff --git a/dep/src/sockets/ResolvServer.cpp b/dep/src/sockets/ResolvServer.cpp
index 07a27c6fc06..3c8a7de6bc0 100644
--- a/dep/src/sockets/ResolvServer.cpp
+++ b/dep/src/sockets/ResolvServer.cpp
@@ -4,20 +4,25 @@
**/
/*
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.
@@ -31,6 +36,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ListenSocket.h"
#include "ResolvSocket.h"
#include "SocketHandler.h"
+
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
@@ -52,11 +58,13 @@ void ResolvServer::Run()
// StdoutLog log;
SocketHandler h;
ListenSocket<ResolvSocket> l(h);
+
if (l.Bind("127.0.0.1", m_port))
{
return;
}
h.Add(&l);
+
m_ready = true;
while (!m_quit && IsRunning() )
{
@@ -78,5 +86,7 @@ bool ResolvServer::Ready()
#ifdef SOCKETS_NAMESPACE
}
#endif
+
#endif // ENABLE_RESOLVER
+
diff --git a/dep/src/sockets/ResolvSocket.cpp b/dep/src/sockets/ResolvSocket.cpp
index f97be03cd06..636de276426 100644
--- a/dep/src/sockets/ResolvSocket.cpp
+++ b/dep/src/sockets/ResolvSocket.cpp
@@ -4,20 +4,25 @@
**/
/*
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.
@@ -37,9 +42,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ISocketHandler.h"
#include "Lock.h"
#include "Mutex.h"
+
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
+
//#ifdef _DEBUG
//#define DEB(x) x
//#else
@@ -170,6 +177,7 @@ DEB(fprintf(stderr, " *** Returning cache for [%s][%s] = '%s'\n", m_query.c_str(
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;
@@ -412,5 +420,7 @@ DEB(fprintf(stderr, " *** Update cache for [%s][%s] = '%s'\n", m_query.c_str(),
#ifdef SOCKETS_NAMESPACE
}
#endif
+
#endif // ENABLE_RESOLVER
+
diff --git a/dep/src/sockets/Socket.cpp b/dep/src/sockets/Socket.cpp
index a0544c37db5..f53cd27621e 100644
--- a/dep/src/sockets/Socket.cpp
+++ b/dep/src/sockets/Socket.cpp
@@ -4,20 +4,25 @@
**/
/*
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.
@@ -34,19 +39,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
#include <ctype.h>
#include <fcntl.h>
+
#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
@@ -175,6 +184,7 @@ 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;
@@ -193,6 +203,7 @@ SOCKET Socket::CreateSocket(int af,int type, const std::string& protocol)
}
}
int protno = p ? p -> p_proto : 0;
+
s = socket(af, type, protno);
if (s == INVALID_SOCKET)
{
@@ -614,6 +625,7 @@ void Socket::CopyConnection(Socket *sock)
#endif
SetSocketType( sock -> GetSocketType() );
SetSocketProtocol( sock -> GetSocketProtocol() );
+
SetClientRemoteAddress( *sock -> GetClientRemoteAddress() );
SetRemoteAddress( *sock -> GetRemoteSocketAddress() );
}
@@ -1711,3 +1723,4 @@ std::string Socket::GetSockAddress6()
}
#endif
+
diff --git a/dep/src/sockets/SocketHandler.cpp b/dep/src/sockets/SocketHandler.cpp
index ff6d4b36d64..acf71fb2efa 100644
--- a/dep/src/sockets/SocketHandler.cpp
+++ b/dep/src/sockets/SocketHandler.cpp
@@ -4,20 +4,25 @@
**/
/*
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.
@@ -31,6 +36,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <stdio.h>
#include <errno.h>
#include <cstdio>
+
#include "SocketHandler.h"
#include "UdpSocket.h"
#include "ResolvSocket.h"
@@ -39,6 +45,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Mutex.h"
#include "Utility.h"
#include "SocketAddress.h"
+
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
@@ -136,6 +143,7 @@ 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
@@ -505,6 +513,7 @@ DEB( fprintf(stderr, "m_maxsock: %d\n", m_maxsock);
} // m_fds loop
m_preverror = -1;
} // if (n > 0)
+
// check CallOnConnect - EVENT
if (!m_fds_callonconnect.empty())
{
@@ -802,6 +811,7 @@ DEB( fprintf(stderr, "Close() before OnDelete\n");)
}
}
}
+
// check erased sockets
bool check_max_fd = false;
while (!m_fds_erase.empty())
@@ -1364,3 +1374,4 @@ void SocketHandler::Trigger(int id, Socket::TriggerData& data, bool erase)
}
#endif
+
diff --git a/dep/src/sockets/StdoutLog.cpp b/dep/src/sockets/StdoutLog.cpp
index 44743c729f7..e745a6d3358 100644
--- a/dep/src/sockets/StdoutLog.cpp
+++ b/dep/src/sockets/StdoutLog.cpp
@@ -4,32 +4,41 @@
**/
/*
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 <stdio.h>
+
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
+
#include <cstdio>
+
#include "ISocketHandler.h"
#include "Socket.h"
#include "StdoutLog.h"
+
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
@@ -45,6 +54,7 @@ void StdoutLog::error(ISocketHandler *,Socket *sock,const std::string& call,int
localtime_r(&t, &tp);
#endif
std::string level;
+
switch (lvl)
{
case LOG_LEVEL_WARNING:
diff --git a/dep/src/sockets/StreamSocket.cpp b/dep/src/sockets/StreamSocket.cpp
index 84bcf7bdca1..009abadad8f 100644
--- a/dep/src/sockets/StreamSocket.cpp
+++ b/dep/src/sockets/StreamSocket.cpp
@@ -142,3 +142,4 @@ int StreamSocket::GetShutdown()
} // namespace SOCKETS_NAMESPACE {
#endif
+
diff --git a/dep/src/sockets/TcpSocket.cpp b/dep/src/sockets/TcpSocket.cpp
index 902f631a6af..5f067b53124 100644
--- a/dep/src/sockets/TcpSocket.cpp
+++ b/dep/src/sockets/TcpSocket.cpp
@@ -4,20 +4,25 @@
**/
/*
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.
@@ -41,12 +46,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
#include <map>
#include <cstdio>
+
#include "TcpSocket.h"
#include "Utility.h"
#include "Ipv4Address.h"
#include "Ipv6Address.h"
#include "Mutex.h"
#include "IFile.h"
+
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
@@ -206,6 +213,7 @@ bool TcpSocket::Open(SocketAddress& ad,SocketAddress& bind_ad,bool skip_socks)
{
CopyConnection( pools );
delete pools;
+
SetIsClient();
SetCallOnConnect(); // ISocketHandler must call OnConnect
Handler().LogError(this, "SetCallOnConnect", 0, "Found pooled connection", LOG_LEVEL_INFO);
@@ -297,6 +305,7 @@ bool TcpSocket::Open(SocketAddress& ad,SocketAddress& bind_ad,bool skip_socks)
Attach(s);
SetCallOnConnect(); // ISocketHandler must call OnConnect
}
+
// 'true' means connected or connecting(not yet connected)
// 'false' means something failed
return true; //!Connecting();
@@ -606,6 +615,7 @@ void TcpSocket::OnWrite()
if (Connecting())
{
int err = SoError();
+
// don't reset connecting flag on error here, we want the OnConnectFailed timeout later on
if (!err) // ok
{
@@ -616,6 +626,7 @@ void TcpSocket::OnWrite()
}
Handler().LogError(this, "tcp: connect failed", err, StrError(err), LOG_LEVEL_FATAL);
Set(false, false); // no more monitoring because connection failed
+
// failed
#ifdef ENABLE_SOCKS4
if (Socks4())
@@ -643,6 +654,7 @@ void TcpSocket::OnWrite()
// try send next block in buffer
// if full block is sent, repeat
// if all blocks are sent, reset m_wfds
+
bool repeat = false;
size_t sz = m_transfer_limit ? GetOutputLength() : 0;
do
@@ -671,10 +683,12 @@ void TcpSocket::OnWrite()
}
}
} while (repeat);
+
if (m_transfer_limit && sz > m_transfer_limit && GetOutputLength() < m_transfer_limit)
{
OnTransferLimit();
}
+
// check output buffer set, set/reset m_wfds accordingly
{
bool br;
@@ -828,6 +842,7 @@ void TcpSocket::SendBuf(const char *buf,size_t len,int)
// else
// try_send
// if any data is unsent, buffer it and set m_wfds
+
// check output buffer set, set/reset m_wfds accordingly
{
bool br;
@@ -934,6 +949,7 @@ bool TcpSocket::OnSocks4Read()
{
ibuf.Read( (char *)&m_socks4_dstip, 4);
SetSocks4(false);
+
switch (m_socks4_cd)
{
case 90:
@@ -1201,11 +1217,13 @@ void TcpSocket::InitializeContext(const std::string& context,const std::string&
{
m_ssl_ctx = server_contexts[context];
}
+
/* Load our keys and certificates*/
if (!(SSL_CTX_use_certificate_file(m_ssl_ctx, keyfile.c_str(), SSL_FILETYPE_PEM)))
{
Handler().LogError(this, "TcpSocket InitializeContext", 0, "Couldn't read certificate file " + keyfile, LOG_LEVEL_FATAL);
}
+
m_password = password;
SSL_CTX_set_default_passwd_cb(m_ssl_ctx, SSL_password_cb);
SSL_CTX_set_default_passwd_cb_userdata(m_ssl_ctx, this);
@@ -1234,11 +1252,13 @@ void TcpSocket::InitializeContext(const std::string& context,const std::string&
{
m_ssl_ctx = server_contexts[context];
}
+
/* Load our keys and certificates*/
if (!(SSL_CTX_use_certificate_file(m_ssl_ctx, certfile.c_str(), SSL_FILETYPE_PEM)))
{
Handler().LogError(this, "TcpSocket InitializeContext", 0, "Couldn't read certificate file " + keyfile, LOG_LEVEL_FATAL);
}
+
m_password = password;
SSL_CTX_set_default_passwd_cb(m_ssl_ctx, SSL_password_cb);
SSL_CTX_set_default_passwd_cb_userdata(m_ssl_ctx, this);
@@ -1307,6 +1327,7 @@ SSL_CTX *TcpSocket::GetSslContext()
Handler().LogError(this, "GetSslContext", 0, "SSL Context is NULL; check InitSSLServer/InitSSLClient", LOG_LEVEL_WARNING);
return m_ssl_ctx;
}
+
SSL *TcpSocket::GetSsl()
{
if (!m_ssl)
@@ -1491,6 +1512,7 @@ bool TcpSocket::CircularBuffer::Read(char *s,size_t l)
}
return true;
}
+
bool TcpSocket::CircularBuffer::SoftRead(char *s, size_t l)
{
if (l > m_q)
@@ -1515,6 +1537,7 @@ bool TcpSocket::CircularBuffer::SoftRead(char *s, size_t l)
}
return true;
}
+
bool TcpSocket::CircularBuffer::Remove(size_t l)
{
return Read(NULL, l);
@@ -1655,3 +1678,4 @@ void TcpSocket::OnTransferLimit()
}
#endif
+
diff --git a/dep/src/sockets/Thread.cpp b/dep/src/sockets/Thread.cpp
index 713c02b3f52..773e9f214fa 100644
--- a/dep/src/sockets/Thread.cpp
+++ b/dep/src/sockets/Thread.cpp
@@ -4,20 +4,25 @@
**/
/*
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.
@@ -29,6 +34,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#else
#include <unistd.h>
#endif
+
#include "Thread.h"
#ifdef SOCKETS_NAMESPACE
@@ -47,6 +53,7 @@ Thread::Thread(bool release)
m_thread = (HANDLE)_beginthreadex(NULL, 0, &StartThread, this, 0, &m_dwThreadId);
#else
pthread_attr_t attr;
+
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
if (pthread_create(&m_thread,&attr, StartThread,this) == -1)
@@ -81,6 +88,7 @@ Thread::~Thread()
threadfunc_t STDPREFIX Thread::StartThread(threadparam_t zz)
{
Thread *p = (Thread *)zz;
+
while (p -> m_running && !p -> m_release)
{
#ifdef _WIN32
diff --git a/dep/src/sockets/UdpSocket.cpp b/dep/src/sockets/UdpSocket.cpp
index f1abe54a1a8..a3d393c00e2 100644
--- a/dep/src/sockets/UdpSocket.cpp
+++ b/dep/src/sockets/UdpSocket.cpp
@@ -4,20 +4,25 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
+
This library is made available under the terms of the GNU GPL.
+
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
+
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
+
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -30,6 +35,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#else
#include <errno.h>
#endif
+
#include "ISocketHandler.h"
#include "UdpSocket.h"
#include "Utility.h"
@@ -367,12 +373,15 @@ int UdpSocket::ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen
} cmsg_un;
struct cmsghdr *cmsg;
struct timeval *tv;
+
vec[0].iov_base = ioBuf;
vec[0].iov_len = inBufSize;
+
memset(&msg, 0, sizeof(msg));
memset(from, 0, fromlen);
memset(ioBuf, 0, inBufSize);
memset(&cmsg_un, 0, sizeof(cmsg_un));
+
msg.msg_name = (caddr_t)from;
msg.msg_namelen = fromlen;
msg.msg_iov = vec;
@@ -380,10 +389,14 @@ int UdpSocket::ReadTS(char *ioBuf, int inBufSize, struct sockaddr *from, socklen
msg.msg_control = cmsg_un.data;
msg.msg_controllen = sizeof(cmsg_un.data);
msg.msg_flags = 0;
+
// Original version - for reference only
//int n = recvfrom(GetSocket(), m_ibuf, m_ibufsz, 0, (struct sockaddr *)&sa, &sa_len);
+
int n = recvmsg(GetSocket(), &msg, MSG_DONTWAIT);
+
// now ioBuf will contain the data, as if we used recvfrom
+
// Now get the time
if(n != -1 && msg.msg_controllen >= sizeof(struct cmsghdr) && !(msg.msg_flags & MSG_CTRUNC))
{
@@ -521,6 +534,7 @@ void UdpSocket::SetBroadcast(bool b)
{
int one = 1;
int zero = 0;
+
if (GetSocket() == INVALID_SOCKET)
{
CreateConnection();
@@ -545,6 +559,7 @@ bool UdpSocket::IsBroadcast()
{
int is_broadcast = 0;
socklen_t size;
+
if (GetSocket() == INVALID_SOCKET)
{
CreateConnection();
@@ -572,6 +587,7 @@ int UdpSocket::GetMulticastTTL()
{
int ttl = 0;
socklen_t size = sizeof(int);
+
if (GetSocket() == INVALID_SOCKET)
{
CreateConnection();
diff --git a/dep/src/sockets/Utility.cpp b/dep/src/sockets/Utility.cpp
index 70dbfc83595..7c093fc0832 100644
--- a/dep/src/sockets/Utility.cpp
+++ b/dep/src/sockets/Utility.cpp
@@ -4,20 +4,25 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
+
This library is made available under the terms of the GNU GPL.
+
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
+
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
+
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -35,6 +40,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <pthread.h>
#endif
#include <map>
+
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
@@ -341,6 +347,7 @@ int Utility::in6_addr_compare(in6_addr a,in6_addr b)
void Utility::ResolveLocal()
{
char h[256];
+
// get local hostname and translate into ip-address
*h = 0;
gethostname(h,255);
@@ -940,11 +947,14 @@ unsigned long Utility::Rng::Get()
}
unsigned long s = TWIST(m_tmp, TWIST_LEN - 1, 0);
m_tmp[TWIST_LEN - 1] = m_tmp[TWIST_IA - 1] ^ (s >> 1) ^ MAGIC_TWIST(s);
+
m_value = 0;
}
return val;
}
+
#ifdef SOCKETS_NAMESPACE
}
#endif
+
diff --git a/dep/src/sockets/socket_include.cpp b/dep/src/sockets/socket_include.cpp
index 171b5c39a23..290602c1b52 100644
--- a/dep/src/sockets/socket_include.cpp
+++ b/dep/src/sockets/socket_include.cpp
@@ -4,25 +4,31 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
+
This library is made available under the terms of the GNU GPL.
+
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
+
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
+
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
+
// only to be included in win32 projects
const char *StrError(int x)
{
@@ -72,6 +78,7 @@ static char tmp[100];
case 11002: return "Nonauthoritative host not found.";
case 11003: return "This is a nonrecoverable error.";
case 11004: return "Valid name, no data record of requested type.";
+
default:
break;
}