@@ -461,19 +461,22 @@ class File
461
461
"""
462
462
Write pending data.
463
463
Returns false if the file wasn't opened with write permission.
464
- Returns raises error if not all the bytes were written.
464
+ Raises an error if not all the bytes were written.
465
465
Returns true if it sent all pending data.
466
466
Returns num_processed and new pending_total also.
467
467
"""
468
- // TODO: Make writev_batch_size user configurable
469
- let writev_batch_size = @pony_os_writev_max ()
470
468
var num_to_send: I32 = 0
471
469
var num_sent: USize = 0
472
470
var bytes_to_send: USize = 0
473
471
var pending_total = _pending_writev_total
474
- while
475
- writeable and (pending_total > 0 ) and (_fd != -1 )
476
- do
472
+
473
+ if (not writeable) or (_fd == -1 ) then
474
+ return (false , num_sent, pending_total)
475
+ end
476
+
477
+ // TODO: Make writev_batch_size user configurable
478
+ let writev_batch_size = @pony_os_writev_max ()
479
+ while pending_total > 0 do
477
480
//determine number of bytes and buffers to send
478
481
if (_pending_writev.size ().i32 ()/2 ) < writev_batch_size then
479
482
num_to_send = _pending_writev.size ().i32 ()/2
@@ -500,20 +503,14 @@ class File
500
503
num_to_send).isize ()
501
504
end
502
505
503
- if len < bytes_to_send.isize () then
504
- error
505
- else
506
- // sent all data we requested in this batch
507
- pending_total = pending_total - bytes_to_send
508
- num_sent = num_sent + num_to_send.usize ()
506
+ if len < bytes_to_send.isize () then error end
509
507
510
- if pending_total == 0 then
511
- return (true , num_sent, pending_total)
512
- end
513
- end
508
+ // sent all data we requested in this batch
509
+ pending_total = pending_total - bytes_to_send
510
+ num_sent = num_sent + num_to_send.usize ()
514
511
end
515
512
516
- (false , num_sent, pending_total)
513
+ (true , num_sent, pending_total)
517
514
518
515
fun ref position (): USize =>
519
516
"""
0 commit comments