[Gambas-user] Trouble writing to Accepted Socket stream

T Lee Davidson t.lee.davidson at gmail.com
Sat Mar 30 10:28:56 CET 2019


On 3/30/19 4:37 AM, Tobias Boege wrote:
> The Write event is supposed (as per source code) to only fire when you have
> enqueued data to be sent. It works like this:
> 
>   Write #Socket --> gb.net tries to send it, installs a Write event
>   callback --> which when fired raises the Gambas event and deinstalls
>   itself again until the next write happens

So then the documentation for the Socket.Write event handler saying, "This event is raised when the socket is ready for 
writing," is not correct?

Should that be, "This event is raised when there is enqueued data ready to be written to the socket"? Or should it be, "This 
event is raised when there is enqueued data to be written to the socket and the socket is ready to accept it"? I think I'm 
confused. Of what use is a callback if one does not have access to the data already in the 'pipe'?


> And that's how I take it you should use this event: your application appends
> to an arbitrary-sized Gambas String buffer the data which should be sent,
> and your Write event handler takes care of feeding the small kernel buffers
> from that string; the Write event will be raised whenever you can feed more.

How exactly would that be done? If the Write event doesn't fire until one has *already* written to the stream, what good is it?

If I have a global buffer declared and then defined with a huge amount of data to be sent over the socket, how do I use the 
Write event to write small chunks of that data to the socket if the Write event doesn't fire until I write to the socket?? Seems 
like a catch 22.

Would one write the first chunk in, say, the Socket_Read event handler and then let the Write event handle the rest? Sort of 
like priming a While loop?


>> Private crlf As String = Chr(13) & Chr(10)
> 
> BTW that particular constant is built into Gambas as gb.CrLf.

I thought something like that might be defined. I found gb.NewLine in "Predefined Constants" [0]. But, gb.CrLf is not there.


___
Lee

[0] http://gambaswiki.org/wiki/cat/constant


More information about the User mailing list