Merge patty_ax25_sock_timer_ack_restart(), _set()

Changes:

    * Combine patty_ax25_sock_ack_timer_restart() and _set() into one
      method, patty_ax25_sock_ack_timer_start(), which accepts a new
      struct timeval argument to potentially add the Timer T1 value to

    * Reorder some functions in src/sock.c, include/patty/ax25/sock.h
This commit is contained in:
XANTRONIX Development 2020-07-27 19:22:40 -04:00 committed by XANTRONIX Industrial
parent 9db9234a56
commit 8632e7ccb8
3 changed files with 28 additions and 26 deletions

View file

@ -98,18 +98,16 @@ patty_ax25_sock *patty_ax25_sock_new(enum patty_ax25_proto proto,
void patty_ax25_sock_destroy(patty_ax25_sock *sock);
void patty_ax25_sock_timer_ack_restart(patty_ax25_sock *sock);
int patty_ax25_sock_timer_ack_expired(patty_ax25_sock *sock);
void patty_ax25_sock_timer_ack_cancel(patty_ax25_sock *sock);
void patty_ax25_sock_timer_ack_set(patty_ax25_sock *sock,
void patty_ax25_sock_timer_ack_start(patty_ax25_sock *sock,
struct timeval *timer);
void patty_ax25_sock_timer_ack_sub(patty_ax25_sock *sock,
struct timeval *elapsed);
int patty_ax25_sock_timer_ack_expired(patty_ax25_sock *sock);
int patty_ax25_sock_reset(patty_ax25_sock *sock);
int patty_ax25_sock_upgrade(patty_ax25_sock *sock,

View file

@ -829,9 +829,7 @@ static int server_connect(patty_ax25_server *server,
return respond_connect(client, -1, errno);
}
patty_ax25_sock_timer_ack_restart(sock);
patty_ax25_sock_timer_ack_set(sock, &server->timer);
patty_ax25_sock_timer_ack_start(sock, &server->timer);
/*
* At this point, we will wait for a DM, FRMR or XID response, which
@ -1152,9 +1150,11 @@ static int handle_frmr(patty_ax25_server *server,
}
if (sock->status == PATTY_AX25_SOCK_PENDING_CONNECT) {
patty_ax25_sock_timer_ack_restart(sock);
int ret = patty_ax25_sock_send_sabm(sock, PATTY_AX25_FRAME_POLL);
return patty_ax25_sock_send_sabm(sock, PATTY_AX25_FRAME_POLL);
patty_ax25_sock_timer_ack_start(sock, &server->timer);
return ret;
}
return 0;
@ -1403,6 +1403,8 @@ static int handle_xid(patty_ax25_server *server,
patty_ax25_sock *local,
*remote;
int ret;
if (patty_ax25_frame_decode_xid(&params, buf, offset, len) < 0) {
goto error_io;
}
@ -1448,9 +1450,11 @@ static int handle_xid(patty_ax25_server *server,
remote->mode = PATTY_AX25_SOCK_SABME;
}
patty_ax25_sock_timer_ack_restart(remote);
ret = patty_ax25_sock_send_sabm(remote, PATTY_AX25_FRAME_POLL);
return patty_ax25_sock_send_sabm(remote, PATTY_AX25_FRAME_POLL);
patty_ax25_sock_timer_ack_start(remote, &server->timer);
return ret;
}
/*
@ -1627,9 +1631,11 @@ static int handle_sock(uint32_t key,
if (sock->status == PATTY_AX25_SOCK_PENDING_CONNECT) {
if (patty_ax25_sock_timer_ack_expired(sock)) {
if (sock->retries) {
patty_ax25_sock_timer_ack_restart(sock);
int ret = patty_ax25_sock_send_sabm(sock, PATTY_AX25_FRAME_POLL);
return patty_ax25_sock_send_sabm(sock, PATTY_AX25_FRAME_POLL);
patty_ax25_sock_timer_ack_start(sock, &server->timer);
return ret;
} else {
(void)sock_shutdown(server, sock);

View file

@ -179,12 +179,8 @@ void patty_ax25_sock_destroy(patty_ax25_sock *sock) {
free(sock);
}
/*
* AX.25 v2.2 Specification, Section 6.3.1 "AX.25 Link Connection Establishment"
*/
void patty_ax25_sock_timer_ack_restart(patty_ax25_sock *sock) {
sock->timer_ack.tv_sec = sock->n_ack / 1000;
sock->timer_ack.tv_usec = (sock->n_ack % 1000) * 1000;
int patty_ax25_sock_timer_ack_expired(patty_ax25_sock *sock) {
return (sock->timer_ack.tv_sec <= 0 && sock->timer_ack.tv_usec == 0)? 1: 0;
}
void patty_ax25_sock_timer_ack_cancel(patty_ax25_sock *sock) {
@ -192,8 +188,14 @@ void patty_ax25_sock_timer_ack_cancel(patty_ax25_sock *sock) {
sock->timer_ack.tv_usec = 0;
}
void patty_ax25_sock_timer_ack_set(patty_ax25_sock *sock,
/*
* AX.25 v2.2 Specification, Section 6.3.1 "AX.25 Link Connection Establishment"
*/
void patty_ax25_sock_timer_ack_start(patty_ax25_sock *sock,
struct timeval *timer) {
sock->timer_ack.tv_sec = sock->n_ack / 1000;
sock->timer_ack.tv_usec = (sock->n_ack % 1000) * 1000;
if (timercmp(&sock->timer_ack, timer, >)) {
struct timeval res;
@ -212,10 +214,6 @@ void patty_ax25_sock_timer_ack_sub(patty_ax25_sock *sock,
memcpy(&sock->timer_ack, &res, sizeof(sock->timer_ack));
}
int patty_ax25_sock_timer_ack_expired(patty_ax25_sock *sock) {
return (sock->timer_ack.tv_sec <= 0 && sock->timer_ack.tv_usec == 0)? 1: 0;
}
/*
* AX.25 v2.2 Specification, Section 6.5 "Resetting Procedure"
*/