~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/net_serv.c

  • Committer: Stewart Smith
  • Date: 2008-09-15 07:13:59 UTC
  • mfrom: (383.1.21 drizzle)
  • mto: This revision was merged to the branch mainline in revision 408.
  • Revision ID: stewart@flamingspork.com-20080915071359-f8bznznyaiqrtqxa
merged

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <drizzle.h>
22
22
#include <drizzled/error.h>
23
23
#include <mysys/my_sys.h>
24
 
#include <mystrings/m_string.h>
25
24
#include <vio/violite.h>
26
25
#include <signal.h>
27
26
#include <errno.h>
37
36
*/
38
37
 
39
38
 
40
 
#define DONT_USE_THR_ALARM
41
 
 
42
 
#include <mysys/thr_alarm.h>
43
 
 
44
 
 
45
39
#define update_statistics(A)
46
40
#define thd_increment_bytes_sent(N)
47
41
 
118
112
    return(1);
119
113
  }
120
114
  net->buff=net->write_pos=buff;
121
 
  net->buff_end=buff+(net->max_packet= (ulong) pkt_length);
 
115
  net->buff_end=buff+(net->max_packet= (uint32_t) pkt_length);
122
116
  return(0);
123
117
}
124
118
 
136
130
    -1   Don't know if data is ready or not
137
131
*/
138
132
 
139
 
static int net_data_is_ready(my_socket sd)
 
