03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

aFromPort, aData);<br />

If iLastError is KErrNone, then this simply passes the data and addressing information<br />

to the transmit queue. If iLastError is not KErrNone, then we leave with this error. This<br />

enables us to pass back any errors from GDP that occurred on the previous send although<br />

they will only be received by the client on the next Send(). In the transmit queue, the<br />

datagram packet is created and placed on the queue. Then, if the adapter is able to send<br />

data at this point (i.e. there is no send outstanding) the datagram is sent:<br />

void CGsdpTransmitQueue::Transmit(TUint32 aGameProtocol, TUint32<br />

aToPort,<br />

const TDesC8& aFromAddress, TUint32 aFromPort, const TDesC8&<br />

aData)<br />

{<br />

// get first free packet slot - drop packet if there isn't one<br />

TGsdpPacket* packet=AddPacket(aGameProtocol, aToPort,<br />

aFromAddress,<br />

aFromPort, aData);<br />

if (!packet)<br />

return;<br />

// see if it can be sent<br />

if(iAdapter.CanSendPacket(*packet))<br />

iAdapter.SendPacket(*packet);<br />

}<br />

SendPacket() is triggered from two places in the code:<br />

� when a datagram is sent, and there is no send outstanding,<br />

� when the GDP protocol calls the SendComplete() callback, signalling that it is ready<br />

to send the next datagram.<br />

This ensures that if there are packets on the queue, there will be asynchronous events that<br />

gradually drain the queue. Finally, in Send-Packet() the GSDP packet is passed down to<br />

the GDP protocol:<br />

void CGsdpGdpAdapter::SendPacket(TGsdpPacket& aPacket)<br />

{<br />

if(!iSendActive) // otherwise drop<br />

{<br />

RDesWriteStream writer(iSendBuffer);<br />

writer < < aPacket.iGameProtocol;<br />

writer < < aPacket.iFromPort;<br />

writer < < aPacket.iToPort;<br />

writer < < aPacket.iData;<br />

writer.CommitL();<br />

iSendActive = ETrue; // do this first in<br />

case SendComplete is sync

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!