SDLNet_TCP_Send and SIGPIPE (Linux)

My network game has worked for ages in Windows, but now that
I made a Linux version of it, there seem to be random crashes
every now and then. Everything has been made on top of SDL so the
code is identical. It is very hard to debug the problem since
a server may crash once in a month or so, but debug information
suggests that crashes might be related to SDLNet_TCP_Send.
With Valgrind, I am able to make send/SLNet_TCP_Send signal
SIGPIPE (and thus crash) when I disconnect from a server at a
certain time. It also seems that players with worse connections
are getting this problem more often.

Could this be a bug in SDL_net/SDL? I am using the latest library
versions (1.2.8 for SDL) and I can read in the change log that SDL
1.2.7 should have made SIGPIPE non-fatal, but what could then
explain this? Is it just Valgrind that is not working? And what
should I do to get rid of the problem? Define my own signal handler?

Would something get broken or could the problem be fixed
if I add “signal(SIGPIPE, SIG_IGN)” to somewhere in my code?
Where should it be put? After SDL and SDL_net have been initialized?

I made a search on this and found these two related articles
but are they still valid? Is SDL_net still buggy?
http://twomix.devolution.com/pipermail/sdl/2004-September/064816.html
http://twomix.devolution.com/pipermail/sdl/2002-April/044554.html

My network game has worked for ages in Windows, but now that
I made a Linux version of it, there seem to be random crashes
every now and then. Everything has been made on top of SDL so the
code is identical. It is very hard to debug the problem since
a server may crash once in a month or so, but debug information
suggests that crashes might be related to SDLNet_TCP_Send.
With Valgrind, I am able to make send/SLNet_TCP_Send signal
SIGPIPE (and thus crash) when I disconnect from a server at a
certain time. It also seems that players with worse connections
are getting this problem more often.

The normal behaviour for send() is to SIGPIPE when the other end has
reset the connection, unless you pass MSG_NOSIGNAL as flags. Does
SDL_Net not do this?

Could this be a bug in SDL_net/SDL? I am using the latest library
versions (1.2.8 for SDL) and I can read in the change log that SDL
1.2.7 should have made SIGPIPE non-fatal, but what could then
explain this? Is it just Valgrind that is not working? And what
should I do to get rid of the problem? Define my own signal handler?

If SDL_Net uses send() without MSG_NOSIGNAL, it’s a bug. In SDL_Net.

Would something get broken or could the problem be fixed
if I add “signal(SIGPIPE, SIG_IGN)” to somewhere in my code?
Where should it be put? After SDL and SDL_net have been initialized?

That will make you not crash, but will instead make you unable to
detect broken connections. And will make you try to send() repeatedly
to a bad fd. Don’t do this.

… or you could, if you try to receive data quite directly after
trying to send, which will detect the broken connection in a nicer
way.

Disclaimer: I know nothing about the implementation of SDL_Net, I’m
just a POSIX hacker.On Wed, Jan 19, 2005 at 05:16:04PM +0200, Antti Mannisto wrote:


Petri Latvala
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050526/6b082eb6/attachment.pgp