Page 2 of 2

Re: Fred, I believe you are mistaken on this...

Posted: Thu Oct 18, 2012 12:11 am
by skywalk
Hi Rich,
Please change the title of your thread to something more meaningful to the community. Addressing Fred or anyone else personally is better handled with private messages. :wink:
Thanks for posting bugs/suggestions that will improve the language for all of us.

Re: Differences in interpretation of native PB network code.

Posted: Thu Oct 18, 2012 12:18 am
by RichAlgeni
Understood Skywalk. Consider me slapped.

How's this?

Re: Differences in interpretation of native PB network code.

Posted: Thu Oct 18, 2012 3:54 am
by skywalk
Thanks...thread has more meaning now 8)

Re: Fred, I believe you are mistaken on this...

Posted: Wed Nov 07, 2012 10:02 am
by auser
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

Re: Differences in interpretation of native PB network code.

Posted: Sat Nov 10, 2012 9:59 pm
by BorisTheOld
In that case, -1 would seem to be perfectly reasonable. :)