~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/net_serv.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

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