File tree Expand file tree Collapse file tree 2 files changed +31
-4
lines changed
Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -215,8 +215,9 @@ def recvmsg(
215215 Receive a message from the socket.
216216 This is a mock implementation that reads from the MocketSocketIO.
217217 """
218- data = self .recv (buffersize )
219- if not data :
218+ try :
219+ data = self .recv (buffersize )
220+ except BlockingIOError :
220221 return b"" , []
221222
222223 # Mocking the ancillary data and flags as empty
@@ -236,8 +237,9 @@ def recvmsg_into(
236237 if not buffers :
237238 return 0
238239
239- data = self .recv (len (buffers [0 ]))
240- if not data :
240+ try :
241+ data = self .recv (len (buffers [0 ]))
242+ except BlockingIOError :
241243 return 0
242244
243245 for i , buffer in enumerate (buffers ):
Original file line number Diff line number Diff line change @@ -90,3 +90,28 @@ def test_sendmsg_empty_buffers():
9090 sock = MocketSocket (socket .AF_INET , socket .SOCK_STREAM )
9191 result = sock .sendmsg ([])
9292 assert result == 0
93+
94+
95+ def test_recvmsg_no_data ():
96+ sock = MocketSocket (socket .AF_INET , socket .SOCK_STREAM )
97+ # Mock _io.read to return empty bytes
98+ sock ._io = type ("MockIO" , (), {"read" : lambda self , n : b"" })()
99+ data , ancdata = sock .recvmsg (1024 )
100+ assert data == b""
101+ assert ancdata == []
102+
103+
104+ def test_recvmsg_into_no_data ():
105+ sock = MocketSocket (socket .AF_INET , socket .SOCK_STREAM )
106+ # Mock _io.read to return empty bytes
107+ sock ._io = type ("MockIO" , (), {"read" : lambda self , n : b"" })()
108+ buf = bytearray (10 )
109+ nbytes = sock .recvmsg_into ([buf ])
110+ assert nbytes == 0
111+ assert buf == bytearray (10 )
112+
113+
114+ def test_getsockopt ():
115+ # getsockopt is a static method, so we can call it directly
116+ result = MocketSocket .getsockopt (0 , 0 )
117+ assert result == socket .SOCK_STREAM
You can’t perform that action at this time.
0 commit comments