Upstream tarball 9597
[amule.git] / src / libs / ec / cpp / ECPacket.cpp
blobc6935942897852ba95902578c4ff9890190ccd40
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2004-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 //
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
8 // respective authors.
9 //
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "ECPacket.h" // Needed for ECPacket
26 #include "ECSocket.h" // Needed for CECSocket
28 /**********************************************************
29 * *
30 * CECPacket class *
31 * *
32 **********************************************************/
34 bool CECPacket::ReadFromSocket(CECSocket& socket)
36 if (m_state == bsName) {
37 if (!socket.ReadNumber(&m_opCode, sizeof(ec_opcode_t))) {
38 return false;
39 } else {
40 m_state = bsChildCnt;
43 if (m_state == bsChildCnt || m_state == bsChildren) {
44 if (!ReadChildren(socket)) {
45 return false;
48 m_state = bsFinished;
49 return true;
53 bool CECPacket::WritePacket(CECSocket& socket) const
55 if (!socket.WriteNumber(&m_opCode, sizeof(ec_opcode_t))) return false;
56 if (!WriteChildren(socket)) return false;
57 return true;
60 /*!
61 * \fn CECPacket::CECPacket(ec_opcode_t opCode, EC_DETAIL_LEVEL detail_level)
63 * \brief Creates a new packet with given OPCODE.
66 /*!
67 * \fn ec_opcode_t CECPacket::GetOpCode(void) const
69 * \brief Returns OPCODE.
71 * \return The OpCode of the packet.
74 /*!
75 * \fn uint32 CECPacket::GetPacketLength(void) const
77 * \brief Returns the length of the packet.
79 * \return The length of the packet.
81 // File_checked_for_headers