SDL_net question, proposed feature?

Hi,

I’ve written a small client and server using SDL. I’m doing a lot of
debugging, so the
server needs to be re-started fairly frequently. If I abort the server
abnornally (Control C, seg fault, abort()), and re-run the program, the
server is unable to bind the socket.

The error from SDL_net is:

Couldn’t create server socket: Couldn’t bind to local port

If I wait about 15-20 seconds, and then run the server again, it binds
to the port and works
correctly.

Here’s my best guess at what the problem is:

The socket isn’t released immediately when the server exits. I think
the solution is to
use something like
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, …);
before binding the socket, so that the server ignores the fact that
somebody else (it’s previous
incarnation) still has control of the socket.

Will SDL_net allow me to set socket options? I’ve UTSLd, and it doesn’t
look like this is possible.
Or maybe there’s another reason that I can’t start the server up again
immediately?

thanks,
Devin

Devin Balkcom writes:

Hi,

I’ve written a small client and server using SDL. I’m doing a lot
of debugging, so the server needs to be re-started fairly
frequently. If I abort the server abnornally (Control C, seg fault,
abort()), and re-run the program, the server is unable to bind the
socket.

The problem is that you’re not shutting down the connection; you’re
aborting the application. Therefore, TCP/IP still needs to maintain
the connection in a “reserved” state. The client may still send stuff
to the server for a certain amount of time after the server “goes
away” (there may be messages enroute before the client is notified
that the connection is gone) so the TCP/IP protocol has timeouts that
disallow a different application from using the same server address
until all possible client requests have timed out after the client
being notified that the server has “gone away”. When you do a proper
shutdown of the connection, TCP/IP does a “negotiated release” meaning
that both sides of the connection know that the connection is gone,
and the server can be sure that no stray messages will be received on
that connection id, following the negotiated release.

The best solution for your Control-C option is to put in an exit
handler that will properly shutdown the connection prior to exiting.
You can do something similar for abort() if your code is generating
it. In the seg fault case, you don’t have much of choice, so you’ll
just have to live with the timeouts, or toggle between a couple of
different server addresses so that each has time to timeout between
uses.

Derrell

Hi,

I have a game that goes between 2d SDL and SDL/OpenGL. Between the
different modes I need to close the window and reopen the new one. The
way I’m currently doing it is:

  1. Close the video subsystem
  2. Restart the video subsystem
  3. Create a new window with SetVideoMode (with SDL_HWSURFACE or
    SDL_OPENGLBLIT)

This seems to work fine on Win98/ME but I notice that:
-On Linux if I open the opengl window twice (Open 2D, Open GL, Open 2D,
Open GL) it fails with:

X Error of failed request: BadValue (integer parameter out of range for
operation)
Major opcode of failed request: 130 (XFree86-DRI)
Minor opcode of failed request: 9 ()
Value in failed request: 0x0
Serial number of failed request: 31
Current serial number in output stream: 31

-On Win2k pro it works sometimes and sometimes it fails

-On Win2k Advanced Server it crashes the kernel with
KMOD_UNHANDLED_EXCEPTION and the bsod.

(The linux box is running XFree 4.0.1 with a Voodoo 3,
The Win2k pro boxes have Nvidia Geforce 256es and Evans & Sutherland
AccelGalaxys, and the W2k Advanced Server has a Nvidia Alladin TNT2)

Should I be closing the window in another way? Perhaps theres something
subtle I missed? Anyone run into the same problems?

Thanks for the help--------------
-Larry

“Lawrence W. Leung” wrote:

Should I be closing the window in another way? Perhaps theres something
subtle I missed? Anyone run into the same problems?

I believe it is safe to call SetVideoMode multiple times for the purpose
of changing resolutions, bit-depth, and fullscreen/windowed. (Well, I
do it and it seems to work.) I don’t use OpenGL but maybe you can skip
the Init/Quit steps altogether??

-- David Snopek

/-- libksd –
| The C++ Cross-Platform Game Framework
| Only want to write it once??
| http://libksd.sourceforge.net
------------

Crazy question:
Do you have any audio playing while you’re restarting the video
subsystem? DirectSound needs a hWnd to play sound and who knows what
happens if that hWnd suddenly disappears?

Do you have a minimal program that you used to test this with? If so,
post a link to where I can download it, I’d like to try it. (I’ve got
an NT4 machine and a Win95 machine)–

Olivier A. Dagenais - Software Architect and Developer

“Lawrence W. Leung” wrote in
message
news:Pine.SOL.4.30.0104151929560.4225-100000 at pulsar.CS.Berkeley.EDU

Hi,

I have a game that goes between 2d SDL and SDL/OpenGL. Between the
different modes I need to close the window and reopen the new one.
The
way I’m currently doing it is:

  1. Close the video subsystem
  2. Restart the video subsystem
  3. Create a new window with SetVideoMode (with SDL_HWSURFACE or
    SDL_OPENGLBLIT)

