diff --git a/soc/runtime/main.c b/soc/runtime/main.c index e2c3691f5..a74162891 100644 --- a/soc/runtime/main.c +++ b/soc/runtime/main.c @@ -191,7 +191,8 @@ static void serial_service(void) if(txlen > 0) { for(i = 0; i < txlen; i++) uart_write(txdata[i]); - session_ack(txlen); + session_ack_consumed(txlen); + session_ack_sent(txlen); } else if(txlen < 0) { reset_serial_session(1); } diff --git a/soc/runtime/net_server.c b/soc/runtime/net_server.c index a18e4da85..184d9fca5 100644 --- a/soc/runtime/net_server.c +++ b/soc/runtime/net_server.c @@ -89,7 +89,7 @@ static err_t net_server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err static err_t net_server_sent(void *arg, struct tcp_pcb *pcb, u16_t len) { - session_ack(len); + session_ack_sent(len); return ERR_OK; } @@ -205,6 +205,7 @@ void net_server_service(void) if(len > sndbuf) len = sndbuf; tcp_write(active_pcb, data, len, 0); + session_ack_consumed(len); } if(len < 0) net_server_close(active_cs, active_pcb); diff --git a/soc/runtime/session.c b/soc/runtime/session.c index 4c394f272..eea96fee5 100644 --- a/soc/runtime/session.c +++ b/soc/runtime/session.c @@ -158,12 +158,13 @@ static union { } __attribute__((packed)) header; } buffer_out; -static int buffer_out_read_cursor, buffer_out_write_cursor; +static int buffer_out_read_cursor, buffer_out_sent_cursor, buffer_out_write_cursor; static void out_packet_reset() { buffer_out_read_cursor = 0; buffer_out_write_cursor = 0; + buffer_out_sent_cursor = 0; } static int out_packet_available() @@ -182,17 +183,28 @@ static void out_packet_extract(void **data, int *length) } } -static void out_packet_advance(int length) +static void out_packet_advance_consumed(int length) { if(buffer_out_read_cursor + length > buffer_out_write_cursor) { - log("session.c: write underrun while trying to acknowledge %d bytes" - " (%d remaining)", + log("session.c: write underrun (consume) while trying to" + " acknowledge %d bytes (%d remaining)", length, buffer_out_write_cursor - buffer_out_read_cursor); return; } buffer_out_read_cursor += length; - if(buffer_out_read_cursor == buffer_out_write_cursor) +} + +static void out_packet_advance_sent(int length) { + if(buffer_out_sent_cursor + length > buffer_out_write_cursor) { + log("session.c: write underrun (send) while trying to" + " acknowledge %d bytes (%d remaining)", + length, buffer_out_write_cursor - buffer_out_sent_cursor); + return; + } + + buffer_out_sent_cursor += length; + if(buffer_out_sent_cursor == buffer_out_write_cursor) out_packet_reset(); } @@ -652,7 +664,12 @@ void session_poll(void **data, int *length) out_packet_extract(data, length); } -void session_ack(int length) +void session_ack_consumed(int length) { - out_packet_advance(length); + out_packet_advance_consumed(length); +} + +void session_ack_sent(int length) +{ + out_packet_advance_sent(length); } diff --git a/soc/runtime/session.h b/soc/runtime/session.h index 8ef353b9e..cd0e3d76e 100644 --- a/soc/runtime/session.h +++ b/soc/runtime/session.h @@ -6,6 +6,7 @@ void session_end(void); int session_input(void *data, int length); void session_poll(void **data, int *length); -void session_ack(int length); +void session_ack_consumed(int length); +void session_ack_sent(int length); #endif /* __SESSION_H */