Changeset: 9d7879af4bff for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9d7879af4bff
Modified Files:
clients/mapilib/connect.c
clients/mapilib/connect_openssl.c
clients/mapilib/mapi.c
clients/mapilib/mapi_intern.h
common/stream/openssl_stream.c
Branch: monetdburl
Log Message:
Send leading NULs on the raw connection, not on the blockstream
diffs (133 lines):
diff --git a/clients/mapilib/connect.c b/clients/mapilib/connect.c
--- a/clients/mapilib/connect.c
+++ b/clients/mapilib/connect.c
@@ -178,7 +178,7 @@ wrap_socket(Mapi mid, SOCKET sock)
goto bailout;
}
- msg = mapi_set_streams(mid, rstream, wstream);
+ msg = mapi_wrap_streams(mid, rstream, wstream);
if (msg != MOK)
goto bailout;
return MOK;
@@ -275,31 +275,6 @@ connect_socket_tcp(Mapi mid)
if (msg != MOK)
return msg;
- // Send some NUL bytes. If we're accidentally connecting to the wrong
- // port or protocol this may cause the remote server to close the
- // connection. If we don't do this, the connection will often hang
- // because the server expects us to speak first and we expect the server
- // to speak first.
- //
- // Note that a pair of NUL bytes is a no-op message in MAPI.
- //
- // Surprisingly, it seems sending these NUL bytes makes non-TLS
- // connection setup a little faster rather than slower!
- static const char zeroes[8] = { 0 };
- ssize_t to_write = sizeof(zeroes);
- while (to_write > 0) {
- ssize_t n = mnstr_write(mid->to, zeroes, 1, to_write);
- if (n < 0) {
- close_connection(mid);
- return mapi_printError(mid, __func__, MERROR, "could
not send leader block: %s", mnstr_peek_error(mid->to));
- }
- to_write -= (size_t)n;
- }
- if (mnstr_flush(mid->to, MNSTR_FLUSH_DATA) != 0) {
- close_connection(mid);
- return mapi_printError(mid, __func__, MERROR, "could not flush
leader block: %s", mnstr_peek_error(mid->to));
- }
-
return msg;
}
diff --git a/clients/mapilib/connect_openssl.c
b/clients/mapilib/connect_openssl.c
--- a/clients/mapilib/connect_openssl.c
+++ b/clients/mapilib/connect_openssl.c
@@ -205,7 +205,7 @@ wrap_tls(Mapi mid, SOCKET sock)
return croak(mid, __func__, "openssl_wstream: %s",
mnstr_peek_error(wstream));
}
// On error: free 'rstream' and 'wstream'.
- msg = mapi_set_streams(mid, rstream, wstream);
+ msg = mapi_wrap_streams(mid, rstream, wstream);
if (msg != MOK) {
mnstr_close(rstream);
mnstr_close(wstream);
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -4614,7 +4614,7 @@ mapi_get_active(Mapi mid)
MapiMsg
-mapi_set_streams(Mapi mid, stream *rstream, stream *wstream)
+mapi_wrap_streams(Mapi mid, stream *rstream, stream *wstream)
{
// do not use check_stream here yet because the socket is not yet in
'mid'
const char *error_message;
@@ -4623,6 +4623,32 @@ mapi_set_streams(Mapi mid, stream *rstre
assert(!isa_block_stream(rstream));
assert(!isa_block_stream(wstream));
+ // First send some NUL bytes. If we're accidentally connecting to the
wrong
+ // port or protocol this may cause the remote server to close the
+ // connection. If we don't do this, the connection will often hang
+ // because the server expects us to speak first and we expect the server
+ // to speak first.
+ //
+ // Note that a pair of NUL bytes is a no-op message in MAPI.
+ //
+ // Surprisingly, it seems sending these NUL bytes makes non-TLS
+ // connection setup a little faster rather than slower!
+ static const char zeroes[8] = { 0 };
+ ssize_t to_write = sizeof(zeroes);
+ while (to_write > 0) {
+ ssize_t n = mnstr_write(wstream, zeroes, 1, to_write);
+ if (n < 0) {
+ close_connection(mid);
+ return mapi_printError(mid, __func__, MERROR, "could
not send leader block: %s", mnstr_peek_error(wstream));
+ }
+ to_write -= (size_t)n;
+ }
+ if (mnstr_flush(wstream, MNSTR_FLUSH_DATA) != 0) {
+ close_connection(mid);
+ return mapi_printError(mid, __func__, MERROR, "could not flush
leader block: %s", mnstr_peek_error(wstream));
+ }
+
+
stream *brstream = NULL;
stream *bwstream = NULL;
diff --git a/clients/mapilib/mapi_intern.h b/clients/mapilib/mapi_intern.h
--- a/clients/mapilib/mapi_intern.h
+++ b/clients/mapilib/mapi_intern.h
@@ -303,7 +303,7 @@ extern const struct MapiStruct MapiStruc
Mapi mapi_new(void);
MapiMsg wrap_tls(Mapi mid, SOCKET sock);
-MapiMsg mapi_set_streams(Mapi mid, stream *rstream, stream *wstream);
+MapiMsg mapi_wrap_streams(Mapi mid, stream *rstream, stream *wstream);
MapiMsg scan_unix_sockets(Mapi mid);
MapiMsg connect_socket_unix(Mapi mid);
diff --git a/common/stream/openssl_stream.c b/common/stream/openssl_stream.c
--- a/common/stream/openssl_stream.c
+++ b/common/stream/openssl_stream.c
@@ -129,9 +129,13 @@ ostream_close(stream *s)
int
ostream_flush(stream *s, mnstr_flush_level flush_level)
{
- (void)s;
(void)flush_level;
- mnstr_set_error(s, MNSTR_WRITE_ERROR, "flush not implemented");
- return -1;
+ BIO *bio = (BIO*) s->stream_data.p;
+ // This segfaults, I don't understand why.
+ // It seems to work without it so for the time being leave it commented
out.
+ // if (1 != BIO_flush(bio))
+ // return ostream_error(s, MNSTR_WRITE_ERROR);
+ (void)bio;
+ return 0;
}
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]