epoc32/include/tcpseq.h
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/tcpseq.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,82 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// tcpseq.h - TCP sequence numbers
    1.18 +// This module defines a TCP sequence number with mod32 arithmetic.
    1.19 +//
    1.20 +
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file tcpseq.h
    1.25 + @publishedAll
    1.26 + @released
    1.27 +*/
    1.28 +
    1.29 +#ifndef __TCPSEQ_H__
    1.30 +#define __TCPSEQ_H__
    1.31 +
    1.32 +#include <e32std.h>
    1.33 +
    1.34 +
    1.35 +/**  TCP sequence number with mod-32 arithmetic.
    1.36 +@publishedAll
    1.37 +@released
    1.38 +*/
    1.39 +class TTcpSeqNum
    1.40 +	{
    1.41 +public:
    1.42 +  	inline TTcpSeqNum()					  			{ iSeq = 0; }
    1.43 +  	inline TTcpSeqNum(TUint32 aSeq)			  		{ iSeq = aSeq; }
    1.44 +  	inline TTcpSeqNum(const TTcpSeqNum& aSeq)		{ iSeq = aSeq.iSeq; }
    1.45 +
    1.46 +  	inline TTcpSeqNum& operator=(TUint32 aSeq)		  { iSeq = aSeq; return *this; }
    1.47 +  	inline TTcpSeqNum& operator=(const TTcpSeqNum& aSeq)	  { iSeq = aSeq.iSeq; return *this; }
    1.48 +  	inline TTcpSeqNum& operator+=(TInt aOff)		  { iSeq += aOff; return *this; }
    1.49 +  	inline TTcpSeqNum& operator-=(TInt aOff)		  { iSeq -= aOff; return *this; }
    1.50 +
    1.51 +  	inline TTcpSeqNum& operator++()			{ ++iSeq; return *this; }
    1.52 +  	inline TTcpSeqNum operator++(TInt)		{ return iSeq++; }
    1.53 +  	inline TTcpSeqNum& operator--()			{ --iSeq; return *this; }
    1.54 +  	inline TTcpSeqNum operator--(TInt)		{ return iSeq--; }
    1.55 +
    1.56 +  	inline TBool operator==(const TTcpSeqNum& aSeq) const	{ return iSeq == aSeq.iSeq; }
    1.57 +  	inline TBool operator!=(const TTcpSeqNum& aSeq) const	{ return iSeq != aSeq.iSeq; }
    1.58 +  	inline TBool operator<(const TTcpSeqNum& aSeq) const	{ return (TInt32)(iSeq - aSeq.iSeq) < 0; }
    1.59 +  	inline TBool operator<=(const TTcpSeqNum& aSeq) const	{ return (TInt32)(iSeq - aSeq.iSeq) <= 0; }
    1.60 +  	inline TBool operator>(const TTcpSeqNum& aSeq) const	{ return (TInt32)(iSeq - aSeq.iSeq) > 0; }
    1.61 +  	inline TBool operator>=(const TTcpSeqNum& aSeq) const	{ return (TInt32)(iSeq - aSeq.iSeq) >= 0; }
    1.62 +  	inline TTcpSeqNum operator+(TInt aOff) const		  	{ return iSeq + aOff; }
    1.63 +  	inline TTcpSeqNum operator-(TInt aOff) const		  	{ return iSeq - aOff; }
    1.64 +  	inline TInt32 operator-(const TTcpSeqNum& aSeq) const   { return iSeq - aSeq.iSeq; }
    1.65 +
    1.66 +  	//
    1.67 +  	// Automatic typecast can lead to ambiguous expressions and
    1.68 +  	// in the worst case to some very hard-to-track errors.
    1.69 +  	// We use the following explicit typecast instead. -ML
    1.70 +  	//
    1.71 +  	inline TUint32 Uint32() const				  { return iSeq; }
    1.72 +	//inline operator TUint32() const			  { return iSeq; }
    1.73 +
    1.74 +  	// Methods for checking whether a sequence number is inside or outside a given window.
    1.75 +  	inline TBool Inside(TTcpSeqNum aSeqLo, TTcpSeqNum aSeqHi)
    1.76 +    	{ return (iSeq - aSeqLo.iSeq) <= (aSeqHi.iSeq - aSeqLo.iSeq); }
    1.77 +
    1.78 +  	inline TBool Outside(TTcpSeqNum aSeqLo, TTcpSeqNum aSeqHi)
    1.79 +    	{ return (iSeq - aSeqLo.iSeq) > (aSeqHi.iSeq - aSeqLo.iSeq); }
    1.80 +
    1.81 +private:
    1.82 +  	TUint32 iSeq;
    1.83 +	};
    1.84 +
    1.85 +#endif