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. *
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
#define FD_SETSIZE 512
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <net/receiverhelper.h>
|
|
|
|
|
#include <net/socket_msg.h>
|
|
|
|
|
#include <net/netexception.h>
|
2007-11-22 20:07:41 +00:00
|
|
|
#include <core/loghelper.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ReceiverHelper::ReceiverHelper()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReceiverHelper::~ReceiverHelper()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-05-04 21:11:29 +00:00
|
|
|
ReceiverHelper::ScanPackets(ReceiveBuffer &buf)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
bool dataAvailable = true;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> tmpPacket;
|
|
|
|
|
// This is necessary, because we use TCP.
|
|
|
|
|
// Packets may be received in multiple chunks or
|
|
|
|
|
// several packets may be received at once.
|
2009-08-02 15:11:40 +00:00
|
|
|
if (buf.recvBufUsed)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// This call will also handle the memmove stuff, i.e.
|
|
|
|
|
// buffering for partial packets.
|
|
|
|
|
tmpPacket = NetPacket::Create(buf.recvBuf, buf.recvBufUsed);
|
2007-11-22 20:07:41 +00:00
|
|
|
} catch (const NetException &e)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
// Reset buffer on error.
|
|
|
|
|
buf.recvBufUsed = 0;
|
2007-11-22 20:08:45 +00:00
|
|
|
LOG_ERROR(e.what());
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-03 20:42:32 +00:00
|
|
|
if (tmpPacket)
|
|
|
|
|
{
|
|
|
|
|
//cerr << "IN:" << endl << tmpPacket->ToString() << endl;
|
2007-11-16 15:24:25 +00:00
|
|
|
buf.receivedPackets.push_back(tmpPacket);
|
2009-08-03 20:42:32 +00:00
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
else
|
|
|
|
|
dataAvailable = false;
|
|
|
|
|
} while(dataAvailable);
|
|
|
|
|
}
|
|
|
|
|
|