[Gambas-user] Socket Limitations

Doriano Blengino doriano.blengino at ...1909...
Sun Jan 3 17:54:26 CET 2010


Benoît Minisini ha scritto:
>> [lot of talk]
>>     
>
> The point of view of the client and the server are not the same:
>
> The client likes blocking socket. It usually asks or sends something to the 
> server, waits for the answer, and so on... It usually does one thing at once.
>
> On the contrary, the server should serve multiple client connection at once. 
> Then it should use non-blocking sockets, and send data to the client only when 
> the socket raises its Write event, meaning that the OS has told Gambas that 
> the internal socket write buffer has space in it.
>
> The timeout is managed by the OS: I can only offer a property to define it, as 
> in other languages, but that should change nothing to the logic of the 
> program.
>
> <Kadaicha irony mode>
>
> I'm not sure that the MSDN documentation is a good reference for socket 
> programming:
>
> - The Microsoft documentation is often not connected to the reality it tries 
> to describe.
>
> - The Windows socket implementation often behaves differently than the other 
> OS implementation.
>
> </Kadaicha irony mode>
>
> My problem is: how can I have the easier Socket interface in Gambas for all 
> possible socket scenarii?
>
> That is the reason why I said that if the user asks for writing a big chunk of 
> data to the socket, I should temporarily other blocking mode. Maybe he is 
> doing something wrong (i.e. using a non-blocking socket, but not the Write 
> event), but Gambas can't be sure.
>
> Gambas 2 behave this way (not my decision), and I removed this behaviour in 
> Gambas 3, but now I don't remember why. I should test all the scenarii...
>
> Regards,
>
>   
Ok, it just came to my mind another possible way. The problem is that 
even having a "write" event, if you try to send out 128K bytes the write 
will not succed in one step. The same for reading - if you want to read 
a line, the OS will tell you that there is something to read, but not 
how much and neither if the incoming data contain a CR-LF or not. So 
there could be a way where you, in gambas, "write #xx" any amount of 
data. When the operation completes, an event is fired, where you can 
issue another write or shutdown the socket. Reading is a little 
trickyer, because the normal syntax implies that the value you read is 
available just after; in this case, one should "declare" that he wants 
to read a line, or a certain number of bytes, and when the event fires 
the data are ready to be used; in the same event you can issue another 
read, and so on. This is not a new idea, anyway.

The timeout, as seen in this discussion, could be settable for error 
raising purposes, and the blocking mode is handy to write simple 
programs without event management.

Just now I am writing a program which interfaces with gdb using pipes - 
this can be a good test to explore my idea; in fact I tried at first 
with blocking mode; then, not happy, tried non blocking mode with 
events; but trying to read whole lines of text does not work the way I 
want because still I find myself writing cycles, so I will try with this 
tecnique (an event raised when the operation requested has completed).

May be this can suggest something, may be not.

Regards,

-- 
Doriano Blengino

"Listen twice before you speak.
This is why we have two ears, but only one mouth."





More information about the User mailing list