diff options
Diffstat (limited to 'sql/net_serv.cc')
-rw-r--r-- | sql/net_serv.cc | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/sql/net_serv.cc b/sql/net_serv.cc index b53195da3b1..8e9dadc1dbf 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -36,9 +36,6 @@ HFTODO this must be hidden if we don't want client capabilities in embedded library */ -#ifdef __WIN__ -#include <winsock.h> -#endif #include <my_global.h> #include <mysql.h> #include <mysql_embed.h> @@ -50,7 +47,9 @@ #include <violite.h> #include <signal.h> #include <errno.h> - +#ifdef __WIN__ +#include <winsock.h> +#endif #ifdef __NETWARE__ #include <sys/select.h> #endif @@ -145,7 +144,7 @@ my_bool my_net_init(NET *net, Vio* vio) if (vio != 0) /* If real connection */ { net->fd = vio_fd(vio); /* For perl DBI/DBD */ -#if defined(MYSQL_SERVER) && !defined(__WIN__) && !defined(__EMX__) && !defined(OS2) +#if defined(MYSQL_SERVER) && !defined(__WIN__) if (!(test_flags & TEST_BLOCKING)) { my_bool old_mode; @@ -266,6 +265,7 @@ static int net_data_is_ready(my_socket sd) SYNOPSIS net_clear() net NET handler + clear_buffer If <> 0, then clear all data from communication buffer DESCRIPTION Read from socket until there is nothing more to read. Discard @@ -280,48 +280,51 @@ static int net_data_is_ready(my_socket sd) */ -void net_clear(NET *net) +void net_clear(NET *net, my_bool clear_buffer) { int count, ready; DBUG_ENTER("net_clear"); #if !defined(EMBEDDED_LIBRARY) - while((ready= net_data_is_ready(net->vio->sd)) > 0) + if (clear_buffer) { - /* The socket is ready */ - if ((count= vio_read(net->vio, (char*) (net->buff), - (uint32) net->max_packet)) > 0) + while ((ready= net_data_is_ready(net->vio->sd)) > 0) { - DBUG_PRINT("info",("skipped %d bytes from file: %s", - count, vio_description(net->vio))); + /* The socket is ready */ + if ((count= vio_read(net->vio, (char*) (net->buff), + (uint32) net->max_packet)) > 0) + { + DBUG_PRINT("info",("skipped %d bytes from file: %s", + count, vio_description(net->vio))); #ifdef EXTRA_DEBUG - fprintf(stderr,"skipped %d bytes from file: %s\n", - count, vio_description(net->vio)); + fprintf(stderr,"Error: net_clear() skipped %d bytes from file: %s\n", + count, vio_description(net->vio)); #endif + } + else + { + DBUG_PRINT("info",("socket ready but only EOF to read - disconnected")); + net->error= 2; + break; + } } - else - { - DBUG_PRINT("info",("socket ready but only EOF to read - disconnected")); - net->error= 2; - break; - } - } #ifdef NET_DATA_IS_READY_CAN_RETURN_MINUS_ONE - /* 'net_data_is_ready' returned "don't know" */ - if (ready == -1) - { - /* Read unblocking to clear net */ - my_bool old_mode; - if (!vio_blocking(net->vio, FALSE, &old_mode)) + /* 'net_data_is_ready' returned "don't know" */ + if (ready == -1) { - while ((count= vio_read(net->vio, (char*) (net->buff), - (uint32) net->max_packet)) > 0) - DBUG_PRINT("info",("skipped %d bytes from file: %s", - count, vio_description(net->vio))); - vio_blocking(net->vio, TRUE, &old_mode); + /* Read unblocking to clear net */ + my_bool old_mode; + if (!vio_blocking(net->vio, FALSE, &old_mode)) + { + while ((count= vio_read(net->vio, (char*) (net->buff), + (uint32) net->max_packet)) > 0) + DBUG_PRINT("info",("skipped %d bytes from file: %s", + count, vio_description(net->vio))); + vio_blocking(net->vio, TRUE, &old_mode); + } } +#endif /* NET_DATA_IS_READY_CAN_RETURN_MINUS_ONE */ } -#endif -#endif +#endif /* EMBEDDED_LIBRARY */ net->pkt_nr=net->compress_pkt_nr=0; /* Ready for new command */ net->write_pos=net->buff; DBUG_VOID_RETURN; @@ -612,7 +615,7 @@ net_real_write(NET *net,const char *packet,ulong len) if ((long) (length=vio_write(net->vio,pos,(uint32) (end-pos))) <= 0) { my_bool interrupted = vio_should_retry(net->vio); -#if (!defined(__WIN__) && !defined(__EMX__) && !defined(OS2)) +#if !defined(__WIN__) if ((interrupted || length==0) && !thr_alarm_in_use(&alarmed)) { if (!thr_alarm(&alarmed,(uint) net->write_timeout,&alarm_buff)) @@ -639,7 +642,7 @@ net_real_write(NET *net,const char *packet,ulong len) } } else -#endif /* (!defined(__WIN__) && !defined(__EMX__)) */ +#endif /* !defined(__WIN__) */ if (thr_alarm_in_use(&alarmed) && !thr_got_alarm(&alarmed) && interrupted) { @@ -811,7 +814,7 @@ my_real_read(NET *net, ulong *complen) DBUG_PRINT("info",("vio_read returned %ld, errno: %d", length, vio_errno(net->vio))); -#if (!defined(__WIN__) && !defined(__EMX__) && !defined(OS2)) || defined(MYSQL_SERVER) +#if !defined(__WIN__) || defined(MYSQL_SERVER) /* We got an error that there was no data on the socket. We now set up an alarm to not 'read forever', change the socket to non blocking @@ -847,7 +850,7 @@ my_real_read(NET *net, ulong *complen) continue; } } -#endif /* (!defined(__WIN__) && !defined(__EMX__)) || defined(MYSQL_SERVER) */ +#endif /* (!defined(__WIN__) || defined(MYSQL_SERVER) */ if (thr_alarm_in_use(&alarmed) && !thr_got_alarm(&alarmed) && interrupted) { /* Probably in MIT threads */ @@ -894,7 +897,7 @@ my_real_read(NET *net, ulong *complen) (int) net->buff[net->where_b + 3], net->pkt_nr)); #ifdef EXTRA_DEBUG - fprintf(stderr,"Packets out of order (Found: %d, expected %d)\n", + fprintf(stderr,"Error: Packets out of order (Found: %d, expected %d)\n", (int) net->buff[net->where_b + 3], (uint) (uchar) net->pkt_nr); #endif |