A simple LDAP/SSL search query (objectclass filter, returning around 20 results) failed with the following message:
Protocol error: Error reading SEQUENCE response for handle
Debugging showed, that this occured when ldap::MessageReceiver tried to read the sequence byte. The reason was, that line 728
728 foreach {code type} [ReceiveBytes $conn(sock) 1] {break}
in combination with the following "default" branch of the switch statement expects the connection to return the byte immediately.
This expectation was not met. I surrounded the above line with a loop which continues on "partial" results for some tries and limited time. The error disappeared this way. The byte could be read from the socket almost at the same millisecond, after 20-30 loops.
More general, it is not wise to expect a non-blocking read to always return at least one byte.
As a solution, either partial "No byte available" responses are dealt with in place, or a more sophisticated "Collect the given number of bytes (for some time)" method is called.
The same query returned without an error when the non-secured ldap port (389) of the server was asked.
This could be an effect of TLS/Tcl bug.
http://sourceforge.net/tracker/index.php?func=detail&aid=1945538&group_id=10894&atid=110894
I'll look at the other suggestions.
This works quite well for me:
Before line 627, which contains "vwait [namespace which -variable $handle](message,$messageId)" in ldap.tcl insert some timeout, e. g. "after 50" or so. It helps when the server is significantly delayed, doesn't matter why. Should be incorporated to next patchlevel of tcllib (the current version is 1.14 recently).