diff --git a/include/patty/ax25/sock.h b/include/patty/ax25/sock.h index 6d1306f..13351c0 100644 --- a/include/patty/ax25/sock.h +++ b/include/patty/ax25/sock.h @@ -200,6 +200,8 @@ void patty_ax25_sock_vs_incr(patty_ax25_sock *sock); void patty_ax25_sock_vr_incr(patty_ax25_sock *sock); +int patty_ax25_sock_flow_left(patty_ax25_sock *sock); + int patty_ax25_sock_flow_full(patty_ax25_sock *sock); /* diff --git a/src/sock.c b/src/sock.c index 1f94bb1..6661ebf 100644 --- a/src/sock.c +++ b/src/sock.c @@ -535,6 +535,14 @@ void *patty_ax25_sock_assembler_read(patty_ax25_sock *sock, return buf + 1; } +int patty_ax25_sock_flow_left(patty_ax25_sock *sock) { + if (sock->n_window_tx == 1) { + return 1; + } + + return sock->vs - tx_seq(sock, sock->va + sock->n_window_tx); +} + int patty_ax25_sock_flow_full(patty_ax25_sock *sock) { /* * 6.4.1 Sending I Frames @@ -644,11 +652,7 @@ error_invalid_type: } static inline uint16_t control_i(patty_ax25_sock *sock, int ns) { - int flag = 0; - - if (sock->vs == tx_seq(sock, sock->va + sock->n_window_tx - 1)) { - flag = 1; - } + int flag = patty_ax25_sock_flow_left(sock) == 1? 1: 0; switch (sock->mode) { case PATTY_AX25_SOCK_SABM: