Changeset: acd7f0433156 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/acd7f0433156
Modified Files:
        clients/mapilib/mapi.c
Branch: default
Log Message:

Send a number of NUL bytes on new MAPI connections over TCP

This forces an error message when accidentally connecting to a TLS server.
Also, surprisingly it seems to make connection setup slightly faster!


diffs (21 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -2576,6 +2576,17 @@ mapi_reconnect(Mapi mid)
        check_stream(mid, mid->to, "Cannot open socket for writing", 
mid->error);
        check_stream(mid, mid->from, "Cannot open socket for reading", 
mid->error);
 
+       // Send an even number of NUL '\0' bytes to the server.
+       // This forces an error message when accidentally connecting to a TLS 
server.
+       // Also, surprisingly it seems to make connection setup slightly faster!
+       static const char zeroes[8] = { 0 };
+       for (ssize_t nleft = sizeof(zeroes); nleft > 0; ) {
+               ssize_t nwritten = mnstr_write(mid->to, zeroes, 1, nleft);
+               if (nwritten < 0)
+                       return mapi_setError(mid, "could not send leader 
block", __func__, MERROR);
+               nleft -= nwritten;
+       }
+
        mid->connected = true;
 
        if (!isa_block_stream(mid->to)) {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to