ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
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;
7 atomic_store_int(&connection->state, SESSION_CONNECTION_STARTING);
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;
22 atomic_store_int(&connection->state, SESSION_CONNECTION_STOPPING);
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);
40 atomic_store_int(&connection->state, SESSION_CONNECTION_STOPPED);
41 return ASCIICHAT_OK;
42}
43
45 acip_transport_interrupt(transport);
46}
#define SET_ERRNO(code,...)
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
@ ERROR_INVALID_STATE
@ ASCIICHAT_OK
Definition error_codes.h:46
struct acip_transport acip_transport_t
Forward declaration of ACIP transport.
Definition host.h:506
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...