diff --git a/sql-common/client.c b/sql-common/client.c index 4a95e02..87d0d6c 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1052,8 +1052,10 @@ cli_safe_read_with_ok(MYSQL *mysql, my_bool parse_ok, *is_data_packet= FALSE; if (net->vio != 0) + { + fprintf(stderr,"Conn ID: %lu\n", mysql->thread_id); len=my_net_read(net); - + } if (len == packet_error || len == 0) { DBUG_PRINT("error",("Wrong connection or packet. fd: %s len: %lu", diff --git a/sql/net_serv.cc b/sql/net_serv.cc index a6bc857..931f908 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -89,6 +89,58 @@ extern void thd_increment_bytes_received(size_t length); static my_bool net_write_buff(NET *, const uchar *, size_t); +/* 26 for regular timestamp, plus 7 (".123456") when using micro-seconds */ +static const int iso8601_size= 33; + + +static int make_iso8601_timestamp(char *buf, ulonglong utime= 0) +{ + struct tm my_tm; + char tzinfo[7]="Z"; // max 6 chars plus \0 + size_t len; + time_t seconds; + + if (utime == 0) + utime= my_micro_time(); + + seconds= utime / 1000000; + utime = utime % 1000000; + + localtime_r(&seconds, &my_tm); + +#ifdef __FreeBSD__ + /* + The field tm_gmtoff is the offset (in seconds) of the time represented + from UTC, with positive values indicating east of the Prime Meridian. + */ + long tim= -my_tm.tm_gmtoff; +#elif _WIN32 + long tim = _timezone; +#else + long tim= timezone; // seconds West of UTC. +#endif + char dir= '-'; + if (tim < 0) + { + dir= '+'; + tim= -tim; + } + my_snprintf(tzinfo, sizeof(tzinfo), "%c%02d:%02d", + dir, (int) (tim / (60 * 60)), (int) ((tim / 60) % 60)); + + len= my_snprintf(buf, iso8601_size, "%04d-%02d-%02dT%02d:%02d:%02d.%06lu%s", + my_tm.tm_year + 1900, + my_tm.tm_mon + 1, + my_tm.tm_mday, + my_tm.tm_hour, + my_tm.tm_min, + my_tm.tm_sec, + (unsigned long) utime, + tzinfo); + + return min(len, iso8601_size - 1); +} + /** Init with packet info. */ my_bool my_net_init(NET *net, Vio* vio) @@ -666,10 +718,20 @@ static my_bool net_read_raw_loop(NET *net, size_t count) bool eof= false; unsigned int retry_count= 0; uchar *buf= net->buff + net->where_b; + char my_timestamp[iso8601_size]; + int saved_errno= 0; while (count) { + saved_errno= socket_errno; + make_iso8601_timestamp(my_timestamp); + fprintf (stderr, "Func net_read_raw_loop(): Before vio_read(), " + "errno: %d, timestamp: %s\n", saved_errno, my_timestamp); + socket_errno= saved_errno; + size_t recvcnt= vio_read(net->vio, buf, count); + fprintf (stderr, "Func net_read_raw_loop(): After vio_read(), errno: %d ," + "recvcnt: %lu\n", socket_errno, (unsigned long)recvcnt); /* VIO_SOCKET_ERROR (-1) indicates an error. */ if (recvcnt == VIO_SOCKET_ERROR) diff --git a/vio/viosocket.c b/vio/viosocket.c index ee59292..9846185 100644 --- a/vio/viosocket.c +++ b/vio/viosocket.c @@ -783,6 +783,7 @@ int vio_io_wait(Vio *vio, enum enum_vio_io_event event, int timeout) Wait for the I/O event and return early in case of error or timeout. */ + fprintf(stderr, "Func: vio_io_wait(): Before poll(), errno: %d\n", socket_errno); switch ((ret= poll(&pfd, 1, timeout))) { case -1: @@ -801,6 +802,7 @@ int vio_io_wait(Vio *vio, enum enum_vio_io_event event, int timeout) break; } + fprintf(stderr, "Func: vio_io_wait(): After poll(), errno: %d\n", socket_errno); MYSQL_END_SOCKET_WAIT(locker, 0); DBUG_RETURN(ret); } diff --git a/vio/viossl.c b/vio/viossl.c index 5622cb7..0912677 100644 --- a/vio/viossl.c +++ b/vio/viossl.c @@ -21,7 +21,6 @@ */ #include "vio_priv.h" - #ifdef HAVE_OPENSSL #ifndef DBUG_OFF @@ -89,10 +88,17 @@ static void ssl_set_sys_error(int ssl_error) break; case SSL_ERROR_SYSCALL: case SSL_ERROR_NONE: + fprintf(stderr, "For SSL_ERROR_SYSCALL/SSL_ERROR_NONE, errno: %d\n", + socket_errno); + break; default: + if (errno == EINTR) + assert(0); break; }; + fprintf(stderr, "Func ssl_set_sys_error(): Before setting errno, " + "ssl_error: %d, errno: %d\n", ssl_error, socket_errno); /* Set error status to a equivalent of the SSL error. */ if (error) { @@ -102,6 +108,8 @@ static void ssl_set_sys_error(int ssl_error) errno= error; #endif } + fprintf(stderr, "Func ssl_set_sys_error(): After setting errno, " + "ssl_error: %d, errno: %d\n", ssl_error, socket_errno); } @@ -128,10 +136,13 @@ static my_bool ssl_should_retry(Vio *vio, int ret, int ssl_error; SSL *ssl= vio->ssl_arg; my_bool should_retry= TRUE; - + char ssl_error_str[MYSQL_ERRMSG_SIZE]; /* Retrieve the result for the SSL I/O operation. */ ssl_error= SSL_get_error(ssl, ret); - + /* Print the errors */ + ERR_error_string_n(ssl_error, ssl_error_str, MYSQL_ERRMSG_SIZE); + fprintf(stderr, "Error in ssl_should_retry(): ssl_error: %d, desc: %s, " + "socket_errno: %d\n", ssl_error, ssl_error_str, socket_errno); /* Retrieve the result for the SSL I/O operation. */ switch (ssl_error) { @@ -164,7 +175,7 @@ static my_bool ssl_should_retry(Vio *vio, int ret, size_t vio_ssl_read(Vio *vio, uchar *buf, size_t size) { - int ret; + int ret=0; SSL *ssl= vio->ssl_arg; unsigned long ssl_errno_not_used; @@ -182,12 +193,16 @@ size_t vio_ssl_read(Vio *vio, uchar *buf, size_t size) */ DBUG_ASSERT(ERR_peek_error() == 0); #endif + fprintf(stderr, "Func vio_ssl_read(): errno before SSL_read: %d, " + "ret value: %d\n", socket_errno, ret); ret= SSL_read(ssl, buf, (int)size); if (ret >= 0) break; + fprintf(stderr, "Func: vio_ssl_read(), errno after SSL_read: %d," + "ret value: %d\n", socket_errno, ret); /* Process the SSL I/O error. */ if (!ssl_should_retry(vio, ret, &event, &ssl_errno_not_used)) break;