@@ -295,6 +295,7 @@ def send_data(host,port)
295
295
end
296
296
sent_data = 0
297
297
sent_blocks = 0
298
+ send_retries = 0
298
299
expected_blocks = data_blocks . size
299
300
expected_size = data_blocks . join . size
300
301
if block_given?
@@ -304,7 +305,15 @@ def send_data(host,port)
304
305
data_blocks . each_with_index do |data_block , idx |
305
306
loop do
306
307
req = [ OpData , ( idx + 1 ) , data_block ] . pack ( "nnA*" )
307
- self . server_sock . sendto ( req , host , port )
308
+ if self . server_sock . sendto ( req , host , port ) <= 0
309
+ send_retries += 1
310
+ if send_retries > 100
311
+ break
312
+ else
313
+ next
314
+ end
315
+ end
316
+ send_retries = 0
308
317
res = self . server_sock . recvfrom ( 65535 )
309
318
if res
310
319
code , type , msg = parse_tftp_response ( res [ 0 ] )
@@ -326,13 +335,19 @@ def send_data(host,port)
326
335
end
327
336
end
328
337
end
338
+
339
+ if send_retries > 100
340
+ yield "Too many send retries, aborted"
341
+ end
342
+
329
343
if block_given?
330
344
if ( sent_data == expected_size )
331
345
yield ( "Transferred #{ sent_data } bytes in #{ sent_blocks } blocks, upload complete!" )
332
346
else
333
347
yield "Upload complete, but with errors."
334
348
end
335
349
end
350
+
336
351
if sent_data == expected_size
337
352
self . status = { :success => [
338
353
self . local_file ,
0 commit comments