~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/net_serv.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <drizzled/current_session.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/session.h>
 
26
#include <drizzled/statistics_variables.h>
 
27
#include <drizzled/system_variables.h>
26
28
 
27
29
#include <assert.h>
28
30
#include <stdio.h>
39
41
#include "vio.h"
40
42
#include "net_serv.h"
41
43
 
42
 
namespace drizzle_plugin
43
 
{
 
44
namespace drizzle_plugin {
44
45
 
45
46
using namespace std;
46
47
using namespace drizzled;
59
60
#define COMP_HEADER_SIZE 3              /* compression header extra size */
60
61
 
61
62
#define MAX_PACKET_LENGTH (256L*256L*256L-1)
62
 
const char  *not_error_sqlstate= "00000";
63
63
 
64
 
static bool net_write_buff(NET *net, const unsigned char *packet, uint32_t len);
 
64
static bool net_write_buff(NET*, const void*, uint32_t len);
65
65
static int drizzleclient_net_real_write(NET *net, const unsigned char *packet, size_t len);
66
66
 
67
67
/** Init with packet info. */
68
68
 
69
 
bool drizzleclient_net_init(NET *net, Vio* vio, uint32_t buffer_length)
70
 
{
71
 
  net->vio = vio;
72
 
  net->max_packet= (uint32_t) buffer_length;
73
 
  net->max_packet_size= max(buffer_length, drizzled::global_system_variables.max_allowed_packet);
74
 
 
75
 
  if (!(net->buff=(unsigned char*) malloc((size_t) net->max_packet+
76
 
                                          NET_HEADER_SIZE + COMP_HEADER_SIZE)))
77
 
    return(1);
78
 
  net->buff_end=net->buff+net->max_packet;
79
 
  net->error=0; net->return_status=0;
80
 
  net->pkt_nr=net->compress_pkt_nr=0;
81
 
  net->write_pos=net->read_pos = net->buff;
82
 
  net->last_error[0]=0;
83
 
  net->compress=0; net->reading_or_writing=0;
84
 
  net->where_b = net->remain_in_buf=0;
85
 
  net->last_errno=0;
86
 
  net->unused= 0;
87
 
 
88
 
  if (vio != 0)                    /* If real connection */
89
 
  {
90
 
    net->fd  = vio->get_fd();            /* For perl DBI/DBD */
91
 
    vio->fastsend();
92
 
  }
93
 
  return(0);
94
 
}
95
 
 
96
 
bool drizzleclient_net_init_sock(NET * net, int sock, uint32_t buffer_length)
97
 
{
98
 
  Vio *vio_tmp= new Vio(sock);
99
 
  if (vio_tmp == NULL)
100
 
  {
101
 
    return true;
102
 
  }
103
 
  else
104
 
    if (drizzleclient_net_init(net, vio_tmp, buffer_length))
105
 
    {
106
 
      /* Only delete the temporary vio if we didn't already attach it to the
107
 
       * NET object.
108
 
       */
109
 
      if (vio_tmp && (net->vio != vio_tmp))
110
 
      {
111
 
        delete vio_tmp;
112
 
      }
113
 
      else
114
 
      {
115
 
        (void) shutdown(sock, SHUT_RDWR);
116
 
        (void) close(sock);
117
 
      }
118
 
      return true;
119
 
    }
120
 
  return false;
121
 
}
122
 
 
123
 
void drizzleclient_net_end(NET *net)
124
 
{
125
 
  if (net->buff != NULL)
126
 
    free(net->buff);
127
 
  net->buff= NULL;
128
 
  return;
129
 
}
130
 
 
131
 
void drizzleclient_net_close(NET *net)
132
 
{
133
 
  drizzled::safe_delete(net->vio);
134
 
}
135
 
 
136
 
bool drizzleclient_net_peer_addr(NET *net, char *buf, uint16_t *port, size_t buflen)
137
 
{
138
 
  return net->vio->peer_addr(buf, port, buflen);
139
 
}
140
 
 
141
 
void drizzleclient_net_keepalive(NET *net, bool flag)
142
 
{
143
 
  net->vio->keepalive(flag);
144
 
}
145
 
 
146
 
int drizzleclient_net_get_sd(NET *net)
147
 
{
148
 
  return net->vio->get_fd();
149
 
}
150
 
 
151
 
bool drizzleclient_net_more_data(NET *net)
152
 
{
153
 
  return (net->vio == 0 || net->vio->get_read_pos() < net->vio->get_read_end());
 
69
void NET::init(int sock, uint32_t buffer_length)
 
70
{
 
71
  vio= new Vio(sock);
 
72
  max_packet= (uint32_t) buffer_length;
 
73
  max_packet_size= max(buffer_length, drizzled::global_system_variables.max_allowed_packet);
 
74
 
 
75
  buff= (unsigned char*) malloc((size_t) max_packet + NET_HEADER_SIZE + COMP_HEADER_SIZE);
 
76
  buff_end= buff + max_packet;
 
77
  error_= 0;
 
78
  pkt_nr= compress_pkt_nr= 0;
 
79
  write_pos= read_pos= buff;
 
80
  compress= 0; 
 
81
  where_b= remain_in_buf= 0;
 
82
  last_errno= 0;
 
83
  vio->fastsend();
 
84
}
 
85
 
 
86
void NET::end()
 
87
{
 
88
  free(buff);
 
89
  buff= NULL;
 
90
}
 
91
 
 
92
void NET::close()
 
93
{
 
94
  drizzled::safe_delete(vio);
 
95
}
 
96
 
 
97
bool NET::peer_addr(char *buf, size_t buflen, uint16_t& port)
 
98
{
 
99
  return vio->peer_addr(buf, buflen, port);
 
100
}
 
101
 
 
102
void NET::keepalive(bool flag)
 
103
{
 
104
  vio->keepalive(flag);
 
105
}
 
106
 
 
107
int NET::get_sd() const
 
108
{
 
109
  return vio->get_fd();
154
110
}
155
111
 
156
112
/** Realloc the packet buffer. */
157
113
 
158
114
static bool drizzleclient_net_realloc(NET *net, size_t length)
159
115
{
160
 
  unsigned char *buff;
161
 
  size_t pkt_length;
162
 
 
163
116
  if (length >= net->max_packet_size)
164
117
  {
165
118
    /* @todo: 1 and 2 codes are identical. */
166
 
    net->error= 3;
 
119
    net->error_= 3;
167
120
    net->last_errno= ER_NET_PACKET_TOO_LARGE;
168
121
    my_error(ER_NET_PACKET_TOO_LARGE, MYF(0));
169
 
    return(1);
 
122
    return 1;
170
123
  }
171
 
  pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1);
 
124
  size_t pkt_length = (length + IO_SIZE - 1) & ~(IO_SIZE - 1);
172
125
  /*
173
126
    We must allocate some extra bytes for the end 0 and to be able to
174
127
    read big compressed blocks
175
128
  */
176
 
  if (!(buff= (unsigned char*) realloc((char*) net->buff, pkt_length +
177
 
                               NET_HEADER_SIZE + COMP_HEADER_SIZE)))
178
 
  {
179
 
    /* @todo: 1 and 2 codes are identical. */
180
 
    net->error= 1;
181
 
    net->last_errno= CR_OUT_OF_MEMORY;
182
 
    /* In the server the error is reported by MY_WME flag. */
183
 
    return(1);
184
 
  }
185
 
  net->buff=net->write_pos=buff;
186
 
  net->buff_end=buff+(net->max_packet= (uint32_t) pkt_length);
187
 
  return(0);
188
 
}
189
 
 
190
 
 
191
 
/**
192
 
   Check if there is any data to be read from the socket.
193
 
 
194
 
   @param sd   socket descriptor
195
 
 
196
 
   @retval
197
 
   0  No data to read
198
 
   @retval
199
 
   1  Data or EOF to read
200
 
   @retval
201
 
   -1   Don't know if data is ready or not
202
 
*/
203
 
 
204
 
static bool net_data_is_ready(int sd)
205
 
{
206
 
  struct pollfd ufds;
207
 
  int res;
208
 
 
209
 
  ufds.fd= sd;
210
 
  ufds.events= POLLIN | POLLPRI;
211
 
  if (!(res= poll(&ufds, 1, 0)))
212
 
    return 0;
213
 
  if (res < 0 || !(ufds.revents & (POLLIN | POLLPRI)))
214
 
    return 0;
215
 
  return 1;
216
 
}
217
 
 
218
 
/**
219
 
   Remove unwanted characters from connection
220
 
   and check if disconnected.
221
 
 
222
 
   Read from socket until there is nothing more to read. Discard
223
 
   what is read.
224
 
 
225
 
   If there is anything when to read 'drizzleclient_net_clear' is called this
226
 
   normally indicates an error in the protocol.
227
 
 
228
 
   When connection is properly closed (for TCP it means with
229
 
   a FIN packet), then select() considers a socket "ready to read",
230
 
   in the sense that there's EOF to read, but read() returns 0.
231
 
 
232
 
   @param net            NET handler
233
 
   @param clear_buffer           if <> 0, then clear all data from comm buff
234
 
*/
235
 
 
236
 
void drizzleclient_net_clear(NET *net, bool clear_buffer)
237
 
{
238
 
  if (clear_buffer)
239
 
  {
240
 
    while (net_data_is_ready(net->vio->get_fd()) > 0)
241
 
    {
242
 
      /* The socket is ready */
243
 
      if (net->vio->read(net->buff, (size_t) net->max_packet) <= 0)
244
 
      {
245
 
        net->error= 2;
246
 
        break;
247
 
      }
248
 
    }
249
 
  }
250
 
  net->pkt_nr=net->compress_pkt_nr=0;        /* Ready for new command */
251
 
  net->write_pos=net->buff;
252
 
  return;
253
 
}
254
 
 
255
 
 
256
 
/** Flush write_buffer if not empty. */
257
 
 
258
 
bool drizzleclient_net_flush(NET *net)
259
 
{
260
 
  bool error= 0;
261
 
  if (net->buff != net->write_pos)
262
 
  {
263
 
    error=drizzleclient_net_real_write(net, net->buff,
264
 
                         (size_t) (net->write_pos - net->buff)) ? 1 : 0;
265
 
    net->write_pos=net->buff;
 
129
  unsigned char* buff= (unsigned char*)realloc((char*) net->buff, pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE);
 
130
  net->buff=net->write_pos= buff;
 
131
  net->buff_end= buff + (net->max_packet= (uint32_t) pkt_length);
 
132
  return 0;
 
133
}
 
134
 
 
135
bool NET::flush()
 
136
{
 
137
  bool error= false;
 
138
  if (buff != write_pos)
 
139
  {
 
140
    error= drizzleclient_net_real_write(this, buff, write_pos - buff) ? true : false;
 
141
    write_pos= buff;
266
142
  }
267
143
  /* Sync packet number if using compression */
268
 
  if (net->compress)
269
 
    net->pkt_nr=net->compress_pkt_nr;
270
 
  return(error);
 
144
  if (compress)
 
145
    pkt_nr= compress_pkt_nr;
 
146
  return error;
271
147
}
272
148
 
273
149
 
285
161
   If compression is used the original package is modified!
286
162
*/
287
163
 
288
 
bool
289
 
drizzleclient_net_write(NET *net,const unsigned char *packet,size_t len)
 
164
static bool
 
165
drizzleclient_net_write(NET* net, const void* packet0, size_t len)
290
166
{
 
167
  const unsigned char* packet= reinterpret_cast<const unsigned char*>(packet0);
291
168
  unsigned char buff[NET_HEADER_SIZE];
292
169
  if (unlikely(!net->vio)) /* nowhere to write */
293
170
    return 0;
301
178
    const uint32_t z_size = MAX_PACKET_LENGTH;
302
179
    int3store(buff, z_size);
303
180
    buff[3]= (unsigned char) net->pkt_nr++;
304
 
    if (net_write_buff(net, buff, NET_HEADER_SIZE) ||
305
 
        net_write_buff(net, packet, z_size))
 
181
    if (net_write_buff(net, buff, NET_HEADER_SIZE) || net_write_buff(net, packet, z_size))
306
182
      return 1;
307
183
    packet += z_size;
308
184
    len-=     z_size;
310
186
  /* Write last packet */
311
187
  int3store(buff,len);
312
188
  buff[3]= (unsigned char) net->pkt_nr++;
313
 
  if (net_write_buff(net, buff, NET_HEADER_SIZE))
314
 
    return 1;
315
 
  return net_write_buff(net,packet,len) ? 1 : 0;
 
189
  return net_write_buff(net, buff, NET_HEADER_SIZE) || net_write_buff(net, packet, len);
316
190
}
317
191
 
318
192
/**
342
216
   1    error
343
217
*/
344
218
 
345
 
bool
 
219
static bool
346
220
drizzleclient_net_write_command(NET *net,unsigned char command,
347
221
                  const unsigned char *header, size_t head_len,
348
222
                  const unsigned char *packet, size_t len)
375
249
  }
376
250
  int3store(buff,length);
377
251
  buff[3]= (unsigned char) net->pkt_nr++;
378
 
  return((net_write_buff(net, buff, header_size) ||
 
252
  return (net_write_buff(net, buff, header_size) ||
379
253
          (head_len && net_write_buff(net, header, head_len)) ||
380
 
          net_write_buff(net, packet, len) || drizzleclient_net_flush(net)) ? 1 : 0 );
 
254
          net_write_buff(net, packet, len) || net->flush());
381
255
}
382
256
 
383
257
/**
407
281
*/
408
282
 
409
283
static bool
410
 
net_write_buff(NET *net, const unsigned char *packet, uint32_t len)
 
284
net_write_buff(NET* net, const void* packet0, uint32_t len)
411
285
{
 
286
  const unsigned char* packet= reinterpret_cast<const unsigned char*>(packet0);
412
287
  uint32_t left_length;
413
288
  if (net->compress && net->max_packet > MAX_PACKET_LENGTH)
414
289
    left_length= MAX_PACKET_LENGTH - (net->write_pos - net->buff);
468
343
static int
469
344
drizzleclient_net_real_write(NET *net, const unsigned char *packet, size_t len)
470
345
{
471
 
  size_t length;
472
 
  const unsigned char *pos, *end;
473
 
  uint32_t retry_count= 0;
474
 
 
475
346
  /* Backup of the original SO_RCVTIMEO timeout */
476
347
 
477
 
  if (net->error == 2)
 
348
  if (net->error_ == 2)
478
349
    return(-1);                /* socket can't be used */
479
350
 
480
 
  net->reading_or_writing=2;
481
351
  if (net->compress)
482
352
  {
483
 
    size_t complen;
484
 
    unsigned char *b;
485
353
    const uint32_t header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE;
486
 
    if (!(b= (unsigned char*) malloc(len + NET_HEADER_SIZE +
487
 
                             COMP_HEADER_SIZE)))
488
 
    {
489
 
      net->error= 2;
490
 
      net->last_errno= CR_OUT_OF_MEMORY;
491
 
      /* In the server, the error is reported by MY_WME flag. */
492
 
      net->reading_or_writing= 0;
493
 
      return(1);
494
 
    }
 
354
    unsigned char* b= (unsigned char*) malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE);
495
355
    memcpy(b+header_length,packet,len);
496
356
 
497
 
    complen= len * 120 / 100 + 12;
498
 
    unsigned char * compbuf= (unsigned char *) malloc(complen);
499
 
    if (compbuf != NULL)
500
 
    {
501
 
      uLongf tmp_complen= complen;
502
 
      int res= compress((Bytef*) compbuf, &tmp_complen,
503
 
                        (Bytef*) (b+header_length),
504
 
                        len);
505
 
      complen= tmp_complen;
506
 
 
507
 
      free(compbuf);
508
 
 
509
 
      if ((res != Z_OK) || (complen >= len))
510
 
        complen= 0;
511
 
      else
512
 
      {
513
 
        size_t tmplen= complen;
514
 
        complen= len;
515
 
        len= tmplen;
516
 
      }
517
 
    }
 
357
    size_t complen= len * 120 / 100 + 12;
 
358
    unsigned char* compbuf= new unsigned char[complen];
 
359
    uLongf tmp_complen= complen;
 
360
    int res= compress((Bytef*) compbuf, &tmp_complen,
 
361
      (Bytef*) (b+header_length),
 
362
      len);
 
363
    complen= tmp_complen;
 
364
 
 
365
    delete[] compbuf;
 
366
 
 
367
    if (res != Z_OK || complen >= len)
 
368
      complen= 0;
518
369
    else
519
370
    {
520
 
      complen=0;
 
371
      size_t tmplen= complen;
 
372
      complen= len;
 
373
      len= tmplen;
521
374
    }
522
375
    int3store(&b[NET_HEADER_SIZE],complen);
523
376
    int3store(b,len);
526
379
    packet= b;
527
380
  }
528
381
 
529
 
  pos= packet;
530
 
  end=pos+len;
 
382
  uint32_t retry_count= 0;
 
383
  const unsigned char* pos= packet;
 
384
  const unsigned char* end= pos + len;
531
385
  /* Loop until we have read everything */
532
386
  while (pos != end)
533
387
  {
534
388
    assert(pos);
535
389
    // TODO - see bug comment below - will we crash now?
 
390
    size_t length;
536
391
    if ((long) (length= net->vio->write( pos, (size_t) (end-pos))) <= 0)
537
392
    {
538
393
     /*
549
404
        we need to switch to blocking mode and wait until the timeout
550
405
        on the socket kicks in.
551
406
      */
552
 
      if ((interrupted || length == 0))
 
407
      if (interrupted || length == 0)
553
408
      {
554
409
        bool old_mode;
555
 
 
556
410
        while (net->vio->blocking(true, &old_mode) < 0)
557
411
        {
558
412
          if (net->vio->should_retry() && retry_count++ < net->retry_count)
559
413
            continue;
560
 
          net->error= 2;                     /* Close socket */
 
414
          net->error_= 2;                     /* Close socket */
561
415
          net->last_errno= ER_NET_PACKET_TOO_LARGE;
562
416
          my_error(ER_NET_PACKET_TOO_LARGE, MYF(0));
563
417
          goto end;
575
429
      {
576
430
        continue;
577
431
      }
578
 
      net->error= 2;                /* Close socket */
579
 
      net->last_errno= (interrupted ? CR_NET_WRITE_INTERRUPTED :
580
 
                        CR_NET_ERROR_ON_WRITE);
 
432
      net->error_= 2;                /* Close socket */
 
433
      net->last_errno= interrupted ? CR_NET_WRITE_INTERRUPTED : CR_NET_ERROR_ON_WRITE;
581
434
      break;
582
435
    }
583
 
    pos+=length;
 
436
    pos+= length;
584
437
 
585
438
    /* If this is an error we may not have a current_session any more */
586
439
    if (current_session)
587
440
      current_session->status_var.bytes_sent+= length;
588
441
  }
589
442
end:
590
 
  if ((net->compress) && (packet != NULL))
591
 
    free((char*) packet);
592
 
  net->reading_or_writing=0;
 
443
  if (net->compress)
 
444
    free((char*)packet);
593
445
 
594
 
  return(((int) (pos != end)));
 
446
  return (int) (pos != end);
595
447
}
596
448
 
597
449
 
607
459
static uint32_t
608
460
my_real_read(NET *net, size_t *complen)
609
461
{
610
 
  unsigned char *pos;
611
462
  size_t length= 0;
612
 
  uint32_t i,retry_count=0;
 
463
  uint32_t retry_count=0;
613
464
  size_t len=packet_error;
614
 
  uint32_t remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
615
 
                    NET_HEADER_SIZE);
 
465
  uint32_t remain= net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE : NET_HEADER_SIZE;
616
466
 
617
467
  *complen = 0;
618
468
 
619
 
  net->reading_or_writing= 1;
620
469
  /* Read timeout is set in drizzleclient_net_set_read_timeout */
621
470
 
622
 
  pos = net->buff + net->where_b;        /* net->packet -4 */
 
471
  unsigned char* pos = net->buff + net->where_b;        /* net->packet -4 */
623
472
 
624
 
  for (i= 0; i < 2 ; i++)
 
473
  for (uint32_t i= 0; i < 2 ; i++)
625
474
  {
626
475
    while (remain > 0)
627
476
    {
643
492
          continue;
644
493
        }
645
494
        len= packet_error;
646
 
        net->error= 2;                /* Close socket */
647
 
        net->last_errno= (net->vio->was_interrupted() ?
648
 
                          CR_NET_READ_INTERRUPTED :
649
 
                          CR_NET_READ_ERROR);
 
495
        net->error_= 2;                /* Close socket */
 
496
        net->last_errno= net->vio->was_interrupted() ? CR_NET_READ_INTERRUPTED : CR_NET_READ_ERROR;
650
497
        goto end;
651
498
      }
652
499
      remain -= (uint32_t) length;
701
548
  }
702
549
 
703
550
end:
704
 
  net->reading_or_writing= 0;
705
 
 
706
 
  return(len);
 
551
  return len;
707
552
}
708
553
 
709
554
 
723
568
   net->read_pos points to the read data.
724
569
*/
725
570
 
726
 
uint32_t
 
571
static uint32_t
727
572
drizzleclient_net_read(NET *net)
728
573
{
729
574
  size_t len, complen;
730
575
 
731
 
  if (!net->compress)
 
576
  if (not net->compress)
732
577
  {
733
578
    len = my_real_read(net,&complen);
734
579
    if (len == MAX_PACKET_LENGTH)
736
581
      /* First packet of a multi-packet.  Concatenate the packets */
737
582
      uint32_t save_pos = net->where_b;
738
583
      size_t total_length= 0;
 
584
 
739
585
      do
740
586
      {
741
587
        net->where_b += len;
742
588
        total_length += len;
743
589
        len = my_real_read(net,&complen);
744
590
      } while (len == MAX_PACKET_LENGTH);
 
591
 
745
592
      if (len != packet_error)
 
593
      {
746
594
        len+= total_length;
 
595
      }
747
596
      net->where_b = save_pos;
748
597
    }
749
598
    net->read_pos = net->buff + net->where_b;
 
599
 
750
600
    if (len != packet_error)
751
601
      net->read_pos[len]=0;        /* Safeguard for drizzleclient_use_result */
 
602
 
752
603
    return len;
753
604
  }
754
605
  else
846
697
 
847
698
          if (error != Z_OK)
848
699
          {
849
 
            net->error= 2;            /* caller will close socket */
 
700
            net->error_= 2;            /* caller will close socket */
850
701
            net->last_errno= CR_NET_UNCOMPRESS_ERROR;
851
702
          }
852
703
          else
873
724
    net->read_pos[len]=0;        /* Safeguard for drizzleclient_use_result */
874
725
  }
