| Ticket UUID: | 1329568 | ||
| Title: | [socket -async] and [puts]: Inadequate documentation? | ||
| Type: | Bug | Created on: | 2005-10-18 15:54:04 |
| Submitter: | setok | Assigned to: | max |
| Subsystem: | 24. Channel Commands | Severity: | Minor |
| Priority: | 3 Low | Last modified: | 2026-10-22 17:19:27 |
| Status: | Closed | Closed by: | serhiy.storchaka |
| Resolution: | Fixed | Closed on: | 2026-10-16 21:17:47 |
| Version: | obsolete: 8.4.11 | ||
| Description: | ||||
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? | ||||
| User Comments: | ||||
andreas_kupries added on 2006-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. setok added on 2006-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_kupries added on 2006-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. oehhar added on 2014-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.storchaka added on 2026-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]. | ||||
