@@ -206,11 +206,9 @@ def _call_connection_lost(self, exc: Exception | None) -> None:
206206 if not self ._closed_fut .done ():
207207 self ._closed_fut .set_result (None )
208208
209- # --- send path ---
210-
211209 def sendto (self , data : bytes , addr : tuple [str , int ] | None = None ) -> None : # type: ignore[override]
212210 if self ._closing :
213- raise RuntimeError ("Transport is closing" )
211+ raise OSError ("Transport is closing" )
214212
215213 target = addr or self ._address
216214 if not self ._write_ready :
@@ -235,7 +233,7 @@ def sendto_many(self, datagrams: list[bytes]) -> None:
235233 Falls back to individual ``sendto`` calls when GSO is not
236234 supported or the socket write buffer is full."""
237235 if self ._closing :
238- raise RuntimeError ("Transport is closing" )
236+ raise OSError ("Transport is closing" )
239237
240238 if not self ._write_ready :
241239 target = self ._address
@@ -324,8 +322,6 @@ def _on_write_ready(self) -> None:
324322 if self ._closing :
325323 self ._call_connection_lost (None )
326324
327- # --- recv path ---
328-
329325 def pause_reading (self ) -> None :
330326 if not self ._paused :
331327 self ._paused = True
@@ -540,6 +536,8 @@ def transport(self) -> asyncio.DatagramTransport:
540536 return self ._transport
541537
542538 def write (self , data : bytes | bytearray | memoryview | list [bytes ]) -> None :
539+ if self ._transport .is_closing ():
540+ raise OSError ("transport is closing" )
543541 if isinstance (data , list ):
544542 if hasattr (self ._transport , "sendto_many" ):
545543 self ._transport .sendto_many (data )
0 commit comments