|
51 | 51 | HOST = socket_helper.HOST |
52 | 52 | # test unicode string and carriage return |
53 | 53 | MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8') |
| 54 | +MSG2 = 'Monty Python test'.encode('utf-8') |
54 | 55 |
|
55 | 56 | VSOCKPORT = 1234 |
56 | 57 | AIX = platform.system() == "AIX" |
@@ -3308,20 +3309,32 @@ def _testRecvFromNegative(self): |
3308 | 3309 | @requireAttrs(socket, "MSG_TRUNC") |
3309 | 3310 | @unittest.skipIf(sys.platform == "win32", "Windows raises WSAEMSGSIZE") |
3310 | 3311 | def testRecvTrunc(self): |
3311 | | - msg = self.serv.recv(2, socket.MSG_TRUNC) |
3312 | | - self.assertEqual(msg, MSG[:2]) |
| 3312 | + # Truncated read where recv() returns the real size of the datagram |
| 3313 | + msg = self.serv.recv(5, socket.MSG_TRUNC) |
| 3314 | + self.assertEqual(msg, MSG[:5]) |
| 3315 | + |
| 3316 | + # Read the whole second datagram |
| 3317 | + msg = self.serv.recv(len(MSG2) + 5, socket.MSG_TRUNC) |
| 3318 | + self.assertEqual(msg, MSG2) |
3313 | 3319 |
|
3314 | 3320 | def _testRecvTrunc(self): |
3315 | 3321 | self.cli.sendto(MSG, 0, (HOST, self.port)) |
| 3322 | + self.cli.sendto(MSG2, 0, (HOST, self.port)) |
3316 | 3323 |
|
3317 | 3324 | @requireAttrs(socket, "MSG_TRUNC") |
3318 | 3325 | @unittest.skipIf(sys.platform == "win32", "Windows raises WSAEMSGSIZE") |
3319 | 3326 | def testRecvFromTrunc(self): |
3320 | | - msg, addr = self.serv.recvfrom(2, socket.MSG_TRUNC) |
3321 | | - self.assertEqual(msg, MSG[:2]) |
| 3327 | + # Truncated read where recvfrom() returns the real size of the datagram |
| 3328 | + msg, addr = self.serv.recvfrom(5, socket.MSG_TRUNC) |
| 3329 | + self.assertEqual(msg, MSG[:5]) |
| 3330 | + |
| 3331 | + # Read the whole second datagram |
| 3332 | + msg, addr = self.serv.recvfrom(len(MSG2) + 5, socket.MSG_TRUNC) |
| 3333 | + self.assertEqual(msg, MSG2) |
3322 | 3334 |
|
3323 | 3335 | def _testRecvFromTrunc(self): |
3324 | 3336 | self.cli.sendto(MSG, 0, (HOST, self.port)) |
| 3337 | + self.cli.sendto(MSG2, 0, (HOST, self.port)) |
3325 | 3338 |
|
3326 | 3339 |
|
3327 | 3340 | @unittest.skipUnless(HAVE_SOCKET_UDPLITE, |
|
0 commit comments