Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-10-22
17:19 • Ticket [1329568fff] socket -async and puts: Inadequate documentation? st... artifact: c1f599f8ed user: serhiy.storchaka
2026-10-16
21:17 • Closed ticket [1329568fff]. artifact: d89f277197 user: serhiy.storchaka
2014-03-11
07:42 • Ticket [1329568fff]: 8 changes artifact: 524be388bb user: oehhar
2006-03-16
05:30 • Ticket [1329568fff]: 4 changes artifact: 3dfc0465ee user: andreas_kupries
2006-03-15
05:04 • Ticket [1329568fff]: 4 changes artifact: c5b65c117a user: setok
04:55 • Ticket [1329568fff]: 5 changes artifact: 8f359fbc29 user: andreas_kupries
2005-10-18
15:54 • New ticket [1329568fff]. artifact: 356b186cdf user: setok

[socket -async] and [puts]: Inadequate documentation?

Closed / Fixed1329568fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 41 days ago
Descriptionplain2005-10-18 15:54:04
What happens if I open a socket with the -async option and then 
immediately start writing to the channel? The documentation 
mentions what happens when reading (although only in terms of 
[gets]). It does have information on how [flush] works, but if I write 
a large amount of information, is it possible I might fill up some 
buffer? What happens then?
andreas_kupriesplain2006-03-15 04:55:55
Logged In: YES 
user_id=75003

The puts command queues data only until the condition set
via  -buffering is met, and then invokes [flush] internally.
At that point the description of [flush] takes over.

By default it flushes when a -buffersize'd number of
characters have accumulated. Or every line, or always.

The best way of dealing with -async is to set a handler for
writable events. It triggers when the connection is open, or
has positively failed.
setokplain2006-03-15 05:04:37
Logged In: YES 
user_id=137542

Thank you for the response. However, this does not answer my question in all 
totality. What if the write buffer is full but a connection has not yet been made? 
This is not actually answered in the [flush] documentation either. Will an error 
occur if an attempt is made to flush the buffer, but the connection of an -async 
socket has not yet been completed? Or will the buffer be resized while we are 
waiting to connect?
andreas_kupriesplain2006-03-16 05:30:13
Logged In: YES 
user_id=75003

How about writing a tcl script which tests this ? My guess
is that you would get an error as there should be no
open/valid file handle Tcl can actually write to.

Regarding buffer resizing, the only way to change buffer
sizes is via fconfigure. The system does no automatic changes.
oehharplain2014-03-11 07:42:58
In the current branch [bug-13d3af3ad5] this is addressed and works as follows:

a) blocking socket

set h [socket -async $host $port]
...
puts $h $data

With the puts, the socket is switched to syncroneous mode. If this succeeds, the puts succeeds, otherwise, the puts fails.

b) non blocking but without event queue:
set h [socket -async $host $port]
fconfigure $h -blocking 0
gets $h $data

I don't know what happens with a puts, but with gets, each time the async connect is proceeded until connected and then it returns any received data.

There are now tests for that...
serhiy.storchakawiki2026-10-16 21:17:47

The documentation now covers this: socket.n says that a blocking flush waits for the connection and a non-blocking one buffers the data, and chan.n says that non-blocking puts buffers without limit. Testing this found a 9.0 regression, reported as [251f46655c].

serhiy.storchaka Ticket [1329568fff]: 3 changes [History diff]2026-10-22 17:19:27
Log in (anonymous is fine) to add a comment.