Removing old native socket stuff which is now unused (replaced by asio calls).

This commit is contained in:
lotodore
2009-06-16 22:00:07 +00:00
parent d45e41c963
commit 31dadd6fa2
19 changed files with 38 additions and 598 deletions
+1 -1
View File
@@ -21,7 +21,7 @@
ClientContext::ClientContext()
: m_protocol(0), m_addrFamily(AF_INET), m_useServerList(false), m_serverPort(0),
: m_sctp(false), m_addrFamily(AF_INET), m_useServerList(false), m_serverPort(0),
m_hasSubscribedLobbyMsg(true)
{
}
+2 -2
View File
@@ -96,7 +96,7 @@ ClientThread::Init(
ClientContext &context = GetContext();
context.SetProtocol(sctp ? SOCKET_IPPROTO_SCTP : 0);
context.SetSctp(sctp);
context.SetAddrFamily(ipv6 ? AF_INET6 : AF_INET);
context.SetServerAddr(serverAddress);
context.SetServerListUrl(serverListUrl);
@@ -839,7 +839,7 @@ ClientThread::CreateContextSession()
{
}
if (!validSocket)
throw ClientException(__FILE__, __LINE__, ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO());
throw ClientException(__FILE__, __LINE__, ERR_SOCK_CREATION_FAILED, 0);
}
ClientState &
-36
View File
@@ -1,36 +0,0 @@
/***************************************************************************
* Copyright (C) 2007 by Lothar May *
* *
* 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 <net/connectdata.h>
#include <memory>
using namespace std;
ConnectData::ConnectData()
: m_sockfd(INVALID_SOCKET), m_peerAddrSize(sizeof(struct sockaddr_storage))
{
memset(&m_peerAddr, 0, sizeof(m_peerAddr));
}
ConnectData::~ConnectData()
{
if (m_sockfd != INVALID_SOCKET)
CLOSESOCKET(m_sockfd);
}
+3 -2
View File
@@ -29,6 +29,7 @@
using namespace std;
#define IRC_WAIT_TERMINATION_MSEC 500
#define IRC_RECV_TIMEOUT_MSEC 50
#define IRC_MAX_RENAME_TRIES 5
#define IRC_MIN_RECONNECT_INTERVAL_SEC 60
@@ -415,12 +416,12 @@ IrcThread::IrcMain()
FD_ZERO(&readSet);
FD_ZERO(&writeSet);
timeout.tv_sec = 0;
timeout.tv_usec = RECV_TIMEOUT_MSEC * 1000;
timeout.tv_usec = IRC_RECV_TIMEOUT_MSEC * 1000;
irc_add_select_descriptors(s, &readSet, &writeSet, &maxfd);
int selectResult = select(maxfd + 1, &readSet, &writeSet, 0, &timeout);
if (!IS_VALID_SELECT(selectResult))
if (selectResult == -1)
{
GetCallback().SignalIrcError(ERR_IRC_SELECT_FAILED);
break;
+2
View File
@@ -17,6 +17,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <boost/asio.hpp>
#include <net/netpacket.h>
#include <net/netexception.h>
#include <net/socket_msg.h>
-1
View File
@@ -20,7 +20,6 @@
#include <net/socket_helper.h>
#include <net/servermanager.h>
#include <net/ircthread.h>
#include <net/connectdata.h>
#include <net/serverlobbythread.h>
#include <net/serveraccepthelper.h>
#include <net/serverexception.h>
-70
View File
@@ -80,76 +80,6 @@ SessionManager::RemoveSession(SessionId session)
m_sessionMap.erase(session);
}
SessionWrapper
SessionManager::Select(unsigned timeoutMsec)
{
SessionWrapper retSession;
SOCKET maxSock = INVALID_SOCKET;
fd_set rdset;
FD_ZERO(&rdset);
{
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::iterator i = m_sessionMap.begin();
SessionMap::iterator end = m_sessionMap.end();
while (i != end)
{
// Collect all sockets.
SOCKET tmpSock = i->second.sessionData->GetSocket();
FD_SET(tmpSock, &rdset);
if (tmpSock > maxSock || maxSock == INVALID_SOCKET)
maxSock = tmpSock;
// Check if a packet is available.
if (!i->second.sessionData->GetReceiveBuffer().receivedPackets.empty())
{
retSession = i->second;
break;
}
++i;
}
}
if (!retSession.sessionData.get())
{
if (maxSock == INVALID_SOCKET)
{
Thread::Msleep(timeoutMsec); // just sleep if there is no session
}
else
{
// wait for data
struct timeval timeout;
timeout.tv_sec = timeoutMsec / 1000;
timeout.tv_usec = (timeoutMsec % 1000) * 1000;
int selectResult = select(maxSock + 1, &rdset, NULL, NULL, &timeout);
if (!IS_VALID_SELECT(selectResult))
{
throw ServerException(__FILE__, __LINE__, ERR_SOCK_SELECT_FAILED, SOCKET_ERRNO());
}
if (selectResult > 0) // one (or more) of the sockets is readable
{
// Check which socket is readable, return the first.
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::iterator i = m_sessionMap.begin();
SessionMap::iterator end = m_sessionMap.end();
while (i != end)
{
if (FD_ISSET(i->second.sessionData->GetSocket(), &rdset))
{
retSession = i->second;
break;
}
++i;
}
}
}
}
return retSession;
}
SessionWrapper
SessionManager::GetSessionById(SessionId id) const
{
+18 -14
View File
@@ -17,15 +17,16 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/version.hpp> // solve compatibility issues
#include <net/socket_startup.h>
#include <net/socket_helper.h>
#include <core/openssl_wrapper.h>
#ifdef PKTH_USE_GNUTLS
#include <gcrypt.h>
#include <boost/thread.hpp>
#include <boost/version.hpp> // solve compatibility issues
extern "C" {
@@ -68,7 +69,7 @@ extern "C" {
#endif // PKTH_USE_GNUTLS
bool
internal_socket_startup()
socket_startup()
{
#ifdef PKTH_USE_GNUTLS
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_boost);
@@ -78,7 +79,7 @@ internal_socket_startup()
}
void
internal_socket_cleanup()
socket_cleanup()
{
}
@@ -87,11 +88,12 @@ bool
socket_has_sctp()
{
#ifdef IPPROTO_SCTP
SOCKET test = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
boost::asio::detail::socket_type test = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
if (test == INVALID_SOCKET)
if (test == boost::asio::detail::invalid_socket)
return false;
CLOSESOCKET(test);
boost::system::error_code ec;
boost::asio::detail::socket_ops::close(test, ec);
return true;
#else
return false;
@@ -101,11 +103,12 @@ socket_has_sctp()
bool
socket_has_ipv6()
{
SOCKET test = socket(AF_INET6, SOCK_STREAM, 0);
boost::asio::detail::socket_type test = socket(AF_INET6, SOCK_STREAM, 0);
if (test == INVALID_SOCKET)
if (test == boost::asio::detail::invalid_socket)
return false;
CLOSESOCKET(test);
boost::system::error_code ec;
boost::asio::detail::socket_ops::close(test, ec);
return true;
}
@@ -113,14 +116,15 @@ bool
socket_has_dual_stack()
{
bool retVal = false;
SOCKET test = socket(AF_INET6, SOCK_STREAM, 0);
boost::asio::detail::socket_type test = socket(AF_INET6, SOCK_STREAM, 0);
if (test != INVALID_SOCKET)
if (test != boost::asio::detail::invalid_socket)
{
int ipv6only = 0;
if (setsockopt(test, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, sizeof(ipv6only)) == 0)
retVal = true;
CLOSESOCKET(test);
boost::system::error_code ec;
boost::asio::detail::socket_ops::close(test, ec);
}
return retVal;
}
+4 -3
View File
@@ -27,6 +27,7 @@
using namespace std;
#define CURL_RECV_TIMEOUT_MSEC 50
TransferHelper::TransferHelper()
{
@@ -91,15 +92,15 @@ TransferHelper::Process()
FD_ZERO(&exceptSet);
timeout.tv_sec = 0;
timeout.tv_usec = RECV_TIMEOUT_MSEC * 1000;
timeout.tv_usec = CURL_RECV_TIMEOUT_MSEC * 1000;
curl_multi_fdset(m_data->curlMultiHandle, &readSet, &writeSet, &exceptSet, &maxfd);
if (maxfd >= 0)
{
int selectResult = select(maxfd+1, &readSet, &writeSet, &exceptSet, &timeout);
if (!IS_VALID_SELECT(selectResult))
throw NetException(__FILE__, __LINE__, ERR_SOCK_TRANSFER_SELECT_FAILED, SOCKET_ERRNO());
if (selectResult == -1)
throw NetException(__FILE__, __LINE__, ERR_SOCK_TRANSFER_SELECT_FAILED, 0);
}
}
else