Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cNetServerConnection Class Reference

#include <cNetServer.h>

Inheritance diagram for GrayLib::cNetServerConnection:
Gray::cRefBase GrayLib::cNetStream IUnknown Gray::cStream Gray::cStreamStats Gray::cStreamInput Gray::cStreamOutput Gray::cStreamBase Gray::cStreamBase

Public Member Functions

 cNetServerConnection (cNetServerGroup *pServerGroup, cNetServerPort *pListenPort, SOCKET hSocket, const cNetAddress &addrPeer, cProtocolStream *pProtocol=nullptr)
 
virtual ~cNetServerConnection ()
 
const char * get_ServerName () const
 
HASHCODE_t get_HashCode () const noexcept
 
 STDMETHOD_ (HASHCODE_t, get_HashCodeX)() const noexcept override
 
 STDMETHOD_ (cString, get_Name)() const override
 
 STDMETHOD_ (cStringA, get_SymName)() const
 
HRESULT ProcessStreamInp ()
 
virtual HRESULT onEventRead () override
 FD_WRITE similar to MFC OnReceive. More...
 
virtual HRESULT OnTickStream ()
 
virtual void Close () override
 
 IUNKNOWN_DISAMBIG (cRefBase)
 
- Public Member Functions inherited from Gray::cRefBase
 cRefBase (int iRefCount=0) noexcept
 
virtual ~cRefBase ()
 
int get_RefCount () const noexcept
 
HASHCODE_t get_HashCode () const noexcept
 
 STDMETHOD_ (HASHCODE_t, get_HashCodeX)() const noexcept
 
virtual void onFinalRelease ()
 
bool isValidObj () const noexcept
 
 STDMETHOD_ (ULONG, AddRef)(void) override
 
 STDMETHOD_ (ULONG, Release)(void) override
 
STDMETHOD() QueryInterface (const IID &riid, void __RPC_FAR *__RPC_FAR *ppvObject) override
 
void IncRefCount ()
 
void DecRefCount ()
 
bool isStaticConstruct () const noexcept
 
void StaticConstruct ()
 
void StaticDestruct ()
 
bool isDestructing () noexcept
 
void SetDestructing ()
 
- Public Member Functions inherited from GrayLib::cNetStream
 cNetStream (SOCKET hSocket=INVALID_SOCKET, bool bAsync=false, size_t nRxBufferLimit=(cStream::k_FILE_BLOCK_SIZE/2))
 
virtual ~cNetStream (void)
 
bool isConnected () const
 
bool isConnecting () const noexcept
 
bool isValidSocket () const noexcept
 
HASHCODE_t get_HashCode () const noexcept
 
bool isInputDesired () const
 
bool isInputEmpty () const
 
bool isOutputEmpty () const
 
ITERATE_t get_InputQty () const
 
ITERATE_t get_OutputQty () const
 
virtual HRESULT onEventWrite ()
 override these if we want to know if data is ready to TX or RX More...
 
HRESULT UpdateQWrite ()
 
HRESULT UpdateQRead ()
 
cStreamOutputget_StreamOut ()
 
cStreamInputget_StreamInp ()
 
virtual HRESULT WriteX (const void *pData, size_t nDataSize) override
 
virtual HRESULT ReadX (void *pData, size_t nDataSize) override
 
virtual size_t SetSeekSizeMin (size_t nSizeMin=k_FILE_BLOCK_SIZE) override
 
virtual STREAM_SEEKRET_t Seek (STREAM_OFFSET_t iOffset, SEEK_ORIGIN_TYPE eSeekOrigin) override
 Disambiguate Seek for cStreamBase to cStreamInput for stupid compiler. More...
 
void SetStateEstablished ()
 
 UNITTEST_FRIEND (cNetStream)
 
- Public Member Functions inherited from Gray::cStream
virtual STREAM_POS_t GetPosition () const override
 
virtual STREAM_POS_t GetLength () const override
 
void SeekToBegin ()
 
STREAM_POS_t SeekToEnd ()
 
- Public Member Functions inherited from Gray::cStreamInput
 cStreamInput () noexcept
 
virtual ~cStreamInput ()
 
virtual HRESULT ReadX (OUT void *pData, size_t nDataSize)
 
HRESULT ReadAll (OUT cHeapBlock &block, size_t nSizeExtra=0)
 
