Exposed and tested disconnect notification TCP packets.

This commit is contained in:
irungentoo 2014-05-15 20:57:55 -04:00
parent 1e7164fcee
commit a514167952
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
3 changed files with 30 additions and 0 deletions

View File

@ -446,6 +446,15 @@ START_TEST(test_client)
do_TCP_connection(conn);
do_TCP_connection(conn2);
ck_assert_msg(data_callback_good == 1, "data callback not called");
status_callback_good = 0;
send_disconnect_request(conn2, 0);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_TCP_connection(conn);
do_TCP_connection(conn2);
ck_assert_msg(status_callback_good == 1, "status callback not called");
ck_assert_msg(status_callback_status == 1, "wrong status");
}
END_TEST

View File

@ -300,6 +300,20 @@ static int send_ping_response(TCP_Client_Connection *con, uint64_t ping_id)
return write_packet_TCP_secure_connection(con, packet, sizeof(packet));
}
/* return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
int send_disconnect_request(TCP_Client_Connection *con, uint8_t con_id)
{
if (con_id >= NUM_CLIENT_CONNECTIONS)
return -1;
con->connections[con_id].status = 0;
con->connections[con_id].number = 0;
return send_disconnect_notification(con, con_id + NUM_RESERVED_PORTS);
}
/* return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
@ -564,6 +578,7 @@ void do_TCP_connection(TCP_Client_Connection *TCP_connection)
if (sizeof(data) == len) {
if (handle_handshake(TCP_connection, data) == 0) {
TCP_connection->kill_at = ~0;
TCP_connection->status = TCP_CLIENT_CONFIRMED;
} else {
TCP_connection->kill_at = 0;

View File

@ -105,6 +105,12 @@ void routing_response_handler(TCP_Client_Connection *con, int (*response_callbac
void routing_status_handler(TCP_Client_Connection *con, int (*status_callback)(void *object, uint32_t number,
uint8_t connection_id, uint8_t status), void *object);
/* return 1 on success.
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
int send_disconnect_request(TCP_Client_Connection *con, uint8_t con_id);
/* Set the number that will be used as an argument in the callbacks related to con_id.
*
* When not set by this function, the number is ~0.