@@ -242,10 +242,14 @@ async def _sock_sendfile_fail(sock, file, offset, count):
242242 ret = self .run_loop (self .loop .sock_sendfile (sock , f , offset , None ))
243243 else :
244244 ret = self .run_loop (self .loop .sock_sendfile (sock , f , offset , None ))
245+
245246 self .assertEqual (f .tell (), len (data ))
246- sock .close ()
247- self .run_loop (proto .wait_closed ())
248- self .assertEqual (ret , len (data ) - offset )
247+
248+ sock .close ()
249+ self .run_loop (proto .wait_closed ())
250+
251+ self .assertEqual (ret , len (data ) - offset )
252+
249253
250254 def test_sock_sendfile_offset (self ):
251255 data = b'abcdef'
@@ -254,6 +258,25 @@ def test_sock_sendfile_offset(self):
254258 with self .subTest (offset = offset , force_fallback = force_fallback ):
255259 self .check_sock_sendfile_offset (data , offset , force_fallback )
256260
261+
262+ def check_sendfile_offset (self , offset , fallback ):
263+ srv_proto , cli_proto = self .prepare_sendfile ()
264+ self .file .seek (123 )
265+ coro = self .loop .sendfile (cli_proto .transport , self .file , offset , fallback = fallback )
266+ ret = self .run_loop (coro )
267+ cli_proto .transport .close ()
268+ self .run_loop (srv_proto .done )
269+ self .assertEqual (ret , len (self .DATA ) - offset )
270+ self .assertEqual (srv_proto .nbytes , len (self .DATA ) - offset )
271+ self .assertEqual (srv_proto .data , self .DATA [offset :])
272+ self .assertEqual (self .file .tell (), len (self .DATA ))
273+
274+ def test_sendfile_offset (self ):
275+ for offset in (0 , len (self .DATA ) // 2 , len (self .DATA )):
276+ for fallback in (False , True ):
277+ with self .subTest (offset = offset , fallback = fallback ):
278+ self .check_sendfile_offset (offset , fallback )
279+
257280 def test_sock_sendfile_mix_with_regular_send (self ):
258281 buf = b"mix_regular_send" * (4 * 1024 ) # 64 KiB
259282 sock , proto = self .prepare_socksendfile ()
0 commit comments