~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-07-28 23:07:42 UTC
  • mto: This revision was merged to the branch mainline in revision 1671.
  • Revision ID: brian@gaz-20100728230742-idji8pjd3trphd1a
Fix up a few additional cases around case insensitive usage for
unordered_map. This also places the code in util/string.h behind an
additional namespace of "util"

Show diffs side-by-side

added added

removed removed

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