~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/net_serv.cc

  • Committer: Tim Penhey
  • Date: 2010-01-20 02:39:01 UTC
  • mto: This revision was merged to the branch mainline in revision 1275.
  • Revision ID: tim.penhey@canonical.com-20100120023901-8teeunid6gwlthzx
Add in a rot 13 function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "config.h"
22
22
#include <drizzled/session.h>
23
 
#include <drizzled/error.h>
24
23
 
25
24
#include <assert.h>
26
25
#include <stdio.h>
38
37
#include "net_serv.h"
39
38
 
40
39
using namespace std;
41
 
using namespace drizzled;
42
40
 
43
41
/*
44
42
  The following handles the differences when this is linked between the
65
63
{
66
64
  net->vio = vio;
67
65
  net->max_packet= (uint32_t) buffer_length;
68
 
  net->max_packet_size= max(buffer_length, drizzled::global_system_variables.max_allowed_packet);
 
66
  net->max_packet_size= max(buffer_length, global_system_variables.max_allowed_packet);
69
67
 
70
68
  if (!(net->buff=(unsigned char*) malloc((size_t) net->max_packet+
71
69
                                          NET_HEADER_SIZE + COMP_HEADER_SIZE)))
82
80
 
83
81
  if (vio != 0)                    /* If real connection */
84
82
  {
85
 
    net->fd  = vio_fd(vio);            /* For perl DBI/DBD */
86
 
    vio_fastsend(vio);
 
83
    net->fd  = drizzleclient_vio_fd(vio);            /* For perl DBI/DBD */
 
84
    drizzleclient_vio_fastsend(vio);
87
85
  }
88
86
  return(0);
89
87
}
90
88
 
91
 
bool drizzleclient_net_init_sock(NET * net, int sock, uint32_t buffer_length)
 
89
bool drizzleclient_net_init_sock(NET * net, int sock, int flags,
 
90
                                 uint32_t buffer_length)
