Hi Currell,
I found when using HTTPS that the TLS handshake does not occur until the
writable (puts) side of the channel is flushed (i.e. after the HTTPS
request). This is not a problem for HTTPS because the client writes before
reading. However, in POP3 it is the other way round, and so a flush will
probably have no effect, and you will wait for ever. (On reflection this
issue should be filed as a bug in TclTLS.)
You can tell when the handshake occurs by using the -command option to
tls::socket.
Can you send a NOOP and then [flush] the channel?
When reading back messages, you are likely to encounter another bug.
This second bug is somewhere in either TclTLS, Tcl stacked channels, the Tcl
[read] command, fileevent generation or buffering, and it causes stalling
when using [read] over TLS.
This bug is reported here:
https://sourceforge.net/p/tls/bugs/38/
http://core.tcl.tk/tcl/tktview/1945538fffffffffffff
https://core.tcl.tk/tcltls/tktview/581d50e6cdc97b0bb5f0e5516086ac469e077f04
https://core.tcl.tk/tcl/tktview/46b6edad51e645c70e88dd4f944a2d4afc63a96a
The first report includes an investigation of the problem in a PDF file.
The last report refers to a different bug, but includes a workaround for
this TLS issue. The workaround is included in a revised form of the http
library in the "bug-46b6edad51-concurrent-http" branch of Tcl, forked from
8.6.8.
In HTTP, the bug is manifested when fetching a resource of known length
using an unchunked transfer. The workaround is to ask for the exact number
of bytes that are known to remain (or more). Since POP3 tells you the exact
size of each message, you should be able to use a similar workaround.
This goes against the standard practice of [read chan numchars] where
numchars is a convenient size for processing. However, if numchars is ever
less than the number of bytes remaining, then TclTLS will stall, if not on
that [read] then on a later one. A non-blocking [read] does not wait for the
entire numchars to arrive: it will return with whatever input is available,
and may need to be called several times.
A third issue is empty reads when [fileevent] reports that input is
available. This problem is mentioned in the bug reports above.
I hope this helps.
Keith.