~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/net_serv.cc

  • Committer: Brian Aker
  • Date: 2010-10-20 20:26:18 UTC
  • mfrom: (1859.2.13 refactor)
  • Revision ID: brian@tangent.org-20101020202618-9222n39lm329urv5
Merge for Brian 

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "vio.h"
38
38
#include "net_serv.h"
39
39
 
40
 
namespace drizzle_plugin
41
 
{
42
 
 
43
40
using namespace std;
44
41
using namespace drizzled;
45
42
 
85
82
 
86
83
  if (vio != 0)                    /* If real connection */
87
84
  {
88
 
    net->fd  = vio->get_fd();            /* For perl DBI/DBD */
89
 
    vio->fastsend();
 
85
    net->fd  = vio_fd(vio);            /* For perl DBI/DBD */
 
86
    vio_fastsend(vio);
90
87
  }
91
88
  return(0);
92
89
}
93
90
 
94
91
bool drizzleclient_net_init_sock(NET * net, int sock, uint32_t buffer_length)
95
92
{
96
 
  Vio *vio_tmp= new Vio(sock);
 
93
  Vio *vio_tmp= mysql_protocol_vio_new(sock);
97
94
  if (vio_tmp == NULL)
98
95
    return true;
99
96
  else
103
100
       * NET object.
104
101
       */
105
102
      if (vio_tmp && (net->vio != vio_tmp))
106
 
        delete vio_tmp;
 
103
        vio_delete(vio_tmp);
107
104
      else
108
105
      {
109
106
        (void) shutdown(sock, SHUT_RDWR);
126
123
{
127
124
  if (net->vio != NULL)
128
125
  {
129
 
    delete net->vio;
 
126
    vio_delete(net->vio);
130
127
    net->vio= 0;
131
128
  }
132
129
}
133
130
 
134
131
bool drizzleclient_net_peer_addr(NET *net, char *buf, uint16_t *port, size_t buflen)
135
132
{
136
 
  return net->vio->peer_addr(buf, port, buflen);
 
133
  return vio_peer_addr(net->vio, buf, port, buflen);
137
134
}
138
135
 
139
136
void drizzleclient_net_keepalive(NET *net, bool flag)
140
137
{
141
 
  net->vio->keepalive(flag);
 
138
  vio_keepalive(net->vio, flag);
142
139
}
143
140
 
144
141
int drizzleclient_net_get_sd(NET *net)
145
142
{
146
 
  return net->vio->get_fd();
 
143
  return net->vio->sd;
147
144
}
148
145
 
149
146
bool drizzleclient_net_more_data(NET *net)
150
147
{
151
 
  return (net->vio == 0 || net->vio->get_read_pos() < net->vio->get_read_end());
 
148
  return (net->vio == 0 || net->vio->read_pos < net->vio->read_end);
152
149
}
153
150
 
154
151
/** Realloc the packet buffer. */
161
158
  if (length >= net->max_packet_size)
162
159
  {
163
160
    /* @todo: 1 and 2 codes are identical. */
164
 
    net->error= 3;
 
161
    net->error= 1;
165
162
    net->last_errno= ER_NET_PACKET_TOO_LARGE;
166
163
    my_error(ER_NET_PACKET_TOO_LARGE, MYF(0));
167
164
    return(1);
235
232
{
236
233
  if (clear_buffer)
237
234
  {
238
 
    while (net_data_is_ready(net->vio->get_fd()) > 0)
 
235
    while (net_data_is_ready(net->vio->sd) > 0)
239
236
    {
240
237
      /* The socket is ready */
241
 
      if (net->vio->read(net->buff, (size_t) net->max_packet) <= 0)
 
238
      if (vio_read(net->vio, net->buff, (size_t) net->max_packet) <= 0)
242
239
      {
243
240
        net->error= 2;
244
241
        break;
530
527
  while (pos != end)
531
528
  {
532
529
    assert(pos);
533
 
    // TODO - see bug comment below - will we crash now?
534
 
    if ((long) (length= net->vio->write( pos, (size_t) (end-pos))) <= 0)
 
530
    if ((long) (length= vio_write(net->vio, pos, (size_t) (end-pos))) <= 0)
535
531
    {
536
532
     /*
537
533
      * We could end up here with net->vio == NULL
541
537
      if (net->vio == NULL)
542
538
        break;
543
539
      
544
 
      const bool interrupted= net->vio->should_retry();
 
540
      const bool interrupted= vio_should_retry(net->vio);
545
541
      /*
546
542
        If we read 0, or we were interrupted this means that
547
543
        we need to switch to blocking mode and wait until the timeout
551
547
      {
552
548
        bool old_mode;
553
549
 
554
 
        while (net->vio->blocking(true, &old_mode) < 0)
 
550
        while (vio_blocking(net->vio, true, &old_mode) < 0)
555
551
        {
556
 
          if (net->vio->should_retry() && retry_count++ < net->retry_count)
 
552
          if (vio_should_retry(net->vio) && retry_count++ < net->retry_count)
557
553
            continue;
558
554
          net->error= 2;                     /* Close socket */
559
555
          net->last_errno= ER_NET_PACKET_TOO_LARGE;
569
565
          continue;
570
566
      }
571
567
 
572
 
      if (net->vio->get_errno() == EINTR)
 
568
      if (vio_errno(net->vio) == EINTR)
573
569
      {
574
570
        continue;
575
571
      }
579
575
      break;
580
576
    }
581
577
    pos+=length;
582
 
 
583
 
    /* If this is an error we may not have a current_session any more */
584
 
    if (current_session)
585
 
      current_session->status_var.bytes_sent+= length;
 
578
    current_session->status_var.bytes_sent+= length;
586
579
  }
587
580
end:
588
581
  if ((net->compress) && (packet != NULL))
606
599
my_real_read(NET *net, size_t *complen)
607
600
{
608
601
  unsigned char *pos;
609
 
  size_t length= 0;
 
602
  size_t length;
610
603
  uint32_t i,retry_count=0;
611
604
  size_t len=packet_error;
612
605
  uint32_t remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
624
617
    while (remain > 0)
625
618
    {
626
619
      /* First read is done with non blocking mode */
627
 
      if ((long) (length= net->vio->read(pos, remain)) <= 0L)
 
620
      if ((long) (length= vio_read(net->vio, pos, remain)) <= 0L)
628
621
      {
629
622
        if (net->vio == NULL)
630
623
          goto end;
631
624
 
632
 
        const bool interrupted = net->vio->should_retry();
 
625
        const bool interrupted = vio_should_retry(net->vio);
633
626
 
634
627
        if (interrupted)
635
628
        {                    /* Probably in MIT threads */
636
629
          if (retry_count++ < net->retry_count)
637
630
            continue;
638
631
        }
639
 
        if (net->vio->get_errno() == EINTR)
 
632
        if (vio_errno(net->vio) == EINTR)
640
633
        {
641
634
          continue;
642
635
        }
643
636
        len= packet_error;
644
637
        net->error= 2;                /* Close socket */
645
 
        net->last_errno= (net->vio->was_interrupted() ?
 
638
        net->last_errno= (vio_was_interrupted(net->vio) ?
646
639
                          CR_NET_READ_INTERRUPTED :
647
640
                          CR_NET_READ_ERROR);
648
641
        goto end;
681
674
      {
682
675
        if (drizzleclient_net_realloc(net,helping))
683
676
        {
684
 
          /* Clear the buffer so libdrizzle doesn't keep retrying */
685
 
          while (len > 0)
686
 
          {
687
 
            length= read(net->vio->get_fd(), net->buff, min((size_t)net->max_packet, len));
688
 
            assert((long)length > 0L);
689
 
            len-= length;
690
 
          }
691
 
            
692
677
          len= packet_error;          /* Return error and close connection */
693
678
          goto end;
694
679
        }
877
862
  net->read_timeout= timeout;
878
863
#ifndef __sun
879
864
  if (net->vio)
880
 
    net->vio->timeout(0, timeout);
 
865
    vio_timeout(net->vio, 0, timeout);
881
866
#endif
882
867
  return;
883
868
}
888
873
  net->write_timeout= timeout;
889
874
#ifndef __sun
890
875
  if (net->vio)
891
 
    net->vio->timeout(1, timeout);
 
876
    vio_timeout(net->vio, 1, timeout);
892
877
#endif
893
878
  return;
894
879
}
904
889
  net->last_error[0]= '\0';
905
890
  strcpy(net->sqlstate, not_error_sqlstate);
906
891
}
907
 
 
908
 
} /* namespace drizzle_plugin */