-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add shutdown_socket()
function for follow up of #505
#506
base: refactor-only-comm-type
Are you sure you want to change the base?
Conversation
@@ -155,7 +155,7 @@ static int create_server(uint16_t port, int* final_socket, uint16_t* final_port, | |||
return -1; | |||
} | |||
set_socket_timeout_option(socket_descriptor, &timeout_time); | |||
int used_port = set_socket_bind_option(socket_descriptor, port, increment_port_on_retry); | |||
uint16_t used_port = set_socket_bind_option(socket_descriptor, port, increment_port_on_retry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor fix on port's data type.
@@ -1943,9 +1918,11 @@ void lf_connect_to_rti(const char* hostname, int port) { | |||
|
|||
void lf_create_server(int specified_port) { | |||
assert(specified_port <= UINT16_MAX && specified_port >= 0); | |||
if (create_TCP_server(specified_port, &_fed.server_socket, (uint16_t*)&_fed.server_port, false)) { | |||
uint16_t port; | |||
if (create_TCP_server(specified_port, &_fed.server_socket, &port, false)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor fix on port's data type.
shutdown_socket()
function.shutdown_socket()
function.
shutdown_socket()
function.shutdown_socket()
function for follow up of #505
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice refactoring. Just left minor suggestions.
core/federated/RTI/rti_remote.c
Outdated
@@ -1030,9 +1009,7 @@ void send_reject(int* socket_id, unsigned char error_code) { | |||
lf_print_warning("RTI failed to write MSG_TYPE_REJECT message on the socket."); | |||
} | |||
// Close the socket. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: how about adding more information for this call? For example, "Close the socket without reading until EOF."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I fixed it as suggested.
core/federated/RTI/rti_remote.c
Outdated
@@ -1418,9 +1395,7 @@ void lf_connect_to_federates(int socket_descriptor) { | |||
if (!authenticate_federate(&socket_id)) { | |||
lf_print_warning("RTI failed to authenticate the incoming federate."); | |||
// Close the socket. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I fixed it as suggested.
core/federated/RTI/rti_remote.c
Outdated
@@ -1488,8 +1463,7 @@ void* respond_to_erroneous_connections(void* nothing) { | |||
lf_print_warning("RTI failed to write FEDERATION_ID_DOES_NOT_MATCH to erroneous incoming connection."); | |||
} | |||
// Close the socket. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I fixed it as suggested.
The macOS test is not passing for some unknown reason. The CI test log seems to not work starting from The reason for not passing is that the program blocks on the final shutdown phase. First, this is how the LF code is intended to work.
This normally works on Linux, thus passing all tests. However, this fails on Mac. I also checked that the
The RTI(15045) is in This error can be reproduced by the lingua-franca's repo on branch @hokeun @edwardalee Could anyone help investigating this problem? |
This PR follow ups #505
New Integrated Function:
shutdown_socket()
int shutdown_socket(int* socket, bool read_before_closing);
Arguments
socket
: A pointer to the socket descriptor that needs to be shut down and closed.read_before_closing
: A boolean indicating whether the socket should read any remaining incoming data before closing:FIN
packet (SHUT_WR
) and waits forEOF
(0-length message) from the peer.SHUT_RDWR
).Return Values
0
: Indicates successful shutdown and closure of the socket.-1
: Indicates a failure during shutdown or closure, with errno set to describe the specific error.Function Description
This function gracefully shuts down and closes a socket.
shutdown(SHUT_RDWR)
to immediately stop both sending and receiving data. Then callsclose()
.shutdown(SHUT_WR)
to signal the end of writing but allows reading to continue.EOF
(indicated byread()
returning 0), and discards all received bytes.Refactoring on
close_inbound_socket()
andclose_outbound_socket()
fromfederate.c
close_inbound_socket()
The original code looked not updated. There were no use case when the argument
flag
was not 1. I removed theflag
argument, and all unused code.close_outbound_socket()
The original flags were only set by this one line code.
int flag = _lf_normal_termination ? 1 : -1;
So it depends on
_lf_normal_termination
. However, this function can directly use_lf_normal_termination
, so I removed theflag
, and directly used_lf_normal_termination
.