Go to the source code of this file.
Functions |
| static command_buffer * | command_buffer_new (size_t len, uint8 *data) |
| void | command_buffer_free (command_buffer *buf) |
| static void | command_buffer_enqueue (command_buffer *buf, command_buffer **queue_start, command_buffer **queue_end) |
| static command_buffer * | command_buffer_dequeue (command_buffer **queue_start, command_buffer **queue_end) |
| int | send_command_binary (uint8 cmd, uint8 *body, unsigned int len) |
| int | send_socklist (SockList msg) |
| command_buffer * | get_next_input_command () |
|
static int | reader_thread_loop (void *dummy) |
| static int | writer_thread_loop (void *dummy) |
| void | socket_thread_start () |
| void | socket_thread_stop () |
| int | handle_socket_shutdown () |
| int | socket_get_error () |
| int | socket_close (struct ClientSocket *csock) |
| int | socket_initialize () |
| void | socket_deinitialize () |
| static int | socket_create (int *fd, char *host, int port) |
| int | socket_open (struct ClientSocket *csock, char *host, int port) |
Variables |
|
static SDL_Thread * | input_thread |
|
static SDL_mutex * | input_buffer_mutex |
|
static SDL_cond * | input_buffer_cond |
|
static SDL_Thread * | output_thread |
|
static SDL_mutex * | output_buffer_mutex |
|
static SDL_cond * | output_buffer_cond |
| static SDL_mutex * | socket_mutex |
| static int | abort_thread = 0 |
|
static command_buffer * | input_queue_start = NULL |
|
static command_buffer * | input_queue_end = NULL |
|
static command_buffer * | output_queue_start = NULL |
|
static command_buffer * | output_queue_end = NULL |
Detailed Description
Socket related code.
Definition in file socket.c.
Function Documentation
Remove the first command buffer from a queue.
Definition at line 105 of file socket.c.
Enqueue a command buffer last in a queue.
Definition at line 85 of file socket.c.
Free all memory related to a single command buffer.
- Parameters:
-
Definition at line 78 of file socket.c.
Create a new command buffer of the given size, copying the data buffer if not NULL. The buffer will always be null-terminated for safety (and one byte larger than requested).
- Parameters:
-
| len | Requested buffer size in bytes. |
| data | Buffer data to copy (len bytes), or NULL. |
- Returns:
- A new command buffer or NULL in case of an error.
Definition at line 59 of file socket.c.
Get a command from the queue.
- Returns:
- The command (being removed from queue), NULL if there is no command.
Definition at line 193 of file socket.c.
| int handle_socket_shutdown |
( |
| ) |
|
Detect and handle socket system shutdowns. Also reset the socket system for a restart.
The main thread should poll this function which detects connection shutdowns and removes the threads if it happens.
Definition at line 446 of file socket.c.
| int send_command_binary |
( |
uint8 |
cmd, |
|
|
uint8 * |
body, |
|
|
unsigned int |
len |
|
) |
| |
Add a binary command to the output buffer. If body is NULL, a single-byte command is created from cmd. Otherwise body should include the length and cmd header.
Definition at line 130 of file socket.c.
Move a command buffer to the out buffer so it can be written to the socket.
Definition at line 166 of file socket.c.
Close a socket.
- Parameters:
-
Definition at line 486 of file socket.c.
| static int socket_create |
( |
int * |
fd, |
|
|
char * |
host, |
|
|
int |
port |
|
) |
| [static] |
Create a new socket.
- Parameters:
-
| [out] | fd | File descriptor we'll update. |
| host | Host to connect to. |
| port | Port to use. |
- Returns:
- 1 on success, 0 on failure.
Definition at line 580 of file socket.c.
| void socket_deinitialize |
( |
| ) |
|
Deinitialize the socket.
Definition at line 562 of file socket.c.
Get error number.
- Returns:
- The error number.
Definition at line 474 of file socket.c.
| int socket_initialize |
( |
| ) |
|
Initialize the socket.
- Returns:
- 1 on success, 0 on failure.
Definition at line 527 of file socket.c.
| int socket_open |
( |
struct ClientSocket * |
csock, |
|
|
char * |
host, |
|
|
int |
port |
|
) |
| |
Open a new socket.
- Parameters:
-
| csock | Socket to open. |
| host | Host to connect to. |
| port | Port to connect to. |
- Returns:
- 1 on success, 0 on failure.
Definition at line 792 of file socket.c.
| void socket_thread_start |
( |
| ) |
|
Initialize and start up the worker threads.
Definition at line 395 of file socket.c.
| void socket_thread_stop |
( |
| ) |
|
Wait for the socket threads to finish. Closes the socket first, if it hasn't already been done.
Definition at line 428 of file socket.c.
| static int writer_thread_loop |
( |
void * |
dummy | ) |
[static] |
Worker for the writer thread. It waits for enqueued outgoing packets and sends them to the server as fast as it can.
If any error is detected, the socket is closed and the thread exits. It is up to them main thread to detect this and join() the worker threads.
Definition at line 330 of file socket.c.
Variable Documentation
All socket threads will exit if they see this flag set.
Definition at line 46 of file socket.c.
Mutex to protect socket deinitialization.
Definition at line 42 of file socket.c.