ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
src/common/session/connection.c
Go to the documentation of this file.
2
4 connection->owner_thread = thread_self();
5 connection->ops = ops;
6 connection->context = context;
8}
9
11 if (!connection || !thread_equal(connection->owner_thread, thread_self()))
12 return SET_ERRNO(ERROR_INVALID_STATE, "Connection startup requires its controlling thread");
13 int expected = SESSION_CONNECTION_STARTING;
14 if (!atomic_cas_int(&connection->state, &expected, SESSION_CONNECTION_RUNNING))
15 return SET_ERRNO(ERROR_INVALID_STATE, "Connection was stopped during startup");
16 return ASCIICHAT_OK;
17}
18
20 if (!connection || atomic_load_int(&connection->state) == SESSION_CONNECTION_STOPPED)
21 return;
23 if (connection->ops.interrupt)
24 connection->ops.interrupt(connection->context);
25}
26
28 if (!connection || atomic_load_int(&connection->state) == SESSION_CONNECTION_STOPPED)
29 return ASCIICHAT_OK;
31 if (!thread_equal(connection->owner_thread, thread_self()))
32 return SET_ERRNO(ERROR_INVALID_STATE, "Connection cleanup requires its controlling thread");
33 if (connection->ops.join) {
34 asciichat_error_t result = connection->ops.join(connection->context);
35 if (result != ASCIICHAT_OK)
36 return result;
37 }
38 if (connection->ops.release)
39 connection->ops.release(connection->context);
41 return ASCIICHAT_OK;
42}
43
45 acip_transport_interrupt(transport);
46}
#define SET_ERRNO(code,...)
void atomic_store_int(atomic_t *a, int value)
Atomically store an int value.
bool atomic_cas_int(atomic_t *a, int *expected, int new_value)
Atomically compare-and-swap an int.
int atomic_load_int(atomic_t *a)
Atomically load an int value.
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ERROR_INVALID_STATE
@ ASCIICHAT_OK
Definition error_codes.h:50
struct acip_transport acip_transport_t
Forward declaration of ACIP transport.
Definition host.h:508
asciichat_error_t session_connection_stop(session_connection_t *connection)
void session_connection_request_stop(session_connection_t *connection)
void session_connection_init(session_connection_t *connection, session_connection_ops_t ops, void *context)
asciichat_error_t session_connection_start(session_connection_t *connection)
void session_connection_interrupt_transport(acip_transport_t *transport)
@ SESSION_CONNECTION_STARTING
asciichat_error_t(* join)(void *context)
Groups the callbacks and caller data for session connection ops. The owner invokes these function poi...