92
91
{
93
 
  Vio *vio_tmp= mysql_protocol_vio_new(sock);
94
 
  if (vio_tmp == NULL)
 
92
 
 
93
  Vio *drizzleclient_vio_tmp= drizzleclient_vio_new(sock, VIO_TYPE_TCPIP, flags);
 
94
  if (drizzleclient_vio_tmp == NULL)
95
95
    return true;
96
96
  else
97
 
    if (drizzleclient_net_init(net, vio_tmp, buffer_length))
 
97
    if (drizzleclient_net_init(net, drizzleclient_vio_tmp, buffer_length))
98
98
    {
99
99
      /* Only delete the temporary vio if we didn't already attach it to the
100
100
       * NET object.
101
101
       */
102
 
      if (vio_tmp && (net->vio != vio_tmp))
103
 
        vio_delete(vio_tmp);
 
102
      if (drizzleclient_vio_tmp && (net->vio != drizzleclient_vio_tmp))
 
103
        drizzleclient_vio_delete(drizzleclient_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
    drizzleclient_vio_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 drizzleclient_vio_peer_addr(net->vio, 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
  drizzleclient_vio_keepalive(net->vio, flag);
139
139
}
140
140
 
141
141
int drizzleclient_net_get_sd(NET *net)
159
159
  {
160
160
    /* @todo: 1 and 2 codes are identical. */
161
161
    net->error= 1;
162
 
    net->last_errno= ER_NET_PACKET_TOO_LARGE;
163
 
    my_error(ER_NET_PACKET_TOO_LARGE, MYF(0));
 
162
    net->last_errno= CR_NET_PACKET_TOO_LARGE;
164
163
    return(1);
165
164
  }
166
165
  pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1);
235
234
    while (net_data_is_ready(net->vio->sd) > 0)
236
235
    {
237
236
      /* The socket is ready */
238
 
      if (vio_read(net->vio, net->buff, (size_t) net->max_packet) <= 0)
 
237
      if (drizzleclient_vio_read(net->vio, net->buff,
 
238
                   (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
    if ((long) (length= drizzleclient_vio_write(net->vio, pos, (size_t) (end-pos))) <= 0)
531
531
    {
532
532
     /*
533
533
      * We could end up here with net->vio == NULL
537
537
      if (net->vio == NULL)
538
538
        break;
539
539
      
540
 
      const bool interrupted= vio_should_retry(net->vio);
 
540
      const bool interrupted= drizzleclient_vio_should_retry(net->vio);
541
541
      /*
542
542
        If we read 0, or we were interrupted this means that
543
543
        we need to switch to blocking mode and wait until the timeout
547
547
      {
548
548
        bool old_mode;
549
549
 
550
 
        while (vio_blocking(net->vio, true, &old_mode) < 0)
 
550
        while (drizzleclient_vio_blocking(net->vio, true, &old_mode) < 0)
551
551
        {
552
 
          if (vio_should_retry(net->vio) && retry_count++ < net->retry_count)
 
552
          if (drizzleclient_vio_should_retry(net->vio) && retry_count++ < net->retry_count)
553
553
            continue;
554
554
          net->error= 2;                     /* Close socket */
555
 
          net->last_errno= ER_NET_PACKET_TOO_LARGE;
556
 
          my_error(ER_NET_PACKET_TOO_LARGE, MYF(0));
 
555
          net->last_errno= CR_NET_PACKET_TOO_LARGE;
557
556
          goto end;
558
557
        }
559
558
        retry_count=0;
565
564
          continue;
566
565
      }
567
566
 
568
 
      if (vio_errno(net->vio) == EINTR)
 
567
      if (drizzleclient_vio_errno(net->vio) == EINTR)
569
568
      {
570
569
        continue;
571
570
      }
616
615
    while (remain > 0)
617
616
    {
618
617
      /* First read is done with non blocking mode */
619
 
      if ((long) (length= vio_read(net->vio, pos, remain)) <= 0L)
 
618
      if ((long) (length= drizzleclient_vio_read(net->vio, pos, remain)) <= 0L)
620
619
      {
621
620
        if (net->vio == NULL)
622
621
          goto end;
623
622
 
624
 
        const bool interrupted = vio_should_retry(net->vio);
 
623
        const bool interrupted = drizzleclient_vio_should_retry(net->vio);
625
624
 
626
625
        if (interrupted)
627
626
        {                    /* Probably in MIT threads */
628
627
          if (retry_count++ < net->retry_count)
629
628
            continue;
630
629
        }
631
 
        if (vio_errno(net->vio) == EINTR)
 
630
        if (drizzleclient_vio_errno(net->vio) == EINTR)
632
631
        {
633
632
          continue;
634
633
        }
635
634
        len= packet_error;
636
635
        net->error= 2;                /* Close socket */
637
 
        net->last_errno= (vio_was_interrupted(net->vio) ?
 
636
        net->last_errno= (drizzleclient_vio_was_interrupted(net->vio) ?
638
637
                          CR_NET_READ_INTERRUPTED :
639
638
                          CR_NET_READ_ERROR);
 
639
        ER(net->last_errno);
640
640
        goto end;
641
641
      }
642
642
      remain -= (uint32_t) length;
650
650
      {
651
651
        len= packet_error;
652
652
        /* Not a NET error on the client. XXX: why? */
653
 
        my_error(ER_NET_PACKETS_OUT_OF_ORDER, MYF(0));
654
653
        goto end;
655
654
      }
656
655
      net->compress_pkt_nr= ++net->pkt_nr;
860
859
  net->read_timeout= timeout;
861
860
#ifndef __sun
862
861
  if (net->vio)
863
 
    vio_timeout(net->vio, 0, timeout);
 
862
    drizzleclient_vio_timeout(net->vio, 0, timeout);
864
863
#endif
865
864
  return;
866
865
}
871
870
  net->write_timeout= timeout;
872
871
#ifndef __sun
873
872
  if (net->vio)
874
 
    vio_timeout(net->vio, 1, timeout);
 
873
    drizzleclient_vio_timeout(net->vio, 1, timeout);
875
874
#endif
876
875
  return;
877
876
}
887
886
  net->last_error[0]= '\0';
888
887
  strcpy(net->sqlstate, not_error_sqlstate);
889
888
}
 
889