Skip to content

Fix Windows build with craft

Jack Hill requested to merge jackh/libktorrent:windows into master

The only failing test is transmittest and I cannot understand how to fix it. I figured out that things go in this order:

  1. The UTPServer creates a ServerSocket and binds it to 0.0.0.0:50000
  2. The test asks UTPServer to connect to 127.0.0.1:50000
  3. The UTPServer creates Connection object and tells it to start connecting to the server
  4. The Connection tells UTPServer to send SYN packet to Connection
  5. When ServerSocket is ready to write, it sends the packet to Connection
  6. ServerSocket (wrapper around Socket) calls Winsocks sendto which sometimes gives the error WSAEFAULT

The buf or to parameters are not part of the user address space, or the tolen parameter is too small.

see https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-sendto.

I ran the test multiple times and forced the sendto to use the same parameters for each run (the only difference being the ServerSocket's fd) yet still the test sometimes passes and fails. Even if the fd happens to be the same value, the test can fail pass or fail. I have even witnessed sendto return -1 (indicating an error), but WSAGetLastError returns 0 (indicating no error).

On the off chance that the does does pass, the sendto reports that it sent 20 bytes, despite the buffer containing 16 bytes. I don't know much about networking but this also seems a bit suspicious to me.

Edited by Jack Hill

Merge request reports