[Bugfix] ump channel did not set initial state for send queue entries

This commit is contained in:
Sparchatus 2022-05-24 16:16:39 +00:00
parent f7441cb70d
commit 4dab497576
4 changed files with 19 additions and 12 deletions

View File

@ -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
);

View File

@ -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);

View File

@ -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");
}

View File

@ -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");
}