BorisTheOld wrote:
Zero seems perfectly normal to me, since in most languages zero means false, and anything else means true.
Returning -1 to mean false is what's confusing, but unfortunately that's the way PB works.
I don't agree. It's the normal behaviour of berkely socket programming (windows, linux, ...). If somebody start network programming with OS functions himself following are very basic ones:
socket():
> -1 = File descriptor
-1 = Invalid socket
listen():
0 = Everything ok
-1 = A socket error occured (e.g. socket already connected)
bind():
0 = Everything ok
-1 = A socket error occured (e.g. port is already in use)
accept():
> -1 = File descriptor
-1 = A socket error occured (e.g. too many open fds)
select()
> 1 = One or more sockets from your array are able to read or write or whatever you told select to check for you
0 = No socket was ready to read or write or whatever you've checked
-1 = A socket error occured (which could be many different like "connection unexpected closed" or "please try again" on non-blocking stuff)
recv()
> 1 = num of bytes that was read successfully
0 = client gracefully disconnected
-1 = A socket error occured (which could mean yet again something serious or something non-fatal)
send()
> -1 = num of bytes sent
-1 = A socket error occured (which could mean send again or connection reset by peer or whatever)
Conclusion: You could get "-1" very often at socket programming. The current PB Network functions are just not made for the purpose of "check just one socket in one thread". If you need that behaviour I would recommend use the berkeley socket commands. So you could "accept" one after each other in your main and do the work seperated in your client threads without the need to sort out all incoming events again in your mainthread for sockets you already forwarded to one of your threads. Afterwards you have the freedom to check just one socket by one select or switch to nonblocking or change different timeout values or handle mutlicasts and so on. PB network functions are good if you would use them in just one thread (either main or not). Unfortunately the current "OpenWindows()" implemention forces you to use that (imho) "non-modular" behaviour everywhere else. And while it's easy to workaround at network programming (coz the berkeley functions are used almost the same on different OS) it's a pain at windows() programming.
Greetings,
auser