Skip to content

Commit

Permalink
csp_rdp_queue_rx_add return success or error
Browse files Browse the repository at this point in the history
  • Loading branch information
moonlight83340 committed Jul 5, 2024
1 parent b01c90c commit 360f428
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
23 changes: 15 additions & 8 deletions src/csp_rdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ static int csp_rdp_send_eack(csp_conn_t * conn) {
}

/* Requeue */
csp_rdp_queue_rx_add(conn, packet);
if (csp_rdp_queue_rx_add(conn, packet) != 0){
csp_rdp_error("RDP %p: Packet lost in csp_rdp_send_eack \n", conn);
}
}

return csp_rdp_send_cmp(conn, packet_eack, RDP_ACK | RDP_EAK, conn->rdp.snd_nxt, conn->rdp.rcv_cur);
Expand Down Expand Up @@ -282,7 +284,9 @@ static inline void csp_rdp_rx_queue_flush(csp_conn_t * conn) {

/* Otherwise, requeue */
} else {
csp_rdp_queue_rx_add(conn, packet);
if (csp_rdp_queue_rx_add(conn, packet) != 0){
csp_rdp_error("RDP %p: Packet lost in csp_rdp_rx_queue_flush \n", conn);
}
}
}
}
Expand All @@ -300,7 +304,9 @@ static inline bool csp_rdp_seq_in_rx_queue(csp_conn_t * conn, uint16_t seq_nr) {
break;
}

csp_rdp_queue_rx_add(conn, packet);
if (csp_rdp_queue_rx_add(conn, packet) != 0){
csp_rdp_error("RDP %p: Packet lost in csp_rdp_seq_in_rx_queue \n", conn);
}

rdp_header_t * header = csp_rdp_header_ref((csp_packet_t *)packet);
csp_rdp_protocol("RDP %p: RX Queue exists matching Element, seq %u\n", conn, header->seq_nr);
Expand All @@ -317,10 +323,11 @@ static inline bool csp_rdp_seq_in_rx_queue(csp_conn_t * conn, uint16_t seq_nr) {

static inline int csp_rdp_rx_queue_add(csp_conn_t * conn, csp_packet_t * packet, uint16_t seq_nr) {

if (csp_rdp_seq_in_rx_queue(conn, seq_nr))
if (csp_rdp_seq_in_rx_queue(conn, seq_nr)){
csp_rdp_protocol("RDP %p: Duplicate sequence number\n", conn);
return -1;
csp_rdp_queue_rx_add(conn, packet);
return 0;
}
return csp_rdp_queue_rx_add(conn, packet);
}

static void csp_rdp_flush_eack(csp_conn_t * conn, csp_packet_t * eack_packet) {
Expand Down Expand Up @@ -735,8 +742,8 @@ bool csp_rdp_new_packet(csp_conn_t * conn, csp_packet_t * packet) {

/* If message is not in sequence, send EACK and store packet */
if (rx_header->seq_nr != (uint16_t)(conn->rdp.rcv_cur + 1)) {
if (csp_rdp_rx_queue_add(conn, packet, rx_header->seq_nr) != 0) {
csp_rdp_protocol("RDP %p: Duplicate sequence number\n", conn);
if (csp_rdp_rx_queue_add(conn, packet, rx_header->seq_nr) != 0) {
csp_rdp_protocol("RDP %p: Fail to add packet to RX queue\n", conn);
csp_rdp_check_ack(conn);
goto discard_open;
}
Expand Down
8 changes: 6 additions & 2 deletions src/csp_rdp_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ int csp_rdp_queue_rx_size(void) {
return csp_queue_size(rx_queue);
}

void csp_rdp_queue_rx_add(csp_conn_t * conn, csp_packet_t * packet) {
int csp_rdp_queue_rx_add(csp_conn_t * conn, csp_packet_t * packet) {
packet->conn = conn;
if (csp_queue_enqueue(rx_queue, &packet, 0) != CSP_QUEUE_OK) {
csp_buffer_free(packet);
return -1;
}
return 0;
}

csp_packet_t * csp_rdp_queue_rx_get(csp_conn_t * conn) {
Expand All @@ -122,7 +124,9 @@ csp_packet_t * csp_rdp_queue_rx_get(csp_conn_t * conn) {
if (packet->conn == conn) {
return packet;
} else {
csp_rdp_queue_rx_add(conn, packet);
if (csp_rdp_queue_rx_add(conn, packet) != 0){
csp_rdp_error("RDP %p: Packet lost in csp_rdp_queue_rx_get \n", conn);
}
}
}
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/csp_rdp_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ void csp_rdp_queue_tx_add(csp_conn_t * conn, csp_packet_t * packet);
csp_packet_t * csp_rdp_queue_tx_get(csp_conn_t * conn);

int csp_rdp_queue_rx_size(void);
void csp_rdp_queue_rx_add(csp_conn_t * conn, csp_packet_t * packet);
int csp_rdp_queue_rx_add(csp_conn_t * conn, csp_packet_t * packet);
csp_packet_t * csp_rdp_queue_rx_get(csp_conn_t * conn);

0 comments on commit 360f428

Please sign in to comment.