133
static bool net_data_is_ready(int sd)
140
134
{
141
135
  struct pollfd ufds;
142
136
  int res;
170
164
 
171
165
void net_clear(NET *net, bool clear_buffer)
172
166
{
173
 
  size_t count;
174
 
  int32_t ready;
175
 
 
176
167
  if (clear_buffer)
177
168
  {
178
 
    while ((ready= net_data_is_ready(net->vio->sd)) > 0)
 
169
    while (net_data_is_ready(net->vio->sd) > 0)
179
170
    {
180
171
      /* The socket is ready */
181
 
      if ((long) (count= vio_read(net->vio, net->buff,
182
 
                                  (size_t) net->max_packet)) <= 0)
 
172
      if (vio_read(net->vio, net->buff,
 
173
                                  (size_t) net->max_packet) <= 0)
183
174
      {
184
175
        net->error= 2;
185
176
        break;
196
187
 
197
188
bool net_flush(NET *net)
198
189
{
199
 
  my_bool error= 0;
 
190
  bool error= 0;
200
191
  if (net->buff != net->write_pos)
201
192
  {
202
193
    error=test(net_real_write(net, net->buff,
237
228
  */
238
229
  while (len >= MAX_PACKET_LENGTH)
239
230
  {
240
 
    const ulong z_size = MAX_PACKET_LENGTH;
 
231
    const uint32_t z_size = MAX_PACKET_LENGTH;
241
232
    int3store(buff, z_size);
242
233
    buff[3]= (uchar) net->pkt_nr++;
243
234
    if (net_write_buff(net, buff, NET_HEADER_SIZE) ||
286
277
                  const uchar *header, size_t head_len,
287
278
                  const uchar *packet, size_t len)
288
279
{
289
 
  ulong length=len+1+head_len;                  /* 1 extra byte for command */
 
280
  uint32_t length=len+1+head_len;                       /* 1 extra byte for command */
290
281
  uchar buff[NET_HEADER_SIZE+1];
291
282
  uint header_size=NET_HEADER_SIZE+1;
292
283
 
348
339
static bool
349
340
net_write_buff(NET *net, const unsigned char *packet, uint32_t len)
350
341
{
351
 
  ulong left_length;
 
342
  uint32_t left_length;
352
343
  if (net->compress && net->max_packet > MAX_PACKET_LENGTH)
353
344
    left_length= MAX_PACKET_LENGTH - (net->write_pos - net->buff);
354
345
  else
355
 
    left_length= (ulong) (net->buff_end - net->write_pos);
 
346
    left_length= (uint32_t) (net->buff_end - net->write_pos);
356
347
 
357
348
  if (len > left_length)
358
349
  {
359
350
    if (net->write_pos != net->buff)
360
351
    {
361
352
      /* Fill up already used packet and write it */
362
 
      memcpy((char*) net->write_pos,packet,left_length);
 
353
      memcpy(net->write_pos,packet,left_length);
363
354
      if (net_real_write(net, net->buff, 
364
355
                         (size_t) (net->write_pos - net->buff) + left_length))
365
356
        return 1;
386
377
      return net_real_write(net, packet, len) ? 1 : 0;
387
378
    /* Send out rest of the blocks as full sized blocks */
388
379
  }
389
 
  memcpy((char*) net->write_pos,packet,len);
 
380
  memcpy(net->write_pos,packet,len);
390
381
  net->write_pos+= len;
391
382
  return 0;
392
383
}
423
414
  {
424
415
    size_t complen;
425
416
    uchar *b;
426
 
    uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE;
 
417
    const uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE;
427
418
    if (!(b= (uchar*) my_malloc(len + NET_HEADER_SIZE +
428
419
                                COMP_HEADER_SIZE, MYF(MY_WME))))
429
420
    {
473
464
  {
474
465
    if ((long) (length= vio_write(net->vio,pos,(size_t) (end-pos))) <= 0)
475
466
    {
476
 
      my_bool interrupted= vio_should_retry(net->vio);
 
467
      const bool interrupted= vio_should_retry(net->vio);
477
468
      /* 
478
469
        If we read 0, or we were interrupted this means that 
479
470
        we need to switch to blocking mode and wait until the timeout 
534
525
    Returns length of packet.
535
526
*/
536
527
 
537
 
static ulong
 
528
static uint32_t
538
529
my_real_read(NET *net, size_t *complen)
539
530
{
540
531
  uchar *pos;
541
532
  size_t length;
542
533
  uint i,retry_count=0;
543
 
  ulong len=packet_error;
 
534
  uint32_t len=packet_error;
544
535
  uint32_t remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
545
536
                  NET_HEADER_SIZE);
546
537
  /* Backup of the original SO_RCVTIMEO timeout */
585
576
      /* First read is done with non blocking mode */
586
577
      if ((long) (length= vio_read(net->vio, pos, remain)) <= 0L)
587
578
      {
588
 
        bool interrupted = vio_should_retry(net->vio);
 
579
        const bool interrupted = vio_should_retry(net->vio);
589
580
 
590
581
        if (interrupted)
591
582
        {                                       /* Probably in MIT threads */
601
592
        net->last_errno= (vio_was_interrupted(net->vio) ?
602
593
                          ER_NET_READ_INTERRUPTED :
603
594
                          ER_NET_READ_ERROR);
 
595
        my_error(net->last_errno, MYF(0));
604
596
        goto end;
605
597
      }
606
598
      remain -= (uint32_t) length;
609
601
    }
610
602
    if (i == 0)
611
603
    {                                   /* First parts is packet length */
612
 
      ulong helping;
 
604
      uint32_t helping;
613
605
 
614
606
      if (net->buff[net->where_b + 3] != (uchar) net->pkt_nr)
615
607
      {
683
675
    if (len == MAX_PACKET_LENGTH)
684
676
    {
685
677
      /* First packet of a multi-packet.  Concatenate the packets */
686
 
      ulong save_pos = net->where_b;
 
678
      uint32_t save_pos = net->where_b;
687
679
      size_t total_length= 0;
688
680
      do
689
681
      {
704
696
  {
705
697
    /* We are using the compressed protocol */
706
698
 
707
 
    ulong buf_length;
708
 
    ulong start_of_packet;
709
 
    ulong first_packet_offset;
 
699
    uint32_t buf_length;
 
700
    uint32_t start_of_packet;
 
701
    uint32_t first_packet_offset;
710
702
    uint read_length, multi_byte_packet=0;
711
703
 
712
704
    if (net->remain_in_buf)
724
716
    }
725
717
    for (;;)
726
718
    {
727
 
      ulong packet_len;
 
719
      uint32_t packet_len;
728
720
 
729
721
      if (buf_length - start_of_packet >= NET_HEADER_SIZE)
730
722
      {
793
785
 
794
786
    net->read_pos=      net->buff+ first_packet_offset + NET_HEADER_SIZE;
795
787
    net->buf_length=    buf_length;
796
 
    net->remain_in_buf= (ulong) (buf_length - start_of_packet);
797
 
    len = ((ulong) (start_of_packet - first_packet_offset) - NET_HEADER_SIZE -
 
788
    net->remain_in_buf= (uint32_t) (buf_length - start_of_packet);
 
789
    len = ((uint32_t) (start_of_packet - first_packet_offset) - NET_HEADER_SIZE -
798
790
           multi_byte_packet);
799
791
    net->save_char= net->read_pos[len]; /* Must be saved */
800
792
    net->read_pos[len]=0;               /* Safeguard for drizzle_use_result */