Go to the source code of this file.
Functions | |
void | DieWithError (char *errorMessage) |
int | ksock_init (char terminator, unsigned buffer_len) |
int | ksock_server_open (ksock_t *server, unsigned short port) |
int | ksock_next_connection (ksock_t *server) |
int | ksock_add_command (const char *name, int min_param, int max_param, int(*function)(int argc, char *argv[], void *data)) |
int | ksock_remove_command (char *name) |
void | list_command () |
int | ksock_send_command (int socket, char *cmd,...) |
int | ksock_send_answer (int *socketStorage, char *cmd) |
int | ksock_exec_command_pending (int clntSock, char *cmd) |
int | ksock_exec_command (char *cmd) |
int | ksock_get_command (int clntSocket, char *cmdBuffer, unsigned bufSize) |
int | ksock_connect (char *servIP, unsigned short servPort) |
int | ksock_server_close (ksock_t *server) |
Variables | |
static char | ksock_command_terminator = '\n' |
static char * | ksock_buf_snd = NULL |
static unsigned | ksock_buf_len = 0 |
static struct kb_command_s * | ksock_cmd_list = NULL |
unsigned | ksock_cmd_n |
void DieWithError | ( | char * | errorMessage | ) |
Definition at line 20 of file kb_socket.c.
Referenced by ksock_connect(), ksock_get_command(), ksock_next_connection(), ksock_send_answer(), ksock_send_command(), ksock_server_open(), and main().
int ksock_add_command | ( | const char * | name, | |
int | min_param, | |||
int | max_param, | |||
int(*)(int argc, char *argv[], void *data) | function | |||
) |
Add a network command to the command list. The number of argument does include the name of the command itself. That means a command without args should have 1 as both min_param and max_param.
Definition at line 113 of file kb_socket.c.
References KB_ALLOC, KB_ERROR, KB_ERROR_NOINIT, KB_REALLOC, ksock_cmd_n, kb_command_s::maxParam, kb_command_s::minParam, kb_command_s::name, and kb_command_s::parse.
Referenced by main().
int ksock_connect | ( | char * | servIP, | |
unsigned short | servPort | |||
) |
Try to connect to the given server
clntSocket | The connection id | |
cmdBuffer | The receive buffer allocated by the caller | |
bufSize | The size of the receive buffer |
Definition at line 370 of file kb_socket.c.
References DieWithError(), and sock.
Referenced by main().
int ksock_exec_command | ( | char * | cmd | ) |
Execute a network command
cmd | the command line |
Definition at line 285 of file kb_socket.c.
References KB_ERROR, KB_ERROR_NOINIT, and kb_parse_command().
Referenced by main().
int ksock_exec_command_pending | ( | int | clntSock, | |
char * | cmd | |||
) |
Send a network command through the given socket and wait for an acknowledge from the server. If the acknowledge is not received before the given timeout, the function returns with an error code.
socket | the receiving socket | |
cmd | the command line |
The application should send the corresponding answer using ksock_send_answer.
Such network commands must use the following syntax: The fisrt word is the command name. The second word is the request id (unsigned long integer). The following words are the command parameters.
cmd | the command line | |
clntSock | the connection id |
Definition at line 260 of file kb_socket.c.
References KB_ALLOC, KB_ERROR, KB_ERROR_NOINIT, and kb_parse_command().
Referenced by main().
int ksock_get_command | ( | int | clntSocket, | |
char * | cmdBuffer, | |||
unsigned | bufSize | |||
) |
Get a command from the given connection.
clntSocket | The connection id | |
cmdBuffer | The receive buffer allocated by the caller | |
bufSize | The size of the receive buffer |
Definition at line 308 of file kb_socket.c.
References DieWithError(), and ksock_command_terminator.
Referenced by main().
int ksock_init | ( | char | terminator, | |
unsigned | buffer_len | |||
) |
Initialize the socket library
terminator | The termination characters for network commands | |
buffer_len | length of the buffer to send commands |
Definition at line 31 of file kb_socket.c.
References KB_ALLOC, ksock_buf_len, ksock_buf_snd, ksock_cmd_n, ksock_command_terminator, kb_command_s::maxParam, kb_command_s::minParam, kb_command_s::name, and kb_command_s::parse.
Referenced by main().
int ksock_next_connection | ( | ksock_t * | server | ) |
Get the next connection to the given server
Definition at line 82 of file kb_socket.c.
References DieWithError(), KB_WARN_CONNECT, kb_warning(), and ksock_s::serv_socket.
Referenced by main().
int ksock_remove_command | ( | char * | name | ) |
Remove a network command from the command list
Definition at line 146 of file kb_socket.c.
References KB_ERROR, KB_ERROR_NOINIT, kb_find_command(), ksock_cmd_n, kb_command_s::maxParam, kb_command_s::minParam, kb_command_s::name, and kb_command_s::parse.
int ksock_send_answer | ( | int * | socketStorage, | |
char * | cmd | |||
) |
Send a network answer through the given socket this function should be called from a command function to send the answer back after a ksock_exec_command_pending.
socket | the receiving socket | |
cmd | the command line |
Definition at line 216 of file kb_socket.c.
References DieWithError(), kb_free, ksock_buf_len, ksock_buf_snd, and ksock_command_terminator.
Referenced by kmot_ipConfigPID(), kmot_ipFirmware(), kmot_ipInitMotor(), kmot_ipMeasure(), kmot_ipResetError(), kmot_ipSetPointSource(), kmot_ipSetPos(), kmot_ipSetSpeed(), and kmot_ipStatus().
int ksock_send_command | ( | int | socket, | |
char * | cmd, | |||
... | ||||
) |
Send a network command through the given socket
socket | the receiving socket | |
cmd | the command line |
Definition at line 186 of file kb_socket.c.
References DieWithError(), ksock_buf_len, ksock_buf_snd, and ksock_command_terminator.
Referenced by handle_joyaxis(), and handle_joybutton().
int ksock_server_close | ( | ksock_t * | server | ) |
Definition at line 392 of file kb_socket.c.
int ksock_server_open | ( | ksock_t * | server, | |
unsigned short | port | |||
) |
Open a server socket
Definition at line 54 of file kb_socket.c.
References DieWithError(), MAXPENDING, ksock_s::serv_addr, and ksock_s::serv_socket.
Referenced by main().
void list_command | ( | ) |
Definition at line 171 of file kb_socket.c.
References kb_command_s::maxParam, kb_command_s::minParam, and kb_command_s::name.
Referenced by main().
unsigned ksock_buf_len = 0 [static] |
Definition at line 15 of file kb_socket.c.
Referenced by ksock_init(), ksock_send_answer(), and ksock_send_command().
char* ksock_buf_snd = NULL [static] |
Definition at line 14 of file kb_socket.c.
Referenced by ksock_init(), ksock_send_answer(), and ksock_send_command().
struct kb_command_s* ksock_cmd_list = NULL [static] |
Definition at line 17 of file kb_socket.c.
unsigned ksock_cmd_n |
Definition at line 18 of file kb_socket.c.
Referenced by ksock_add_command(), ksock_init(), and ksock_remove_command().
char ksock_command_terminator = '\n' [static] |
Definition at line 13 of file kb_socket.c.
Referenced by ksock_get_command(), ksock_init(), ksock_send_answer(), and ksock_send_command().