From c44d83ad0671506864270f4455a468518a65e9e5 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 5 Jan 2022 18:05:43 -0600 Subject: [PATCH] Update: Only clear socket id when fast closing and update documentation. --- level_0/f_socket/c/socket.c | 4 +++- level_0/f_socket/c/socket.h | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/level_0/f_socket/c/socket.c b/level_0/f_socket/c/socket.c index f173422..107b3b1 100644 --- a/level_0/f_socket/c/socket.c +++ b/level_0/f_socket/c/socket.c @@ -228,7 +228,9 @@ extern "C" { return F_status_set_error(F_failure); } - socket->id = -1; + if (action == f_socket_close_fast_e) { + socket->id = -1; + } return F_none; } diff --git a/level_0/f_socket/c/socket.h b/level_0/f_socket/c/socket.h index 23e4acb..a6b6830 100644 --- a/level_0/f_socket/c/socket.h +++ b/level_0/f_socket/c/socket.h @@ -258,7 +258,21 @@ extern "C" { /** * Terminate a socket connection. * - * To properly close a UNIX socket, call f_file_close() and f_file_remove(). + * The shutdown() call is used for all actions, except f_socket_close_fast_e. + * When shutdown() is called, a proper network disconnection process is initiated. + * The network connection will properly send the FIN packets. + * The shutdown() also allows current buffers to be properly flushed. + * The file descriptor is not closed. + * The remaining buffer can still be processed. + * Be sure to call either this function again with f_socket_close_fast_e or call f_file_close() directly. + * + * When action is f_socket_close_fast_e, then close() is called. + * What happens then is that rather than waiting for FIN a RST is immediately sent (RST is sent only if connection is still active). + * All buffers are discarded. + * The connection is immediately removed. + * Thus, f_socket_close_fast_e (calling close()) on a socket results in bad network practice. + * + * In the above cases, whether or not a RST or FIN are sent is also dependent on whether the f_socket_option_linger_d is used (SO_LINGER). * * @param socket * The socket structure. -- 1.8.3.1