virtual HRESULT ReadStringLine (OUT char *pszBuffer, StrLen_t iSizeMax)
 
virtual HRESULT ReadStringLine (OUT wchar_t *pszBuffer, StrLen_t iSizeMax)
 
HRESULT ReadT (OUT void *pVal, size_t nSize)
 
template<typename TYPE >
HRESULT ReadT (OUT TYPE &val)
 
template<typename TYPE >
HRESULT ReadTN (OUT TYPE &val)
 
HRESULT ReadSize (OUT size_t &nSize)
 
template<typename TYPE >
HRESULT ReadSizeT (OUT TYPE &n)
 
HRESULT ReadHashCode (OUT UINT32 &nHashCode)
 
HRESULT ReadHashCode (OUT UINT64 &nHashCode)
 
HRESULT ReadN (OUT BYTE *pBuffer, size_t nSizeMax)
 
template<typename _CH >
HRESULT ReadStringN (OUT _CH *pszStr, StrLen_t iSizeMax)
 
virtual HRESULT ReadPeek (void *pData, size_t nDataSize)
 
- Public Member Functions inherited from Gray::cStreamBase
virtual ~cStreamBase ()
 
void SeekToBegin ()
 
STREAM_POS_t SeekToEnd ()
 
- Public Member Functions inherited from Gray::cStreamOutput
 cStreamOutput () noexcept
 
virtual ~cStreamOutput ()
 
HRESULT WriteT (const void *pVal, size_t nDataSize)
 
template<typename TYPE >
HRESULT WriteT (TYPE val)
 
HRESULT WriteSize (size_t nSize)
 
HRESULT WriteHashCode (HASHCODE_t nHashCode)
 
HRESULT WriteN (const void *pBuffer, size_t nSize)
 
template<typename _CH >
HRESULT WriteStringN (const _CH *pszStr)
 
template<typename _CH >
HRESULT WriteCharRepeat (_CH nChar, int nCount=1)
 
virtual HRESULT WriteString (const char *pszStr)
 
virtual HRESULT WriteString (const wchar_t *pszStr)
 
StrLen_t VPrintf (const char *pszFormat, va_list args)
 
StrLen_t VPrintf (const wchar_t *pszFormat, va_list args)
 
StrLen_t _cdecl Printf (const char *pszFormat,...)
 
StrLen_t _cdecl Printf (const wchar_t *pszFormat,...)
 
HRESULT WriteStream (cStreamInput &sInp, STREAM_POS_t nSizeMax=k_FILE_BLOCK_SIZE, IStreamProgressCallback *pProgress=nullptr, TIMESYSD_t nTimeout=0)
 Copy cStreamInput to this stream. More...
 
virtual HRESULT FlushX ()
 
- Public Member Functions inherited from Gray::cStreamStats
void Add (const cStreamStats &n)
 

Public Attributes

cNetServerGroupm_pServerGroup
 Assigned to this group/thread for processing. More...
 
cNetServerPortPtr m_pListenPort
 the server port i connected on. (if incoming connection, nullptr if outgoing connection)(used to resolve protocol) More...
 
const cNetAddress m_addrPeer
 The peer (source/remote) connection address. if i care. More...
 
cProtocolStreamPtr m_pProtocol
 resolved to talk this protocol. nullptr = protocol not resolved yet. More...
 
- Public Attributes inherited from GrayLib::cNetStream
cNetSocket m_Socket
 the raw TCP SOCKET we are buffering to/from. More...
 
bool m_bAsync
 Will this socket be using OnEvent FD_READ FD_WRITE events ? More...
 
bool m_bInpThrottled
 The m_bAsync input was throttled. we cant rely on m_bAsync OnEvent to notify us again. we must poll. More...
 
cStreamQueue m_bout
 raw output buffer to m_Socket. can write to this externally if m_bAsync. More...
 
cStreamQueue m_binp
 raw input buffer from m_Socket. can read from this externally if m_bAsync. More...
 
HRESULT m_hResultRx
 The status of the connect or disconnect. S_OK = connected. else how to it close ? don't return this until we read all the m_binp data. More...
 
- Public Attributes inherited from Gray::cStreamStats
cStreamStat m_StatOut
 
cStreamStat m_StatInp
 

Additional Inherited Members

