wait X seconds implementation - C under linux

Feb 15, 2010 at 11:13pm
I have an UDP server and I need to close connection to a client after 10 seconds . How can I implement that ?
Feb 15, 2010 at 11:22pm
closed account (S6k9GNh0)
Use a timer and wait for ten seconds?
Feb 16, 2010 at 12:58am
There's this function called "sleep." Maybe you can find a man-page or something for it, because it'll be really hard to figure out how to use it and what it does, otherwise. They should start naming their functions better; they aren't descriptive enough.

Edit: Here's a man page: http://linux.die.net/man/3/sleep
Last edited on Feb 16, 2010 at 12:59am
Feb 16, 2010 at 2:50pm
Sleep functions block execution of your program.
When handling sockets, you want to use a non-blocking function instead. On POSIX systems, choose one of select() or poll().
http://linux.die.net/man/2/select
http://linux.die.net/man/2/poll
Feb 16, 2010 at 9:58pm
Or hand off the socket to a thread that sleep()s for 10 seconds then closes the connection.
Topic archived. No new replies allowed.