News:

Congratulations!
 You've won the News Item Lottery! Your prize? Reading this news item! :)

Quick patch to fix network bug and add better debug logging

Started by Ashley, March 04, 2012, 10:56:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ashley

I found a bug in network_open_address(), where if the bind() call failed the socket was not invalidated, thus if no connection could be made on any address it was returning a non-Invalid, but non-Connected socket.

Attached patch fixes this, and also adds better logging for a few sections by properly writing out errno results from networking calls.

(I found this by misconfiguring my client with the wrong listen directive address, so it couldn't connect!)
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Dwachs

Thanks for figuring this out!

One remark: the GET_LAST_ERROR() macro is there for a reason: windows code is recommended to use windows-internal function rather than errno, which is now hidden behind the macro GET_LAST_ERROR().

I do not know whether it makes much sense to call strerror with socket errors on windows systems.
Parsley, sage, rosemary, and maggikraut.

prissi

It does not, since this is a DLL error of which the standard C library know nothing. In the old days there where even several such DLLs before microsoft ended this by providing winsock.dll out of the box.

Ashley

I'll be sure to use GET_LAST_ERROR() then instead of manually using errno - what about the gai_strerror() method employed by getnameinfo() and similar?
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Dwachs

Parsley, sage, rosemary, and maggikraut.

prissi

In my tries those functions did not gave nice error messages by rather generic "IO error -42" or so. But it may depend on the windows version. I will run some trials.

EDIT: It is even weritten there:
QuoteIf the ecode parameter is not an error code value that getaddrinfo returns, the gai_strerror function returns a pointer to a string that indicates an unknown error.

Thus the usual ouput would be "unknown error -42", as I observed too.

Ashley

gai_strerror() should of course only be used with functions which it understands the error codes to (e.g. getaddrinfo, getnameinfo etc.)

Looks like on Windows WSAGetLastError() is the way to go for getting windows sockets errors (it is also threadsafe, whereas gai_strerror is not on Windows). Maybe we could have a define, SOCKLASTERROR or similar which on Windows goes to WSAGetLastError(), and on *nix maps to gai_strerror()?
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.