![]() |
![]() |
![]() |
#1 | |
Registered User
![]() Join Date: Mar 2016
Location: Germany
Posts: 73
|
Peeking UDP datagrams doesn't work with WinUAE's bsdsocket.library
It seems like WinUAE's bsdsocket.library can't peek UDP datagrams. On real hardware it works fine, though. My TCP/IP stack on real hardware is Genesis. It also works on MorphOS and OS4 so it really looks like a WinUAE bsdsocket.library bug.
To reproduce, run the attached program in two separate shells. In the first shell, run "udptest s" to start the server. In the second shell, run "udptest c" to start the client. The client will try to send "Hello World" to the server while the server will continually peek the queue and report what's in it. On my WinUAE test system, the server will always print "TAKEN: -1", i.e. nothing in the queue. On real hardware using Genesis, the server will report "TAKEN: 1" as soon as the client program has been run. Here's the udptest program: https://easyupload.io/5l81j9 Here's the source code: https://easyupload.io/d9zsz8 And here's an unformatted copy & paste of the source code: Quote:
|
|
![]() |
![]() |
#2 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 45
Posts: 24,647
|
This test won't really tell anything else than that UDP data is not received. For some reason (Windows firewall?)
Do you mean you get data if you don't use MSG_PEEK? |
![]() |
![]() |
#3 |
Registered User
![]() Join Date: Mar 2016
Location: Germany
Posts: 73
|
Right, so I don't get data without MSG_PEEK either. But disabling the Windows firewall doesn't help. It just doesn't work.
So is this a problem on my system only? Can you reproduce it? |
![]() |
![]() |
#4 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 45
Posts: 24,647
|
Same happens here. WinUAE forwards correct data to winsock sendto() and recvfrom() parameters are also correct so this must be some Windows feature.
recvfrom() also returns EWOULDBLOCK so there really is no data available. Perhaps the reason is that reader uses Windows current IP but writer uses 127.0.0.1? |
![]() |
![]() |
#5 |
Registered User
![]() Join Date: Mar 2016
Location: Germany
Posts: 73
|
IIRC I think there are a few incompatibilities between Winsock and Unix sockets. So this might be one of them?!
FWIW I just tried the program on Ubuntu and it works fine there as well so it really looks like a Windows issue but of course WinUAE should try to work around that then so that bsdsocket.library's behaviour is identical between WinUAE and real Amiga hardware... |
![]() |
![]() |
#6 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 45
Posts: 24,647
|
First someone needs to find whats the difference and why.. UAE bsdsocket.library emulation is basically a pipe between Amiga bsdsocket and host bsdsocket, there is not much it can fake.
|
![]() |
![]() |
#7 |
Registered User
![]() Join Date: Mar 2016
Location: Germany
Posts: 73
|
Ok, so I've compiled the program for Windows and analyzed what's going on. There is indeed a difference in behaviour when it comes to MSG_PEEK. On Windows, recvfrom() with MSG_PEEK will return -1 and set WSAEMSGSIZE if the provided buffer isn't large enough for what's in the socket. This doesn't happen with Unix/Amiga sockets. On Unix/Amiga recvfrom() with MSG_PEEK won't fail if the buffer is smaller than the data in the socket. So this is what should be fixed in WinUAE.
Here is the Windows test program: https://easyupload.io/zxlx75 And the source code: https://easyupload.io/wa1eht If you do some googling, you'll also notice that some other projects which map the Unix socket API directly to Winsock had to deal with this issue as well, see here for example: https://cygwin.cygwin.narkive.com/sB...sg-peek-broken |
![]() |
![]() |
#8 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 45
Posts: 24,647
|
Right, seems simple enough to work around.
Does this affect both UDP and TCP sockets? (I wasn't sure after few net searchs..) EDIT: and what should happen if buffer size is zero? EDIT2: also does it only affect MSG_PEEK? Non-MSG_PEEK reads work "correctly" already? Last edited by Toni Wilen; 06 November 2020 at 18:25. |
![]() |
![]() |
#9 |
Registered User
![]() Join Date: Mar 2016
Location: Germany
Posts: 73
|
From my tests only UDP sockets are affected. The Cygwin guys in the thread linked above also seem to have had the problem with UDP sockets only.
When the buffer size is 0, recvfrom() returns 0 and errno is set to 0 as well on real hardware. So this is the behaviour WinUAE should replicate. Actually, it doesn't seem to be limited to MSG_PEEK. Without MSG_PEEK the behaviour is the same, i.e. -1 is returned and WSAEMSGSIZE is set. This is also consistent with MSDN's documentation of recvfrom() which says: "If no error occurs, recvfrom returns the number of bytes received." and "If the datagram or message is larger than the buffer specified, the buffer is filled with the first part of the datagram, and recvfrom generates the error WSAEMSGSIZE". In other words: whenever WSAEMSGSIZE is set, -1 will be returned. This is different from the Unix recvfrom() which doesn't generate an error if the buffer is too small. |
![]() |
![]() |
#10 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 45
Posts: 24,647
|
https://download.abime.net/winuae/files/b/winuae.7z should fix it.
If recv() or recvfrom() returns -1 and error is WSAEMSGSIZE and UDP socket: clear error and return buffer length value instead of -1. |
![]() |
![]() |
#11 |
Registered User
![]() Join Date: Mar 2016
Location: Germany
Posts: 73
|
Works, thanks for the quick fix!
|
![]() |
![]() |
#12 |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 45
Posts: 24,647
|
I'll (almost) always fix problems quickly if there is nice test case(s) and problem is well known.
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
bsdsocket.library - how does it work? | Sim085 | support.WinUAE | 17 | 30 June 2019 20:17 |
Bsdsocket.Library | Emufr3ak | Coders. Asm / Hardware | 5 | 25 December 2016 12:20 |
winuae bsdsocket.library | clauddio | support.WinUAE | 5 | 21 July 2015 22:47 |
Can't connect with bsdsocket.library error (WinUAE 2.5.0) | arti | support.WinUAE | 12 | 13 December 2012 22:29 |
WinUAE doesn't work under Vista | bobgeldof | support.WinUAE | 22 | 23 October 2009 20:42 |
|
|