~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/net_serv.cc

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
 
83
83
  if (vio != 0)                    /* If real connection */
84
84
  {
85
 
    net->fd  = vio_fd(vio);            /* For perl DBI/DBD */
86
 
    vio_fastsend(vio);
 
85
    net->fd  = vio->get_fd();            /* For perl DBI/DBD */
 
86
    vio->fastsend();
87
87
  }
88
88
  return(0);
89
89
}
90
90
 
91
91
bool drizzleclient_net_init_sock(NET * net, int sock, uint32_t buffer_length)
92
92
{
93
 
  Vio *vio_tmp= mysql_protocol_vio_new(sock);
 
93
  Vio *vio_tmp= new Vio(sock);
94
94
  if (vio_tmp == NULL)
95
95
    return true;
96
96
  else
100
100
       * NET object.
101
101
       */
102
102
      if (vio_tmp && (net->vio != vio_tmp))
103
 
        vio_delete(vio_tmp);
 
103
        delete vio_tmp;
104
104
      else
105
105
      {
106
106
        (void) shutdown(sock, SHUT_RDWR);
123
123
{
124
124
  if (net->vio != NULL)
125
125
  {
126
 
    vio_delete(net->vio);
 
126
    delete net->vio;
127
127
    net->vio= 0;
128
128
  }
129
129
}
130
130
 
131
131
bool drizzleclient_net_peer_addr(NET *net, char *buf, uint16_t *port, size_t buflen)
132
132
{
133
 
  return vio_peer_addr(net->vio, buf, port, buflen);
 
133
  return net->vio->peer_addr(buf, port, buflen);
134
134
}
135
135
 
136
136
void drizzleclient_net_keepalive(NET *net, bool flag)
137
137
{
138
 
  vio_keepalive(net->vio, flag);
 
138
  net->vio->keepalive(flag);
139
139
}
140
140
 
141
141
int drizzleclient_net_get_sd(NET *net)
142
142
{
143
 
  return net->vio->sd;
 
143
  return net->vio->get_fd();
144
144
}
145
145
 
146
146
bool drizzleclient_net_more_data(NET *net)
147
147
{
148
 
  return (net->vio == 0 || net->vio->read_pos < net->vio->read_end);
 
148
  return (net->vio == 0 || net->vio->get_read_pos() < net->vio->get_read_end());
149
149
}
150
150
 
151
151
/** Realloc the packet buffer. */
158
158
  if (length >= net->max_packet_size)
159
159
  {
160
160
    /* @todo: 1 and 2 codes are identical. */
161
 
    net->error= 1;
 
161
    net->error= 3;
162
162
    net->last_errno= ER_NET_PACKET_TOO_LARGE;
163
163
    my_error(ER_NET_PACKET_TOO_LARGE, MYF(0));
164
164
    return(1);
232
232
{
233
233
  if (clear_buffer)
234
234
  {
235
 
    while (net_data_is_ready(net->vio->sd) > 0)
 
235
    while (net_data_is_ready(net->vio->get_fd()) > 0)
236
236
    {
237
237
      /* The socket is ready */
238
 
      if (vio_read(net->vio, net->buff, (size_t) net->max_packet) <= 0)
 
238
      if (net->vio->read(net->buff, (size_t) net->max_packet) <= 0)
239
239
      {
240
240
        net->error= 2;
241
241
        break;
527
527
  while (pos != end)
528
528
  {
529
529
    assert(pos);
530
 
    if ((long) (length= vio_write(net->vio, pos, (size_t) (end-pos))) <= 0)
 
530
    // TODO - see bug comment below - will we crash now?
 
531
    if ((long) (length= net->vio->write( pos, (size_t) (end-pos))) <= 0)
531
532
    {
532
533
     /*
533
534
      * We could end up here with net->vio == NULL
537
538
      if (net->vio == NULL)
538
539
        break;
539
540
      
540
 
      const bool interrupted= vio_should_retry(net->vio);
 
541
      const bool interrupted= net->vio->should_retry();
541
542
      /*
542
543
        If we read 0, or we were interrupted this means that
543
544
        we need to switch to blocking mode and wait until the timeout
547
548
      {
548
549
        bool old_mode;
549
550
 
550
 
        while (vio_blocking(net->vio, true, &old_mode) < 0)
 
551
        while (net->vio->blocking(true, &old_mode) < 0)
551
552
        {
552
 
          if (vio_should_retry(net->vio) && retry_count++ < net->retry_count)
 
553
          if (net->vio->should_retry() && retry_count++ < net->retry_count)
553
554
            continue;
554
555
          net->error= 2;                     /* Close socket */
555
556
          net->last_errno= ER_NET_PACKET_TOO_LARGE;
565
566
          continue;
566
567
      }
567
568
 
568
 
      if (vio_errno(net->vio) == EINTR)
 
569
      if (net->vio->get_errno() == EINTR)
569
570
      {
570
571
        continue;
571
572
      }
599
600
my_real_read(NET *net, size_t *complen)
600
601
{
601
602
  unsigned char *pos;
602
 
  size_t length;
 
603
  size_t length= 0;
603
604
  uint32_t i,retry_count=0;
604
605
  size_t len=packet_error;
605
606
  uint32_t remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
617
618
    while (remain > 0)
618
619
    {
619
620
      /* First read is done with non blocking mode */
620
 
      if ((long) (length= vio_read(net->vio, pos, remain)) <= 0L)
 
621
      if ((long) (length= net->vio->read(pos, remain)) <= 0L)
621
622
      {
622
623
        if (net->vio == NULL)
623
624
          goto end;
624
625
 
625
 
        const bool interrupted = vio_should_retry(net->vio);
 
626
        const bool interrupted = net->vio->should_retry();
626
627
 
627
628
        if (interrupted)
628
629
        {                    /* Probably in MIT threads */
629
630
          if (retry_count++ < net->retry_count)
630
631
            continue;
631
632
        }
632
 
        if (vio_errno(net->vio) == EINTR)
 
633
        if (net->vio->get_errno() == EINTR)
633
634
        {
634
635
          continue;
635
636
        }
636
637
        len= packet_error;
637
638
        net->error= 2;                /* Close socket */
638
 
        net->last_errno= (vio_was_interrupted(net->vio) ?
 
639
        net->last_errno= (net->vio->was_interrupted() ?
639
640
                          CR_NET_READ_INTERRUPTED :
640
641
                          CR_NET_READ_ERROR);
641
642
        goto end;
674
675
      {
675
676
        if (drizzleclient_net_realloc(net,helping))
676
677
        {
 
678
          /* Clear the buffer so libdrizzle doesn't keep retrying */
 
679
          while (len > 0)
 
680
          {
 
681
            length= read(net->vio->get_fd(), net->buff, min((size_t)net->max_packet, len));
 
682
            assert((long)length > 0L);
 
683
            len-= length;
 
684
          }
 
685
            
677
686
          len= packet_error;          /* Return error and close connection */
678
687
          goto end;
679
688
        }
862
871
  net->read_timeout= timeout;
863
872
#ifndef __sun
864
873
  if (net->vio)
865
 
    vio_timeout(net->vio, 0, timeout);
 
874
    net->vio->timeout(0, timeout);
866
875
#endif
867
876
  return;
868
877
}
873
882
  net->write_timeout= timeout;
874
883
#ifndef __sun
875
884
  if (net->vio)
876
 
    vio_timeout(net->vio, 1, timeout);
 
885
    net->vio->timeout(1, timeout);
877
886
#endif
878
887
  return;
879
888
}