~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/net_serv.c

  • Committer: Monty Taylor
  • Date: 2008-10-02 01:27:37 UTC
  • Revision ID: monty@inaugust.com-20081002012737-3uxmdovii2l14uqe
Removed unused crud.

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
21
#include "libdrizzle.h"
23
22
#include "libdrizzle_priv.h"
24
23
#include <libdrizzle/errmsg.h>
43
42
*/
44
43
 
45
44
 
 
45
#define update_statistics(A)
 
46
#define thd_increment_bytes_sent(N)
 
47
 
 
48
#define TEST_BLOCKING        8
46
49
#define MAX_PACKET_LENGTH (256L*256L*256L-1)
 
50
#define MIN_COMPRESS_LENGTH             50      /* Don't compress small bl. */
47
51
 
48
52
static bool net_write_buff(NET *net, const unsigned char *packet, uint32_t len);
49
53
 
337
341
{
338
342
  uint32_t length=len+1+head_len;            /* 1 extra byte for command */
339
343
  unsigned char buff[NET_HEADER_SIZE+1];
340
 
  uint32_t header_size=NET_HEADER_SIZE+1;
 
344
  uint header_size=NET_HEADER_SIZE+1;
341
345
 
342
346
  buff[4]=command;                /* For first packet */
343
347
 
458
462
{
459
463
  size_t length;
460
464
  const unsigned char *pos,*end;
461
 
  uint32_t retry_count= 0;
 
465
  uint retry_count= 0;
462
466
 
463
467
  /* Backup of the original SO_RCVTIMEO timeout */
464
 
#ifndef __sun
465
 
  struct timespec backtime;
 
468
  struct timeval backtime;
466
469
  int error;
467
 
#endif
468
470
 
469
471
  if (net->error == 2)
470
472
    return(-1);                /* socket can't be used */
474
476
  {
475
477
    size_t complen;
476
478
    unsigned char *b;
477
 
    const uint32_t header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE;
 
479
    const uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE;
478
480
    if (!(b= (unsigned char*) malloc(len + NET_HEADER_SIZE +
479
481
                             COMP_HEADER_SIZE)))
480
482
    {
518
520
    packet= b;
519
521
  }
520
522
 
521
 
#ifndef __sun
522
523
  /* Check for error, currently assert */
523
524
  if (net->write_timeout)
524
525
  {
525
 
    struct timespec waittime;
 
526
    struct timeval waittime;
526
527
    socklen_t length;
527
528
 
528
529
    waittime.tv_sec= net->write_timeout;
529
 
    waittime.tv_nsec= 0;
 
530
    waittime.tv_usec= 0;
530
531
 
531
 
    memset(&backtime, 0, sizeof(struct timespec));
532
 
    length= sizeof(struct timespec);
 
532
    memset(&backtime, 0, sizeof(struct timeval));
 
533
    length= sizeof(struct timeval);
533
534
    error= getsockopt(net->vio->sd, SOL_SOCKET, SO_RCVTIMEO,
534
535
                      &backtime, &length);
535
536
    if (error != 0)
538
539
      assert(error == 0);
539
540
    }
540
541
    error= setsockopt(net->vio->sd, SOL_SOCKET, SO_RCVTIMEO,
541
 
                      &waittime, (socklen_t)sizeof(struct timespec));
 
542
                      &waittime, (socklen_t)sizeof(struct timeval));
542
543
    assert(error == 0);
543
544
  }
544
 
#endif
545
 
 
546
545
  pos= packet;
547
546
  end=pos+len;
548
547
  /* Loop until we have read everything */
587
586
      break;
588
587
    }
589
588
    pos+=length;
 
589
    update_statistics(thd_increment_bytes_sent(length));
590
590
  }
591
591
end:
592
592
  if ((net->compress) && (packet != NULL))
593
593
    free((char*) packet);
594
594
  net->reading_or_writing=0;
595
595
 
596
 
#ifndef __sun
597
596
  if (net->write_timeout)
598
597
    error= setsockopt(net->vio->sd, SOL_SOCKET, SO_RCVTIMEO,
599
 
                      &backtime, (socklen_t)sizeof(struct timespec));
600
 
#endif
 
