Skip to content

Commit

Permalink
Support multi threaded read/write
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-mariappan-ramasamy committed Jan 6, 2025
1 parent 36f183b commit eb3855b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 0 additions & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
:defines:
:release:
- _FORTIFY_SOURCE=2
- ENABLE_MULTITHREADED
:test:
- TEST

Expand Down
6 changes: 3 additions & 3 deletions src/he/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1236,12 +1236,12 @@ he_return_code_t he_conn_pmtud_probe_timeout(he_conn_t *conn) {
return he_internal_pmtud_handle_probe_timeout(conn);
}

#ifdef ENABLE_MULTITHREADED
#ifdef HE_ENABLE_MULTITHREADED
thread_local int wolf_error = 0;
#endif

void he_conn_set_ssl_error(he_conn_t *conn, int error) {
#ifdef ENABLE_MULTITHREADED
#ifdef HE_ENABLE_MULTITHREADED
(void) conn;
wolf_error = error;
#else
Expand All @@ -1250,7 +1250,7 @@ void he_conn_set_ssl_error(he_conn_t *conn, int error) {
}

int he_conn_get_ssl_error(he_conn_t *conn) {
#ifdef ENABLE_MULTITHREADED
#ifdef HE_ENABLE_MULTITHREADED
return wolf_error;
#else
return conn->wolf_error;
Expand Down
24 changes: 15 additions & 9 deletions src/he/he_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
# endif
#endif

#ifdef HE_ENABLE_MULTITHREADED
# define HE_ATOMIC _Atomic
#else
# define HE_ATOMIC
#endif

typedef struct he_packet_buffer {
// Buffer has data
bool has_packet;
Expand Down Expand Up @@ -146,7 +152,7 @@ typedef struct he_internal_pmtud_ {
he_pmtud_state_t state;

/// Current effective PMTU
_Atomic uint16_t effective_pmtu;
HE_ATOMIC uint16_t effective_pmtu;

/// PMTUD internal data
uint16_t base;
Expand Down Expand Up @@ -236,10 +242,10 @@ struct he_conn {
// -------------- State (Mutable) -----------------

/// Client State
_Atomic he_conn_state_t state;
HE_ATOMIC he_conn_state_t state;

/// Wolf Timeout
_Atomic int wolf_timeout;
HE_ATOMIC int wolf_timeout;

/// Pointer to incoming data buffer
uint8_t *incoming_data;
Expand All @@ -256,14 +262,14 @@ struct he_conn {
uint8_t write_buffer[HE_MAX_WIRE_MTU];

/// Session ID
_Atomic uint64_t session_id;
_Atomic uint64_t pending_session_id;
HE_ATOMIC uint64_t session_id;
HE_ATOMIC uint64_t pending_session_id;

/// Has the first message been received?
_Atomic bool first_message_received;
HE_ATOMIC bool first_message_received;

/// Do we already have a timer running? If so, we don't want to generate new callbacks
_Atomic bool is_nudge_timer_running;
HE_ATOMIC bool is_nudge_timer_running;

bool renegotiation_in_progress;
bool renegotiation_due;
Expand All @@ -276,10 +282,10 @@ struct he_conn {
he_internal_pmtud_t pmtud;

/// UDP Fragmentation
_Atomic uint16_t frag_next_id;
HE_ATOMIC uint16_t frag_next_id;
he_fragment_table_t *frag_table;

#ifndef ENABLE_MULTITHREADED
#ifndef HE_ENABLE_MULTITHREADED
/// Last wolfssl error
int wolf_error;
#endif
Expand Down

0 comments on commit eb3855b

Please sign in to comment.