875
726
  return len;
876
 
  }
877
 
 
878
 
 
879
 
void drizzleclient_net_set_read_timeout(NET *net, uint32_t timeout)
880
 
{
881
 
  net->read_timeout= timeout;
882
 
#ifndef __sun
883
 
  if (net->vio)
884
 
    net->vio->timeout(0, timeout);
885
 
#endif
886
 
  return;
887
 
}
888
 
 
889
 
 
890
 
void drizzleclient_net_set_write_timeout(NET *net, uint32_t timeout)
891
 
{
892
 
  net->write_timeout= timeout;
893
 
#ifndef __sun
894
 
  if (net->vio)
895
 
    net->vio->timeout(1, timeout);
896
 
#endif
897
 
  return;
898
 
}
899
 
/**
900
 
  Clear possible error state of struct NET
901
 
 
902
 
  @param net  clear the state of the argument
903
 
*/
904
 
 
905
 
void drizzleclient_drizzleclient_net_clear_error(NET *net)
906
 
{
907
 
  net->last_errno= 0;
908
 
  net->last_error[0]= '\0';
909
 
  strcpy(net->sqlstate, not_error_sqlstate);
 
727
}
 
728
 
 
729
void NET::set_read_timeout(uint32_t timeout)
 
730
{
 
731
  read_timeout_= timeout;
 
732
#ifndef __sun
 
733
  if (vio)
 
734
    vio->timeout(0, timeout);
 
735
#endif
 
736
  return;
 
737
}
 
738
 
 
739
void NET::set_write_timeout(uint32_t timeout)
 
740
{
 
741
  write_timeout_= timeout;
 
742
#ifndef __sun
 
743
  if (vio)
 
744
    vio->timeout(1, timeout);
 
745
#endif
 
746
  return;
 
747
}
 
748
 
 
749
bool NET::write(const void* data, size_t size)
 
750
{
 
751
  return drizzleclient_net_write(this, data, size);
 
752
}
 
753
 
 
754
bool NET::write_command(unsigned char command, data_ref header, data_ref body)
 
755
{
 
756
  return drizzleclient_net_write_command(this, command, header.data(), header.size(), body.data(), body.size());
 
757
}
 
758
 
 
759
uint32_t NET::read()
 
760
{
 
761
  return drizzleclient_net_read(this);
910
762
}
911
763
 
912
764
} /* namespace drizzle_plugin */