Answers

Question and Answer:

  Home  Brew

⟩ When reading from a socket the phone reads whatever it can in one go, while the emulator reads large packets in chunks. Why?

This is a limitation of the phone.

Program should call ISOCKET_Readable() to be informed when more data can be read from the stream. The callback routine registered by ISOCKET_Readable() will be invoked whenever data becomes available---you can usually call ISOCKET_Read() at this point. Continue calling ISOCKET_Readable() for as long as your program expects more data.

rv = ISOCKET_Read(piSock, (byte *)szBuf, sizeof(szBuf));

if (rv == AEE_NET_WOULDBLOCK) {

// WOULDBLOCK => no more data available at the moment

// Register the callback to read the data later.

ISOCKET_Readable(piSock, CommonReadCB, (void*)pMe);

return;

}

else if (rv == AEE_NET_ERROR) {

// error reading from socket

ReleaseNetAndSocket (pMe);

}

else if (rv > 0) {

// rv bytes of data has been read from the socket into

// szBuf

// Read remaining data

ISOCKET_Readable(piSock, CommonReadCB, (void*)pMe);

}

else { // rv == 0

// There is no more data to be received.

// The peer has shut down the connection.

ReleaseNetAndSocket (pMe);

}

 160 views

More Questions for you: