2007-11-16 15:24:25 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
* 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/clientcontext.h>
|
2009-01-11 20:12:26 +00:00
|
|
|
#include <net/senderthread.h>
|
2009-01-07 21:52:16 +00:00
|
|
|
|
2009-01-11 20:12:26 +00:00
|
|
|
class ClientSenderCallback : public SenderCallback, public SessionDataCallback
|
2009-01-07 21:52:16 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ClientSenderCallback() {}
|
|
|
|
|
virtual ~ClientSenderCallback() {}
|
|
|
|
|
|
|
|
|
|
virtual void SignalNetError(SessionId /*session*/, int /*errorID*/, int /*osErrorID*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-11 20:12:26 +00:00
|
|
|
virtual void SignalSessionTerminated(unsigned /*session*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-07 21:52:16 +00:00
|
|
|
private:
|
|
|
|
|
};
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
ClientContext::ClientContext()
|
2008-05-16 20:42:46 +00:00
|
|
|
: m_protocol(0), m_addrFamily(AF_INET), m_useServerList(false), m_serverPort(0),
|
|
|
|
|
m_hasSubscribedLobbyMsg(true)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
bzero(&m_clientSockaddr, sizeof(m_clientSockaddr));
|
2009-01-07 21:52:16 +00:00
|
|
|
m_senderCallback.reset(new ClientSenderCallback());
|
2009-01-11 20:12:26 +00:00
|
|
|
m_senderThread.reset(new SenderThread(*m_senderCallback));
|
|
|
|
|
m_senderThread->Start();
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientContext::~ClientContext()
|
|
|
|
|
{
|
2009-01-11 20:12:26 +00:00
|
|
|
m_senderThread->SignalStop();
|
|
|
|
|
m_senderThread->WaitStop();
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SOCKET
|
|
|
|
|
ClientContext::GetSocket() const
|
|
|
|
|
{
|
|
|
|
|
assert(m_sessionData.get());
|
|
|
|
|
return m_sessionData->GetSocket();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ClientContext::SetSocket(SOCKET sockfd)
|
|
|
|
|
{
|
2009-01-11 20:12:26 +00:00
|
|
|
m_sessionData.reset(new SessionData(sockfd, SESSION_ID_GENERIC, m_senderThread, *m_senderCallback));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<SessionData>
|
|
|
|
|
ClientContext::GetSessionData() const
|
|
|
|
|
{
|
|
|
|
|
return m_sessionData;
|
|
|
|
|
}
|
|
|
|
|
|