~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/net_serv.cc

  • Committer: Stewart Smith
  • Date: 2010-07-27 00:49:32 UTC
  • mto: (1720.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 1721.
  • Revision ID: stewart@flamingspork.com-20100727004932-basq3vx9szmmbswm
fix storing and manipulating foreign keys in the proto around ALTER TABLE, CREATE TABLE and ALTER TABLE ADD/DROP FOREIGN KEY. We also (mostly) emulate the naming of innodb foreign keys in the upper layer.

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->get_fd();            /* For perl DBI/DBD */
86
 
    vio->fastsend();
 
85
    net->fd  = vio_fd(vio);            /* For perl DBI/DBD */
 
86
    vio_fastsend(vio);
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= new Vio(sock);
 
93
  Vio *vio_tmp= mysql_protocol_vio_new(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
 
        delete vio_tmp;
 
103
        vio_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
 
    delete net->vio;
 
126
    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 net->vio->peer_addr(buf, port, buflen);
 
133
  return 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
 
  net->vio->keepalive(flag);
 
138
  vio_keepalive(net->vio, flag);
139
139
}
140
140
 
141
141
int drizzleclient_net_get_sd(NET *net)
142
142
{
143
 
  return net->vio->get_fd();
 
143
  return net->vio->sd;
144
144
}
145
145
 
146
146
bool drizzleclient_net_more_data(NET *net)
147
147
{
148
 
  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);
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= 3;
 
161
    net->error= 1;
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->get_fd()) > 0)
 
235
    while (net_data_is_ready(net->vio->sd) > 0)
236
236
    {
237
237
      /* The socket is ready */
238
 
      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)
239
239
      {
240
240
        net->error= 2;
241
241
        break;
527
527
  while (pos != end)
528
528
  {
529
529
    assert(pos);
530
 
    // TODO - see bug comment below - will we crash now?
531
 
    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)
532
531
    {
533
532
     /*
534
533
      * We could end up here with net->vio == NULL
538
537
      if (net->vio == NULL)
539
538
        break;
540
539
      
541
 
      const bool interrupted= net->vio->should_retry();
 
540
      const bool interrupted= vio_should_retry(net->vio);
542
541
      /*
543
542
        If we read 0, or we were interrupted this means that
544
543
        we need to switch to blocking mode and wait until the timeout
548
547
      {
549
548
        bool old_mode;
550
549
 
551
 
        while (net->vio->blocking(true, &old_mode) < 0)
 
550
        while (vio_blocking(net->vio, true, &old_mode) < 0)
552
551
        {
553
 
          if (net->vio->should_retry() && retry_count++ < net->retry_count)
 
552
          if (vio_should_retry(net->vio) && retry_count++ < net->retry_count)
554
553
            continue;
555
554
          net->error= 2;                     /* Close socket */
556
555
          net->last_errno= ER_NET_PACKET_TOO_LARGE;
566
565
          continue;
567
566
      }
568
567
 
569
 
      if (net->vio->get_errno() == EINTR)
 
568
      if (vio_errno(net->vio) == EINTR)
570
569
      {
571
570
        continue;
572
571
      }
600
599
my_real_read(NET *net, size_t *complen)
601
600
{
602
601
  unsigned char *pos;
603
 
  size_t length= 0;
 
602
  size_t length;
604
603
  uint32_t i,retry_count=0;
605
604
  size_t len=packet_error;
606
605
  uint32_t remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
618
617
    while (remain > 0)
619
618
    {
620
619
      /* First read is done with non blocking mode */
621
 
      if ((long) (length= net->vio->read(pos, remain)) <= 0L)
 
620
      if ((long) (length= vio_read(net->vio, pos, remain)) <= 0L)
622
621
      {
623
622
        if (net->vio == NULL)
624
623
          goto end;
625
624
 
626
 
        const bool interrupted = net->vio->should_retry();
 
625
        const bool interrupted = vio_should_retry(net->vio);
627
626
 
628
627
        if (interrupted)
629
628
        {                    /* Probably in MIT threads */
630
629
          if (retry_count++ < net->retry_count)
631
630
            continue;
632
631
        }
633
 
        if (net->vio->get_errno() == EINTR)
 
632
        if (vio_errno(net->vio) == EINTR)
634
633
        {
635
634
          continue;
636
635
        }
637
636
        len= packet_error;
638
637
        net->error= 2;                /* Close socket */
639
 
        net->last_errno= (net->vio->was_interrupted() ?
 
638
        net->last_errno= (vio_was_interrupted(net->vio) ?
640
639
                          CR_NET_READ_INTERRUPTED :
641
640
                          CR_NET_READ_ERROR);
642
641
        goto end;
675
674
      {
676
675
        if (drizzleclient_net_realloc(net,helping))
677
676
        {
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
 
            
686
677
          len= packet_error;          /* Return error and close connection */
687
678
          goto end;
688
679
        }
871
862
  net->read_timeout= timeout;
872
863
#ifndef __sun
873
864
  if (net->vio)
874
 
    net->vio->timeout(0, timeout);
 
865
    vio_timeout(net->vio, 0, timeout);
875
866
#endif
876
867
  return;
877
868
}
882
873
  net->write_timeout= timeout;
883
874
#ifndef __sun
884
875
  if (net->vio)
885
 
    net->vio->timeout(1, timeout);
 
876
    vio_timeout(net->vio, 1, timeout);
886
877
#endif
887
878
  return;
888
879
}