Avoid depending on libc calls and instead explicitly check the socket file descriptor.
Return F_file_descriptor_not when -1.
Add unit test for this.
if (!socket) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
+ if (socket->id == -1) return F_file_descriptor_not;
+
int result = 0;
if (action == f_socket_close_fast_e) {
* @return
* F_okay on success.
* F_connect_not if the socket is not connected.
+ * F_file_descriptor_not if socket.id is -1.
*
* F_busy_address (with error bit) if address is already in use (therefore unavailable).
* F_file_descriptor (with error bit) if id is an invalid descriptor.
}
}
+void test__f_socket_disconnect__returns_file_descriptor_not(void **state) {
+
+ {
+ f_socket_t socket = f_socket_t_initialize;
+
+ const f_status_t status = f_socket_disconnect(&socket, 0);
+
+ assert_int_equal(status, F_file_descriptor_not);
+ }
+}
+
void test__f_socket_disconnect__works_for_close_fast(void **state) {
f_socket_t socket = f_socket_t_initialize;
extern void test__f_socket_disconnect__parameter_checking(void **state);
/**
+ * Test that the function returns F_file_descriptor_not.
+ *
+ * @see f_socket_disconnect()
+ */
+extern void test__f_socket_disconnect__returns_file_descriptor_not(void **state);
+
+/**
* Test that function works for f_socket_close_fast_e.
*
* @see f_socket_disconnect()
cmocka_unit_test(test__f_socket_disconnect__fails_for_close_read),
cmocka_unit_test(test__f_socket_disconnect__fails_for_close_unknown),
cmocka_unit_test(test__f_socket_disconnect__fails_for_close_write),
+
+ cmocka_unit_test(test__f_socket_disconnect__returns_file_descriptor_not),
+
cmocka_unit_test(test__f_socket_disconnect__works_for_close_fast),
cmocka_unit_test(test__f_socket_disconnect__works_for_close_read),
cmocka_unit_test(test__f_socket_disconnect__works_for_close_write),