I am having troubles implementing NetLibSelect in my main event loop in
order to handle both data from a socket and user input. The problem I am
experiencing is that NetLibSelect seems (it's a little hard to tell for sure
since I can't debug on the emulator) to not set the FD for the socket even
though data is available. The first time around everything goes fine, and
some data is read from the socket. On the next iteration of the loop, even
though there is still data left to be read (as the read did not read all
available data) NetLibSelect says that there is nothing to read. The app
then hangs in this state until an event comes along (i.e. a pen tap) and
then for some strange reason NetLibSelect says that data is available and
the data is read. This whole process is repeated over and over again, an
din order for my program to successfully download a large chunk of data I
must continually tap the screen! I can't seem to figure out why this is
happening, and the fact that I can't use the debugger with NetLibSelect and
sysFileDescStdIn makes my life that much harder. Has anyone else run into
similar problems? Can anyone find anything wrong in my code?
Thanks in advance,
Alan
----------------------------
static void AppEventLoop(void)
{
UInt16 error = 0;
EventType event;
Int16 nNumFDs;
NetFDSetType readFDs, writeFDs;
NetInfoType netInfoBlock;
Boolean bSendMessage = false;
// Initialize the net information block:
MemSet(&netInfoBlock, sizeof(netInfoBlock), 0);
// Get the library ref number, socket handle, and flags from
storage:
error = NetInfo(&netInfoBlock, "get");
if (!error)
{
AppNetRefnum = netInfoBlock.netRefNum;
int sock = netInfoBlock.netSock;
do
{
// Check to see if we are posting
if (g_bBusy)
{
nNumFDs = 0;
netFDZero(&readFDs);
netFDZero(&writeFDs);
if (sock > 0)
netFDSet(sock, &readFDs);
netFDSet(sysFileDescStdIn, &readFDs);
int nWidth = sysFileDescStdIn;
if (sock > nWidth)
int nWidth = sock;
nNumFDs = NetLibSelect(AppNetRefnum, nWidth
+ 1, &readFDs, &writeFDs,
(NetFDSetType*)0,
SysTicksPerSecond() / 5, &errno);
// Process any events
if (nNumFDs > 0)
{
if (netFDIsSet(sock, &readFDs))
{
// Retrieve the response data
from the socket:
LPBYTE responseBufP =
(LPBYTE)MemPtrNew(MAX_RESPONSE_SIZE);
if (responseBufP)
{
Int32 nBytesRead =
0;
MemSet(responseBufP,
MAX_RESPONSE_SIZE, 0);
nBytesRead =
NetGetDataFromSocket(responseBufP, MAX_RESPONSE_SIZE);
if (nBytesRead > 0)
{
// We read
some data...handle it here
}
else if (nBytesRead
== 0)
{
// Socket
closed...process the response
}
MemPtrFree(responseBufP);
}
}
}
}
EvtGetEvent(&event, (!g_bBusy) ? evtWaitForever :
1);
if (! SysHandleEvent(&event))
if (! MenuHandleEvent(0, &event,
&error))
if (! AppHandleEvent(&event))
FrmDispatchEvent(&event);
} while (event.eType != appStopEvent);
}
return;
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/