Skip to content

Commit

Permalink
session.c: bring back session_ack_{consumed,sent}.
Browse files Browse the repository at this point in the history
These (called session_ack_{data,mem} before) were removed in error.
  • Loading branch information
whitequark committed Aug 8, 2015
1 parent 4efae2b commit f5ea202
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
3 changes: 2 additions & 1 deletion soc/runtime/main.c
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion soc/runtime/net_server.c
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
31 changes: 24 additions & 7 deletions soc/runtime/session.c
Expand Up @@ -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()
Expand All @@ -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();
}

Expand Down Expand Up @@ -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_consumed(length);
}

void session_ack_sent(int length)
{
out_packet_advance(length);
out_packet_advance_sent(length);
}
3 changes: 2 additions & 1 deletion soc/runtime/session.h
Expand Up @@ -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 */

0 comments on commit f5ea202

Please sign in to comment.