* Close all open sockets and files, allowing a (somewhat) graceful * shutdown() of socket connections. This eliminates the abortive * TCP RST sent by a Winsock-based system when the close() occurs. **/
| 49 | * TCP RST sent by a Winsock-based system when the close() occurs. |
| 50 | **/ |
| 51 | void close_all(void) |
| 52 | { |
| 53 | #ifdef SHUTDOWN_ALL_SOCKETS |
| 54 | int max_fd; |
| 55 | int fd; |
| 56 | int ret; |
| 57 | STRUCT_STAT st; |
| 58 | |
| 59 | max_fd = sysconf(_SC_OPEN_MAX) - 1; |
| 60 | for (fd = max_fd; fd >= 0; fd--) { |
| 61 | if ((ret = do_fstat(fd, &st)) == 0) { |
| 62 | if (is_a_socket(fd)) |
| 63 | ret = shutdown(fd, 2); |
| 64 | ret = close(fd); |
| 65 | } |
| 66 | } |
| 67 | #endif |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @file cleanup.c |
no test coverage detected