~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/net_serv.c

  • Committer: Brian Aker
  • Date: 2008-07-16 17:02:56 UTC
  • Revision ID: brian@tangent.org-20080716170256-gu5w6539hs9v03i9
Removed alarm timeouts on writes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
423
423
    - TODO is it needed to set this variable if we have no socket
424
424
*/
425
425
 
 
426
/*
 
427
  TODO: rewrite this in a manner to do non-block writes. If a write can not be made, and we are
 
428
  in the server, yield to another process and come back later.
 
429
*/
426
430
int
427
431
net_real_write(NET *net,const uchar *packet, size_t len)
428
432
{
429
433
  size_t length;
430
434
  const uchar *pos,*end;
431
 
  thr_alarm_t alarmed;
432
 
  uint retry_count=0;
433
 
  my_bool net_blocking = vio_is_blocking(net->vio);
434
 
  DBUG_ENTER("net_real_write");
 
435
  uint retry_count= 0;
435
436
 
436
437
  if (net->error == 2)
437
438
    DBUG_RETURN(-1);                            /* socket can't be used */
462
463
    packet= b;
463
464
  }
464
465
 
465
 
#ifdef DEBUG_DATA_PACKETS
466
 
  DBUG_DUMP("data", packet, len);
467
 
#endif
468
 
 
469
 
  alarmed=0;
470
 
  /* Write timeout is set in my_net_set_write_timeout */
471
 
 
472
466
  pos= packet;
473
467
  end=pos+len;
 
468
  /* Loop until we have read everything */
474
469
  while (pos != end)
475
470
  {
476
471
    if ((long) (length= vio_write(net->vio,pos,(size_t) (end-pos))) <= 0)
477
472
    {
478
 
      my_bool interrupted = vio_should_retry(net->vio);
479
 
      if ((interrupted || length == 0) && !thr_alarm_in_use(&alarmed))
 
473
      my_bool interrupted= vio_should_retry(net->vio);
 
474
      /* 
 
475
        If we read 0, or we were interrupted this means that 
 
476
        we need to switch to blocking mode and wait until the timeout 
 
477
        on the socket kicks in.
 
478
      */
 
479
      if ((interrupted || length == 0))
480
480
      {
481
 
        if (!thr_alarm(&alarmed, net->write_timeout, &alarm_buff))
482
 
        {                                       /* Always true for client */
483
 
          bool old_mode;
484
 
          while (vio_blocking(net->vio, true, &old_mode) < 0)
485
 
          {
486
 
            if (vio_should_retry(net->vio) && retry_count++ < net->retry_count)
487
 
              continue;
488
 
#ifdef EXTRA_DEBUG
489
 
            fprintf(stderr,
490
 
                    "%s: my_net_write: fcntl returned error %d, aborting thread\n",
491
 
                    my_progname,vio_errno(net->vio));
492
 
#endif /* EXTRA_DEBUG */
493
 
            net->error= 2;                     /* Close socket */
494
 
            net->last_errno= ER_NET_PACKET_TOO_LARGE;
495
 
            goto end;
496
 
          }
497
 
          retry_count=0;
498
 
          continue;
499
 
        }
 
481
        bool old_mode;
 
482
 
 
483
        while (vio_blocking(net->vio, true, &old_mode) < 0)
 
484
        {
 
485
          if (vio_should_retry(net->vio) && retry_count++ < net->retry_count)
 
486
            continue;
 
487
          net->error= 2;                     /* Close socket */
 
488
          net->last_errno= ER_NET_PACKET_TOO_LARGE;
 
489
          goto end;
 
490
        }
 
491
        retry_count=0;
 
492
        continue;
500
493
      }
501
494
      else
502
 
        if (thr_alarm_in_use(&alarmed) && !thr_got_alarm(&alarmed) &&
503
 
            interrupted)
504
495
      {
505
 
        if (retry_count++ < net->retry_count)
506
 
            continue;
507
 
#ifdef EXTRA_DEBUG
508
 
          fprintf(stderr, "%s: write looped, aborting thread\n",
509
 
                  my_progname);
510
 
#endif /* EXTRA_DEBUG */
 
496
        if (retry_count++ < net->retry_count)
 
497
          continue;
511
498
      }
 
499
      
512
500
      if (vio_errno(net->vio) == SOCKET_EINTR)
513
501
      {
514
 
        DBUG_PRINT("warning",("Interrupted write. Retrying..."));
515
 
        continue;
 
502
        continue;
516
503
      }
517
504
      net->error= 2;                            /* Close socket */
518
505
      net->last_errno= (interrupted ? ER_NET_WRITE_INTERRUPTED :
519
 
                               ER_NET_ERROR_ON_WRITE);
 
506
                        ER_NET_ERROR_ON_WRITE);
520
507
      break;
521
508
    }
522
509
    pos+=length;
525
512
 end:
526
513
  if (net->compress)
527
514
    my_free((char*) packet,MYF(0));
528
 
  if (thr_alarm_in_use(&alarmed))
529
 
  {
530
 
    bool old_mode;
531
 
    thr_end_alarm(&alarmed);
532
 
    vio_blocking(net->vio, net_blocking, &old_mode);
533
 
  }
534
515
  net->reading_or_writing=0;
 
516
 
535
517
  DBUG_RETURN(((int) (pos != end)));
536
518
}
537
519