~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzleclient/net_serv.c

  • Committer: Brian Aker
  • Date: 2009-02-05 10:38:55 UTC
  • Revision ID: brian@tangent.org-20090205103855-wajzccrbu7zbvmh4
Reworked some classes out of session.h
Also updated ignore file.

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
 
#define __need_timeval 1
22
 
 
 
21
#include <drizzled/global.h>
23
22
#include "libdrizzle.h"
24
23
#include "libdrizzle_priv.h"
25
 
#include <libdrizzle/errmsg.h>
26
 
#include <vio/violite.h>
 
24
#include "errmsg.h"
 
25
#include "vio.h"
27
26
#include <assert.h>
28
27
#include <stdio.h>
29
28
#include <stdlib.h>
44
43
*/
45
44
 
46
45
 
47
 
#define update_statistics(A)
48
 
#define thd_increment_bytes_sent(N)
49
 
 
50
 
#define TEST_BLOCKING        8
51
46
#define MAX_PACKET_LENGTH (256L*256L*256L-1)
52
 
#define MIN_COMPRESS_LENGTH             50      /* Don't compress small bl. */
53
47
 
54
48
static bool net_write_buff(NET *net, const unsigned char *packet, uint32_t len);
55
49
 
61
55
  net->vio = vio;
62
56
  my_net_local_init(net);            /* Set some limits */
63
57
  if (!(net->buff=(unsigned char*) malloc((size_t) net->max_packet+
64
 
                                  NET_HEADER_SIZE + COMP_HEADER_SIZE)))
 
58
                                          NET_HEADER_SIZE + COMP_HEADER_SIZE)))
65
59
    return(1);
66
60
  net->buff_end=net->buff+net->max_packet;
67
61
  net->error=0; net->return_status=0;
109
103
{
110
104
  if (net->buff != NULL)
111
105
    free(net->buff);
112
 
  net->buff=0;
 
106
  net->buff= NULL;
113
107
  return;
114
108
}
115
109
 
460
454
  in the server, yield to another process and come back later.
461
455
*/
462
456
int
463
 
net_real_write(NET *net,const unsigned char *packet, size_t len)
 
457
net_real_write(NET *net, const unsigned char *packet, size_t len)
464
458
{
465
459
  size_t length;
466
 
  const unsigned char *pos,*end;
 
460
  const unsigned char *pos, *end;
467
461
  uint32_t retry_count= 0;
468
462
 
469
463
  /* Backup of the original SO_RCVTIMEO timeout */
529
523
  if (net->write_timeout)
530
524
  {
531
525
    struct timespec waittime;
532
 
    socklen_t length;
 
526
    socklen_t time_len;
533
527
 
534
528
    waittime.tv_sec= net->write_timeout;
535
529
    waittime.tv_nsec= 0;
536
530
 
537
531
    memset(&backtime, 0, sizeof(struct timespec));
538
 
    length= sizeof(struct timespec);
 
532
    time_len= sizeof(struct timespec);
539
533
    error= getsockopt(net->vio->sd, SOL_SOCKET, SO_RCVTIMEO,
540
 
                      &backtime, &length);
 
534
                      &backtime, &time_len);
541
535
    if (error != 0)
542
536
    {
543
537
      perror("getsockopt");
554
548
  /* Loop until we have read everything */
555
549
  while (pos != end)
556
550
  {
557
 
    if ((long) (length= vio_write(net->vio,pos,(size_t) (end-pos))) <= 0)
 
551
    assert(pos);
 
552
    if ((long) (length= vio_write(net->vio, pos, (size_t) (end-pos))) <= 0)
558
553
    {
559
554
      const bool interrupted= vio_should_retry(net->vio);
560
555
      /*
593
588
      break;
594
589
    }
595
590
    pos+=length;
596
 
    update_statistics(thd_increment_bytes_sent(length));
597
591
  }
598
592
end:
599
593
  if ((net->compress) && (packet != NULL))
648
642
  if (net->read_timeout)
649
643
  {
650
644
    struct timespec waittime;
651
 
    socklen_t length;
 
645
    socklen_t time_len;
652
646
 
653
647
    waittime.tv_sec= net->read_timeout;
654
648
    waittime.tv_nsec= 0;
655
649
 
656
650
    memset(&backtime, 0, sizeof(struct timespec));
657
 
    length= sizeof(struct timespec);
 
651
    time_len= sizeof(struct timespec);
658
652
    error= getsockopt(net->vio->sd, SOL_SOCKET, SO_RCVTIMEO,
659
 
                      &backtime, &length);
 
653
                      &backtime, &time_len);
660
654
    if (error != 0)
661
655
    {
662
656
      perror("getsockopt");
696
690
      }
697
691
      remain -= (uint32_t) length;
698
692
      pos+= length;
699
 
      update_statistics(thd_increment_bytes_received(length));
700
693
    }
701
694
    if (i == 0)
702
695
    {                    /* First parts is packet length */