598
                      &backtime, (socklen_t)sizeof(struct timeval));
601
599
 
602
600
  return(((int) (pos != end)));
603
601
}
617
615
{
618
616
  unsigned char *pos;
619
617
  size_t length;
620
 
  uint32_t i,retry_count=0;
 
618
  uint i,retry_count=0;
621
619
  uint32_t len=packet_error;
622
620
  uint32_t remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
623
621
                    NET_HEADER_SIZE);
624
 
 
625
 
#ifndef __sun
626
622
  /* Backup of the original SO_RCVTIMEO timeout */
627
 
  struct timespec backtime;
 
623
  struct timeval backtime;
628
624
  int error= 0;
629
 
#endif
630
625
 
631
626
  *complen = 0;
632
627
 
636
631
  pos = net->buff + net->where_b;        /* net->packet -4 */
637
632
 
638
633
 
639
 
#ifndef __sun
640
634
  /* Check for error, currently assert */
641
635
  if (net->read_timeout)
642
636
  {
643
 
    struct timespec waittime;
 
637
    struct timeval waittime;
644
638
    socklen_t length;
645
639
 
646
640
    waittime.tv_sec= net->read_timeout;
647
 
    waittime.tv_nsec= 0;
 
641
    waittime.tv_usec= 0;
648
642
 
649
 
    memset(&backtime, 0, sizeof(struct timespec));
650
 
    length= sizeof(struct timespec);
 
643
    memset(&backtime, 0, sizeof(struct timeval));
 
644
    length= sizeof(struct timeval);
651
645
    error= getsockopt(net->vio->sd, SOL_SOCKET, SO_RCVTIMEO,
652
646
                      &backtime, &length);
653
647
    if (error != 0)
656
650
      assert(error == 0);
657
651
    }
658
652
    error= setsockopt(net->vio->sd, SOL_SOCKET, SO_RCVTIMEO,
659
 
                      &waittime, (socklen_t)sizeof(struct timespec));
 
653
                      &waittime, (socklen_t)sizeof(struct timeval));
660
654
    assert(error == 0);
661
655
  }
662
 
#endif
663
656
 
664
657
  for (i= 0; i < 2 ; i++)
665
658
  {
689
682
      }
690
683
      remain -= (uint32_t) length;
691
684
      pos+= length;
 
685
      update_statistics(thd_increment_bytes_received(length));
692
686
    }
693
687
    if (i == 0)
694
688
    {                    /* First parts is packet length */
729
723
  }
730
724
 
731
725
end:
732
 
#ifndef __sun
733
726
  if  (net->read_timeout)
734
727
    error= setsockopt(net->vio->sd, SOL_SOCKET, SO_RCVTIMEO,
735
 
                      &backtime, (socklen_t)sizeof(struct timespec));
 
728
                      &backtime, (socklen_t)sizeof(struct timeval));
736
729
  assert(error == 0);
737
 
#endif
738
730
  net->reading_or_writing= 0;
739
731
 
740
732
  return(len);
792
784
    uint32_t buf_length;
793
785
    uint32_t start_of_packet;
794
786
    uint32_t first_packet_offset;
795
 
    uint32_t read_length, multi_byte_packet=0;
 
787
    uint read_length, multi_byte_packet=0;
796
788
 
797
789
    if (net->remain_in_buf)
798
790
    {
908
900
  }
909
901
 
910
902
 
911
 
void my_net_set_read_timeout(NET *net, uint32_t timeout)
 
903
void my_net_set_read_timeout(NET *net, uint timeout)
912
904
{
913
905
  net->read_timeout= timeout;
914
 
#ifndef __sun
915
906
  if (net->vio)
916
907
    vio_timeout(net->vio, 0, timeout);
917
 
#endif
918
908
  return;
919
909
}
920
910
 
921
911
 
922
 
void my_net_set_write_timeout(NET *net, uint32_t timeout)
 
912
void my_net_set_write_timeout(NET *net, uint timeout)
923
913
{
924
914
  net->write_timeout= timeout;
925
 
#ifndef __sun
926
915
  if (net->vio)
927
916
    vio_timeout(net->vio, 1, timeout);
928
 
#endif
929
917
  return;
930
918
}
931
919
/**