423
423
- TODO is it needed to set this variable if we have no socket
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.
427
431
net_real_write(NET *net,const uchar *packet, size_t len)
430
434
const uchar *pos,*end;
433
my_bool net_blocking = vio_is_blocking(net->vio);
434
DBUG_ENTER("net_real_write");
436
437
if (net->error == 2)
437
438
DBUG_RETURN(-1); /* socket can't be used */
465
#ifdef DEBUG_DATA_PACKETS
466
DBUG_DUMP("data", packet, len);
470
/* Write timeout is set in my_net_set_write_timeout */
468
/* Loop until we have read everything */
474
469
while (pos != end)
476
471
if ((long) (length= vio_write(net->vio,pos,(size_t) (end-pos))) <= 0)
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);
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.
479
if ((interrupted || length == 0))
481
if (!thr_alarm(&alarmed, net->write_timeout, &alarm_buff))
482
{ /* Always true for client */
484
while (vio_blocking(net->vio, true, &old_mode) < 0)
486
if (vio_should_retry(net->vio) && retry_count++ < net->retry_count)
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;
483
while (vio_blocking(net->vio, true, &old_mode) < 0)
485
if (vio_should_retry(net->vio) && retry_count++ < net->retry_count)
487
net->error= 2; /* Close socket */
488
net->last_errno= ER_NET_PACKET_TOO_LARGE;
502
if (thr_alarm_in_use(&alarmed) && !thr_got_alarm(&alarmed) &&
505
if (retry_count++ < net->retry_count)
508
fprintf(stderr, "%s: write looped, aborting thread\n",
510
#endif /* EXTRA_DEBUG */
496
if (retry_count++ < net->retry_count)
512
500
if (vio_errno(net->vio) == SOCKET_EINTR)
514
DBUG_PRINT("warning",("Interrupted write. Retrying..."));
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);
526
513
if (net->compress)
527
514
my_free((char*) packet,MYF(0));
528
if (thr_alarm_in_use(&alarmed))
531
thr_end_alarm(&alarmed);
532
vio_blocking(net->vio, net_blocking, &old_mode);
534
515
net->reading_or_writing=0;
535
517
DBUG_RETURN(((int) (pos != end)));