![]() |
| | #1 |
| Registered User Join Date: Feb 2009
Posts: 10
| Exiting socket gracefully When I call accept function, it keeps on waiting for the new connection. I want to know, can I call accept function in some manner so that it doesn't completely hang the execution. I don't want to use Ctrl+C to exit the server everytime. I know threading is an option, but some other better option? |
| vkaushal21 is offline | |
| | #2 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,946
| Use non-block. Quote:
Code: #include <fcntl.h> fcntl(socket_fd,F_SETFL,O_NONBLOCK);
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS | |
| MK27 is offline | |
| | #3 | |
| Registered User Join Date: Nov 2007
Posts: 11
| Quote:
(= | |
| Tesctassa is offline | |
| | #4 |
| Jaxom's & Imriel's Dad Join Date: Aug 2006 Location: Alabama
Posts: 801
| Try using select() on it. Configure an internal pipe that you can use to break out of the select wait state (if you need to break out for some reason --- like your main tread is exiting) |
| Kennedy is offline | |
![]() |
| Tags |
| socket accept |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Function call from another .c module | Ali.B | C Programming | 14 | 08-03-2009 11:45 AM |
| Problem with socket descriptors | McKracken | C Programming | 1 | 07-22-2009 08:51 AM |
| socket programming question, closing sockets... | ursula | Networking/Device Communication | 2 | 05-31-2009 05:17 PM |
| Socket Help - Multiple Clients | project95talon | C Programming | 5 | 11-17-2005 02:51 AM |
| socket newbie, losing a few chars from server to client | registering | Linux Programming | 2 | 06-07-2003 11:48 AM |