From 4dab49757620d80a7b99f48149193b1787cb4d1d Mon Sep 17 00:00:00 2001 From: Sparchatus Date: Tue, 24 May 2022 16:16:39 +0000 Subject: [PATCH] [Bugfix] ump channel did not set initial state for send queue entries --- include/aos/ump_chan.h | 12 ++++++------ lib/aos/ump_chan.c | 15 +++++++++++---- usr/echoserver/main.c | 2 +- usr/hello/hello.c | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/aos/ump_chan.h b/include/aos/ump_chan.h index 9d7a03f..206baaa 100644 --- a/include/aos/ump_chan.h +++ b/include/aos/ump_chan.h @@ -17,7 +17,7 @@ struct ump_send_queue_entry; typedef void (*ump_recv_header_callback_fn_t)(void *arg, size_t header_size, void *header, size_t payload_size); typedef void (*ump_recv_payload_callback_fn_t)(void *arg, size_t payload_size, void *payload); -typedef void (*ump_send_callback_fn_t)(void *arg, void *payload, struct ump_send_queue_entry *entry); +typedef void (*ump_send_callback_fn_t)(void *arg, struct ump_send_queue_entry *entry); /** * @brief Specifies which role an endpoint would like to take in the UMP protocol @@ -71,10 +71,10 @@ struct ump_send_queue_entry { enum ump_send_entry_state state; size_t header_size; - void *header; + const void *header; size_t payload_size; - void *payload; + const void *payload; ump_send_callback_fn_t callback; void *callback_arg; @@ -84,7 +84,7 @@ struct ump_send_queue_entry { * it will be updated to refer to the payload */ size_t send_bytes_left; - void *send_buf_position; + const void *send_buf_position; struct ump_send_queue_entry *next; }; @@ -213,9 +213,9 @@ void ump_send ( struct ump_send_chan *chan, struct ump_send_queue_entry *entry, size_t header_size, - void *header, + const void *header, size_t payload_size, - void *payload, + const void *payload, ump_send_callback_fn_t callback, void *callback_arg ); diff --git a/lib/aos/ump_chan.c b/lib/aos/ump_chan.c index 546735d..c9fd08f 100644 --- a/lib/aos/ump_chan.c +++ b/lib/aos/ump_chan.c @@ -28,7 +28,7 @@ static void ump_ring_init(struct ump_ring_state *ring_state, void *buf, size_t b * @return true successfully wrote the entry * @return false failed to write the entry because the buffer is full */ -static bool ump_ring_try_write_next(struct ump_ring_state *ring_state, void *buf, size_t bytes) { +static bool ump_ring_try_write_next(struct ump_ring_state *ring_state, const void *buf, size_t bytes) { assert(bytes <= UMP_RING_BUF_DATA_SIZE); assert(buf != NULL); @@ -223,7 +223,7 @@ static void ump_try_send(struct ump_send_chan *send_chan) { // send the callback assert(entry->callback != NULL); - entry->callback(entry->callback_arg, entry->payload, entry); + entry->callback(entry->callback_arg, entry); } } @@ -409,13 +409,16 @@ void ump_send ( struct ump_send_chan *chan, struct ump_send_queue_entry *entry, size_t header_size, - void *header, + const void *header, size_t payload_size, - void *payload, + const void *payload, ump_send_callback_fn_t callback, void *callback_arg ) { + assert(chan != NULL); + // initialize the queue entry + entry->state = UMP_SEND_ENTRY_STATE_START_MESSAGE; entry->header_size = header_size; entry->header = header; entry->payload_size = payload_size; @@ -440,6 +443,8 @@ void ump_recv_header ( ump_recv_header_callback_fn_t callback, void *callback_arg ) { + assert(chan != NULL); + thread_mutex_lock(&chan->recv_register_lock); // TODO rueegges: caller has to ensure it only registers at most once?! Or should we just make it a noop? assert(chan->state == UMP_RECV_STATE_IDLE); @@ -459,6 +464,8 @@ void ump_recv_payload ( ump_recv_payload_callback_fn_t callback, void *callback_arg ) { + assert(chan != NULL); + thread_mutex_lock(&chan->recv_register_lock); // TODO rueegges: caller has to ensure it only registers at most once?! Or should we just make it a noop? assert(chan->state == UMP_RECV_STATE_PAYLOAD_IDLE); diff --git a/usr/echoserver/main.c b/usr/echoserver/main.c index 8a55646..59edb3a 100644 --- a/usr/echoserver/main.c +++ b/usr/echoserver/main.c @@ -22,7 +22,7 @@ static void handle_header_recv(void *arg, size_t header_size, void *header, size } __attribute__((__used__)) -static void handle_send(void *arg, void *payload, struct ump_send_queue_entry *entry) { +static void handle_send(void *arg, struct ump_send_queue_entry *entry) { printf("Echo server: Message sent!\n"); } diff --git a/usr/hello/hello.c b/usr/hello/hello.c index 04c65d6..c4d8a48 100644 --- a/usr/hello/hello.c +++ b/usr/hello/hello.c @@ -54,7 +54,7 @@ static void handle_header_recv(void *arg, size_t header_size, void *header, size } __attribute__((__used__)) -static void handle_send(void *arg, void *payload, struct ump_send_queue_entry *entry) { +static void handle_send(void *arg, struct ump_send_queue_entry *entry) { printf("Echo client: Message sent!\n"); }