- Main Page
- Classes
- Files

- File List
- File Members

# E:/uas2/Server/RecvPacket.h

Go to the documentation of this file.

    00001 /*
    00002 * This file is part of UAS2.
    00003 *
    00004 * UAS2 is free software; you can redistribute it and/or modify
    00005 * it under the terms of the GNU General Public License as published by
    00006 * the Free Software Foundation; either version 2 of the License, or
    00007 * (at your option) any later version.
    00008 *
    00009 * UAS2 is distributed in the hope that it will be useful,
    00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012 * GNU General Public License for more details.
    00013
    00014 * You should have received a copy of the GNU General Public License
    00015 * along with UASv1; if not, write to the Free Software
    00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00017 */
    00018
    00023 #ifndef __RECVPACKET_H
    00024 #define __RECVPACKET_H
    00025
    00026 #include <cassert>
    00027
    00028 #include "Shared.h"
    00029
    00030 class cRecvPacket
    00031 {
    00032 public:
    00033         cRecvPacket( )
    00034                 :       m_wSize( 0 )
    00035         {
    00036                 m_pcTH = reinterpret_cast< cTransportHeader * >( m_bData );
    00037         }
    00038
    00039         ~cRecvPacket( ) {}
    00040
    00041         inline DWORD    GetSequence     ( )     { return m_pcTH->m_dwSequence;  }
    00042         inline DWORD    GetFlags        ( )     { return m_pcTH->m_dwFlags;             }
    00043         inline DWORD    GetCRC          ( ) { return m_pcTH->m_dwCRC;           }
    00044         inline WORD             GetLogicalID( ) { return m_pcTH->m_wLogicalID;  }
    00045         inline WORD             GetTime         ( )     { return m_pcTH->m_wTime;               }
    00046         inline WORD             GetTotalSize( ) { return m_pcTH->m_wTotalSize;  }
    00047         inline WORD             GetTable        ( ) { return m_pcTH->m_wTable;          }
    00048
    00049         inline BYTE     *GetPayloadFront( )                                     { return m_bData + sizeof( cTransportHeader );                          }
    00050         inline BYTE     *GetPayload             ( WORD wOffset )        { return m_bData + sizeof( cTransportHeader ) + wOffset;        }
    00051         inline BYTE     *GetPayloadBack ( )                                     { return m_bData + sizeof( cTransportHeader ) + m_pcTH->m_wTotalSize;   }
    00052
    00053         inline void CopyPayload( WORD wOffset, void *pDest, WORD wSize )
    00054         {
    00055                 CopyMemory( pDest, m_bData + sizeof( cTransportHeader ) + wOffset, wSize );
    00056         }
    00057
    00058         inline BYTE& operator[]( int n )
    00059         {
    00060         #ifdef _DEBUG
    00061                 WORD wMaxSize = GetTotalSize( ) + sizeof( cTransportHeader );
    00062                 if ( wMaxSize > 0 )
    00063                         assert( n < wMaxSize );
    00064         #endif
    00065
    00066                 return m_bData[n];
    00067         }
    00068
    00069         inline int GetPadding( BYTE *pbStart );
    00070
    00071         BYTE            m_bData[MAX_PACKET_SIZE];
    00072         WORD            m_wSize;
    00073         SOCKADDR_IN m_saSockAddr;
    00074
    00075 private:
    00076         cTransportHeader *m_pcTH;
    00077 };
    00078
    00079 inline int cRecvPacket::GetPadding( BYTE *pbStart )
    00080 {
    00081         WORD wSize = *(WORD *)pbStart;
    00082         pbStart += (sizeof( WORD ) + wSize);
    00083
    00084         DWORD dwDiff = pbStart - m_bData;
    00085
    00086         if( dwDiff < 4 )
    00087                 return 4 - dwDiff;
    00088         else if ( (dwDiff % 4) != 0 )
    00089                 return 4 - (dwDiff % 4);
    00090         else
    00091                 return 0;
    00092 }
    00093
    00094 #endif  // #ifndef __RECVPACKET_H