37
37
can't normally do this the client should have a bigger max_allowed_packet.
40
#if !defined(MYSQL_SERVER)
45
#include "my_pthread.h"
46
void sql_print_error(const char *format,...);
48
41
#define DONT_USE_THR_ALARM
51
43
#include "thr_alarm.h"
55
The following variables/functions should really not be declared
56
extern, but as it's hard to include mysql_priv.h here, we have to
57
live with this for a while.
59
extern uint test_flags;
60
extern ulong bytes_sent, bytes_received, net_big_packet_count;
61
#define update_statistics(A) A
62
#endif /* defined(MYSQL_SERVER) */
64
#if !defined(MYSQL_SERVER)
65
46
#define update_statistics(A)
66
47
#define thd_increment_bytes_sent(N)
69
49
#define TEST_BLOCKING 8
70
50
#define MAX_PACKET_LENGTH (256L*256L*256L-1)
96
76
if (vio != 0) /* If real connection */
98
78
net->fd = vio_fd(vio); /* For perl DBI/DBD */
99
#if defined(MYSQL_SERVER)
100
if (!(test_flags & TEST_BLOCKING))
103
vio_blocking(vio, FALSE, &old_mode);
106
79
vio_fastsend(vio);
536
503
DBUG_DUMP("data", packet, len);
540
thr_alarm_init(&alarmed);
542
thr_alarm(&alarmed, net->write_timeout, &alarm_buff);
545
507
/* Write timeout is set in my_net_set_write_timeout */
546
#endif /* NO_ALARM */
589
547
#endif /* EXTRA_DEBUG */
591
#if !defined(MYSQL_SERVER)
592
549
if (vio_errno(net->vio) == SOCKET_EINTR)
594
551
DBUG_PRINT("warning",("Interrupted write. Retrying..."));
597
#endif /* !defined(MYSQL_SERVER) */
598
554
net->error= 2; /* Close socket */
599
555
net->last_errno= (interrupted ? ER_NET_WRITE_INTERRUPTED :
600
556
ER_NET_ERROR_ON_WRITE);
602
my_error(net->last_errno, MYF(0));
603
#endif /* MYSQL_SERVER */
623
/*****************************************************************************
624
** Read something from server/clinet
625
*****************************************************************************/
629
static my_bool net_safe_read(NET *net, uchar *buff, size_t length,
630
thr_alarm_t *alarmed)
636
if ((long) (tmp= vio_read(net->vio, buff, length)) <= 0)
638
my_bool interrupted = vio_should_retry(net->vio);
639
if (!thr_got_alarm(alarmed) && interrupted)
640
{ /* Probably in MIT threads */
641
if (retry_count++ < net->retry_count)
653
Help function to clear the commuication buffer when we get a too big packet.
655
@param net Communication handle
656
@param remain Bytes to read
657
@param alarmed Parameter for thr_alarm()
658
@param alarm_buff Parameter for thr_alarm()
661
0 Was able to read the whole packet
663
1 Got mailformed packet from client
666
static my_bool my_net_skip_rest(NET *net, uint32 remain, thr_alarm_t *alarmed,
670
DBUG_ENTER("my_net_skip_rest");
671
DBUG_PRINT("enter",("bytes_to_skip: %u", (uint) remain));
673
/* The following is good for debugging */
674
update_statistics(thd_increment_net_big_packet_count(1));
676
if (!thr_alarm_in_use(alarmed))
679
if (thr_alarm(alarmed,net->read_timeout, alarm_buff) ||
680
vio_blocking(net->vio, TRUE, &old_mode) < 0)
681
DBUG_RETURN(1); /* Can't setup, abort */
687
size_t length= min(remain, net->max_packet);
688
if (net_safe_read(net, net->buff, length, alarmed))
690
update_statistics(thd_increment_bytes_received(length));
691
remain -= (uint32) length;
693
if (old != MAX_PACKET_LENGTH)
695
if (net_safe_read(net, net->buff, NET_HEADER_SIZE, alarmed))
697
old=remain= uint3korr(net->buff);
702
#endif /* NO_ALARM */
706
577
Reads one packet to net->buff + net->where_b.
707
578
Long packets are handled by my_net_read().
730
598
net->reading_or_writing=1;
731
599
thr_alarm_init(&alarmed);
734
thr_alarm(&alarmed,net->read_timeout,&alarm_buff);
736
600
/* Read timeout is set in my_net_set_read_timeout */
737
#endif /* NO_ALARM */
739
602
pos = net->buff + net->where_b; /* net->packet -4 */
740
603
for (i=0 ; i < 2 ; i++)
749
612
DBUG_PRINT("info",("vio_read returned %ld errno: %d",
750
613
(long) length, vio_errno(net->vio)));
751
#if defined(MYSQL_SERVER)
753
We got an error that there was no data on the socket. We now set up
754
an alarm to not 'read forever', change the socket to non blocking
757
if ((interrupted || length == 0) && !thr_alarm_in_use(&alarmed))
759
if (!thr_alarm(&alarmed,net->read_timeout,&alarm_buff)) /* Don't wait too long */
762
while (vio_blocking(net->vio, TRUE, &old_mode) < 0)
764
if (vio_should_retry(net->vio) &&
765
retry_count++ < net->retry_count)
768
("fcntl returned error %d, aborting thread",
769
vio_errno(net->vio)));
772
"%s: read: fcntl returned error %d, aborting thread\n",
773
my_progname,vio_errno(net->vio));
774
#endif /* EXTRA_DEBUG */
776
net->error= 2; /* Close socket */
777
net->last_errno= ER_NET_FCNTL_ERROR;
779
my_error(ER_NET_FCNTL_ERROR, MYF(0));
787
#endif /* defined(MYSQL_SERVER) */
788
614
if (thr_alarm_in_use(&alarmed) && !thr_got_alarm(&alarmed) &&
790
616
{ /* Probably in MIT threads */
795
621
my_progname,vio_errno(net->vio));
796
622
#endif /* EXTRA_DEBUG */
798
#if !defined(MYSQL_SERVER)
799
624
if (vio_errno(net->vio) == SOCKET_EINTR)
801
626
DBUG_PRINT("warning",("Interrupted read. Retrying..."));
805
629
DBUG_PRINT("error",("Couldn't read packet: remain: %u errno: %d length: %ld",
806
630
remain, vio_errno(net->vio), (long) length));
807
631
len= packet_error;
867
685
if (net_realloc(net,helping))
869
#if defined(MYSQL_SERVER) && !defined(NO_ALARM)
870
if (!net->compress &&
871
!my_net_skip_rest(net, (uint32) len, &alarmed, &alarm_buff))
872
net->error= 3; /* Successfully skiped packet */
874
687
len= packet_error; /* Return error and close connection */
1051
861
DBUG_ENTER("my_net_set_read_timeout");
1052
862
DBUG_PRINT("enter", ("timeout: %d", timeout));
1053
863
net->read_timeout= timeout;
1056
865
vio_timeout(net->vio, 0, timeout);
1058
866
DBUG_VOID_RETURN;
1064
872
DBUG_ENTER("my_net_set_write_timeout");
1065
873
DBUG_PRINT("enter", ("timeout: %d", timeout));
1066
874
net->write_timeout= timeout;
1069
876
vio_timeout(net->vio, 1, timeout);
1071
877
DBUG_VOID_RETURN;