This seems to work fine on Win98/ME but I notice that:
-On Linux if I open the opengl window twice (Open 2D, Open GL, Open
2D,
Open GL) it fails with:

X Error of failed request: BadValue (integer parameter out of range
for
operation)
Major opcode of failed request: 130 (XFree86-DRI)
Minor opcode of failed request: 9 ()
Value in failed request: 0x0
Serial number of failed request: 31
Current serial number in output stream: 31

-On Win2k pro it works sometimes and sometimes it fails

-On Win2k Advanced Server it crashes the kernel with
KMOD_UNHANDLED_EXCEPTION and the bsod.

(The linux box is running XFree 4.0.1 with a Voodoo 3,
The Win2k pro boxes have Nvidia Geforce 256es and Evans & Sutherland
AccelGalaxys, and the W2k Advanced Server has a Nvidia Alladin TNT2)

Should I be closing the window in another way? Perhaps theres
something
subtle I missed? Anyone run into the same problems?

Thanks for the help

-Larry

“Lawrence W. Leung” wrote:

Should I be closing the window in another way? Perhaps theres something
subtle I missed? Anyone run into the same problems?

I believe it is safe to call SetVideoMode multiple times for the purpose
of changing resolutions, bit-depth, and fullscreen/windowed. (Well, I
do it and it seems to work.) I don’t use OpenGL but maybe you can skip
the Init/Quit steps altogether??

Yes, it’s safe even to change 2D v.s. 3D between calls to SDL_SetVideoMode().
If it doesn’t work, it’s probably a bug.

See ya,
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Sam Lantinga schrieb am 16 Apr 2001:

“Lawrence W. Leung” wrote:

Should I be closing the window in another way? Perhaps theres something
subtle I missed? Anyone run into the same problems?

I believe it is safe to call SetVideoMode multiple times for the purpose
of changing resolutions, bit-depth, and fullscreen/windowed. (Well, I
do it and it seems to work.) I don’t use OpenGL but maybe you can skip
the Init/Quit steps altogether??

Yes, it’s safe even to change 2D v.s. 3D between calls to SDL_SetVideoMode().
If it doesn’t work, it’s probably a bug.

GLtron has this problem too, since it needs to recreate the window
when changing resolutions. I mostly get around by not destroying
the old window
. I.e. don’t call SDL_QuitSubSystem(), just
create the new window. I believe it’s a bug in SDL’s unloading of the
GL driver.

  • Andreas–
    Check out my 3D lightcycle game: http://www.gltron.org
    More than 100’000 Downloads of the last version (0.59)

Yes, it’s safe even to change 2D v.s. 3D between calls to SDL_SetVideoMode().
If it doesn’t work, it’s probably a bug.

GLtron has this problem too, since it needs to recreate the window
when changing resolutions. I mostly get around by not destroying
the old window
. I.e. don’t call SDL_QuitSubSystem(), just
create the new window. I believe it’s a bug in SDL’s unloading of the
GL driver.

By not destroying windows do you mean not calling FreeSurface ? This
doesn’t seem to make sense as you haveta let directx give the screen to
opengl right?

Before I had it not restarting and just calling FreeSurface and then
initing a new one.
It wasn’t perfect so I tried to implement a complete restart to fix
the problem but I guess that didn’t work either :frowning:

-Larry

Before I had it not restarting and just calling FreeSurface and then
initing a new one.

I wasn’t aware freeing the screen surface was something end-users
could/should do.–

Olivier A. Dagenais - Software Architect and Developer

“Lawrence W. Leung” wrote:

By not destroying windows do you mean not calling FreeSurface ? This
doesn’t seem to make sense as you haveta let directx give the screen to
opengl right?

Before I had it not restarting and just calling FreeSurface and then
initing a new one.
It wasn’t perfect so I tried to implement a complete restart to fix
the problem but I guess that didn’t work either :frowning:

Don’t ever call FreeSurface on the screen surface. SDL will take of
that. Just make multiple calls to SetVideoMode and don’t worry so much
about the implmentation (directx/opengl).

-- David Snopek

/-- libksd –
| The C++ Cross-Platform Game Framework
| Only want to write it once??
| http://libksd.sourceforge.net
------------

There used to be a DRI bug along these lines - it would crash when
trying to open a second context.On Sun, Apr 15, 2001 at 07:45:27PM -0700, Lawrence W. Leung wrote:

  1. Close the video subsystem
  2. Restart the video subsystem
  3. Create a new window with SetVideoMode (with SDL_HWSURFACE or
    SDL_OPENGLBLIT)

This seems to work fine on Win98/ME but I notice that:
-On Linux if I open the opengl window twice (Open 2D, Open GL, Open 2D,
Open GL) it fails with:

X Error of failed request: BadValue (integer parameter out of range for
operation)
Major opcode of failed request: 130 (XFree86-DRI)
Minor opcode of failed request: 9 ()
Value in failed request: 0x0
Serial number of failed request: 31
Current serial number in output stream: 31

Martin

Bother, said Pooh, as he bumped into Barney.