- Static Public Attributes inherited from Gray::cStreamBase
static const BYTE k_SIZE_MASK = 0x80
 Used for WriteSize() More...
 
static const size_t k_FILE_BLOCK_SIZE = (32 * 1024)
 default arbitrary transfer block size. more than this is NOT more efficient. More...
 

Detailed Description

a single client/connection/socket to the cNetServer. Raw Stream. used as opaque holder class for a cProtocolStream for the server. connected via cNetStream/cNetSocket

Note
Isolates cProtocolStream from cNetSocket/cNetStream. e.g. pProtocol = cHttpProtocolStream

Constructor & Destructor Documentation

◆ cNetServerConnection()

GrayLib::cNetServerConnection::cNetServerConnection ( cNetServerGroup pServerGroup,
cNetServerPort pListenPort,
SOCKET  hSocket,
const cNetAddress addrPeer,
cProtocolStream pProtocol = nullptr 
)

◆ ~cNetServerConnection()

GrayLib::cNetServerConnection::~cNetServerConnection ( )
virtual

Member Function Documentation

◆ Close()

void GrayLib::cNetServerConnection::Close ( )
overridevirtual

Tell the protocol it is closing.

Note
can't clear m_pProtocol until OnClientClose() called from cNetServer thread only.

Reimplemented from GrayLib::cNetStream.

◆ get_HashCode()

HASHCODE_t GrayLib::cNetServerConnection::get_HashCode ( ) const
inlinenoexcept

Use the socket id as a unique id for this stream.

◆ get_ServerName()

const char * GrayLib::cNetServerConnection::get_ServerName ( ) const

◆ IUNKNOWN_DISAMBIG()

GrayLib::cNetServerConnection::IUNKNOWN_DISAMBIG ( cRefBase  )

◆ onEventRead()

HRESULT GrayLib::cNetServerConnection::onEventRead ( )
overridevirtual

FD_WRITE similar to MFC OnReceive.

Override cNetStream Check socket for new data.

Returns
0 = nothing here. <0 = error number of bytes size new data;

Event FD_READ or polled frequently. Read and queue up any data that is available.

Note
default read high water limit = cStream::k_FILE_BLOCK_SIZE/2
Returns
0 = nothing here. <0 = error. HRESULT_WIN32_C(WSAECONNABORTED), HRESULT_WIN32_C(ERROR_DEVICE_NOT_CONNECTED) Number of bytes size new data;

Reimplemented from GrayLib::cNetStream.

◆ OnTickStream()

HRESULT GrayLib::cNetServerConnection::OnTickStream ( )
virtual

Send a tick along to the protocol so it can do things periodically. like timeout.

◆ ProcessStreamInp()

HRESULT GrayLib::cNetServerConnection::ProcessStreamInp ( )

Called periodically to process queued incoming data. if any. If this is a resolved m_pProtocol, process all the input data.

Returns
HRESULT. HRESULT_WIN32_C(ERROR_IO_INCOMPLETE) = need more.

◆ STDMETHOD_() [1/3]

GrayLib::cNetServerConnection::STDMETHOD_ ( cString  ,
get_Name   
) const
override

◆ STDMETHOD_() [2/3]

GrayLib::cNetServerConnection::STDMETHOD_ ( cStringA  ,
get_SymName   
) const
inline

◆ STDMETHOD_() [3/3]

GrayLib::cNetServerConnection::STDMETHOD_ ( HASHCODE_t  ,
get_HashCodeX   
) const
inlineoverridenoexcept

Virtualized version of get_HashCode for IUnkObject

Member Data Documentation

◆ m_addrPeer

const cNetAddress GrayLib::cNetServerConnection::m_addrPeer

The peer (source/remote) connection address. if i care.

◆ m_pListenPort

cNetServerPortPtr GrayLib::cNetServerConnection::m_pListenPort

the server port i connected on. (if incoming connection, nullptr if outgoing connection)(used to resolve protocol)

◆ m_pProtocol

cProtocolStreamPtr GrayLib::cNetServerConnection::m_pProtocol

resolved to talk this protocol. nullptr = protocol not resolved yet.

◆ m_pServerGroup

cNetServerGroup* GrayLib::cNetServerConnection::m_pServerGroup

Assigned to this group/thread for processing.


The documentation for this class was generated from the following files: