PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

strange sockets behavior

Has anyone tried doing client-server stuff on the pocketpc? I found something looking like a bug, and it took me a vast amount of time to locate the source.
I'm operating on non-blocking sockets, unsing tcp/ip streaming operation. I didn't bother if there's a data to recieve, since non-blocking sockets should return in any case, returning error explaining me what's going wrong.
This didn't work. When I call recv(), it never returns if there is no data, or if I request more than it can recieve. This is wrong. There is a plain statement about non-blocking sockets in msdn:

WSAEWOULDBLOCK
10035
Resource temporarily unavailable.
This error is returned from operations on nonblocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket. It is a nonfatal error, and the operation should be retried later. It is normal for WSAEWOULDBLOCK to be reported as the result from calling connect on a nonblocking SOCK_STREAM socket, since some time must elapse for the connection to be established.


So it should return immidiately -1, and the get last error should return 10035 absolutely. This is what happens on a PC, but on a PocketPC recv hangs, and I had to reset my PDA. Though I can close connection on the other device, only then recv returns.

It took me 3 days banging my head into the wall to fix the stuff by calling ioctlsocket before(though I had to rewrite a lot of stuff until I discovered what actually must be done).

Can anyone comment, why is this happenning on a PocketPC?
I'm not sure what you're asking. It started working properly when you set the socket to non-blocking?

Code:

u_long n=1;
int rc=ioctlsocket(sock, FIONBIO, &n;);


If so, then that's the correct behavior. Were you expecting the socket to be non-blocking by default?

Dan East
Dan, of course I set sockets to non-blocking. They work correctly, since connect and accept doesn't stall and
return errors fine.

And 'it' never works correctly. If I call recv when there's no data, it stalled. I meant that I call ioctlsocket now like this:
Code:
ioctlsocket(clientS, FIONREAD, ¶m); // Check data to read


I've been told that there are no nonblocking sockets on a pocketpc, and they are somehow emulated thru threads. Can this be true?
Can you use the select function to test before the recv? I'm not too familiar with socket stuff, but this works well with UDP packets from PC to PDA.

Code:

TIMEVAL tv;

tv.tv_sec = 0;
tv.tv_usec = 1000 * 100 ;//100 mS
if (select(0, &fd, NULL, NULL, &tv)==0)
{ //timeout
}
else
{
n=recvfrom(sd, msg, MAX_MSG, 0,(struct sockaddr *) &cliAddr, &cliLen);
...
}

fast_rx, I'm pretty sure that select will work too, just like ioctlsocket(it's even possible that one calls another since they are similar). It is only that I didn't want to check anything - and the power of non-blocking sockets allows me this.

What really pissed me off is that wince sockets doesn't work exactly like on the PC.