[Gambas-user] Socket Limitations

Doriano Blengino doriano.blengino at ...1909...
Sat Jan 2 19:43:31 CET 2010


Benoît Minisini ha scritto:
>>> 2010/1/2 Benoît Minisini <gambas at ...1...>:
>>>       
>>>> Please provide the source code of the network communication,
>>>> otherwise I can't see what you are doing exactly.
>>>>         
>> Ok, here is some code that adequately reproduces the problem, and the
>> exact same code with a smaller chunk of text that does not have the
>> problem.
>>
>> SocketOK works.
>>
>> ChokeASocket is exactly 100% the same code except that it has a 48k
>> file to transmit to the remote server.
>>
>> The remote server is already setup in the code so just run it. I
>> recommend running SocketOK first. I have tried this with four
>> independent servers and get the same result, SocketDeath.
>>
>> Regards,
>>
>>     
>
> OK, I identified the problem:
>
> By default, Socket are in non-blocking mode (Blocking property set to False). 
> So writing to it a big chunk fails. The bug is that instead of raising an 
> error during the Write instruction, it fails silently.
>
> By having a blocking socket, your program works.
>
> So, two remarks:
>
> You should set the Blocking property to True in the Ready event.
>
> Maybe the Write instruction is silly: if the user wants to write a big chunk 
> of bytes, we should temporarily enter blocking mode while writing. Or not?
>   
I could only say that "big chunk" is something very uncertain - may be 
4096 bytes or 3. And that turning on or off the blocking mode should be, 
I think, never done automatically. May be that a timeout parameter could 
circumvent the problem, but again it is a bet. I mean, a timeout is a 
semi-blocking mode, but after a timeout occurs, one can only assume that 
the entire write has failed, even if, in fact, some data has been 
succefully written.
> It is not evident, because you may want to write on the socket only during its 
> Write event and need to never block. The problem is you can't know how many 
> bytes to send without sending them, and Gambas at the moment does not tell how 
> many bytes were successfully sent to the socket in one shot.
>
> Or maybe Socket must be blocking by default?
>
> Some thinking is needed there...
>
>   


-- 
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