When a remote device sends the first data packet, the MLlcpConnLessListener::FrameReceived()
callback is called. The remote connection is stored and COwnLlcpConnection::Receive()
is called. Once the first
data packet is completed immediately, and COwnLlcpConnection::Receive()
is repeated.
Call the CMyOwnLlcpApplication::FrameReceived()
method and store
the remote connection, as shown in the following code snippet:
Example:
// CMyOwnLlcpApplication::FrameReceived() // From MLlcpConnLessListener // ----------------------------------------------------------------------------- // void CMyOwnLlcpApplication::FrameReceived( MLlcpConnLessTransporter* aConnection ) { TInt error = KErrNone; // Only accepting one incoming remote connection if ( !iRemoteConnection ) { // Creating a wrapper for the connection. TRAP( error, iRemoteConnection = COwnLlcpConnection::NewL( aConnection ) ); if ( error == KErrNone ) { // Start receiving the data iRemoteConnection->Receive( *this ); } else { delete aConnection; } } else { delete aConnection; } } // ----------------------------------------------------------------------------- // End of CMyOwnLlcpApplication::FrameReceived()
Implement
the COwnLlcpConnection::Receive()
method as shown
in the following code snippet:
Example:
// COwnLlcpConnection::Receive() // ----------------------------------------------------------------------------- // TInt COwnLlcpConnection::Receive( MLlcpTransmitCb& aLlcpTransmitCb ) { TInt error = KErrNone; if ( iActionState == EIdle ) { TInt length = 0; length = iConnection->SupportedDataLength(); if ( length > 0 ) { iReceiveBuf.Zero(); error = iReceiveBuf.ReAlloc( length ); if ( error == KErrNone ) { iConnection->Receive( iStatus, iReceiveBuf ); SetActive(); iActionState = EReceiving; iLlcpTransmitCb = &aLlcpTransmitCb } } else { // If the length is 0 or negative, the LLCP link is destroyed. error = KErrNotReady; } } else { // The connection is already connecting or transferring data, // Cannot start receiving. error = KErrInUse; } return error; } // ----------------------------------------------------------------------------- // End of COwnLlcpConnection::Receive()
Note:
The COwnLlcpConnection::Receive()
method cannot
start receiving data if there are any pending transfer or receive
requests. In such a scenario, KErrInUse
is returned.
An LLCP link between the local and remote devices can be removed
anytime and hence the MLlcpConnLessTransporter::SupportedDataLength()
method can return negative values and must be handled correctly.
The following diagram illustrates the sequence diagram of data receiving: