Implement patty_client_ping()
Implement patty_client_ping() to provide a means of testing if a client connection is still active
This commit is contained in:
parent
5edb889471
commit
116bf788d5
3 changed files with 39 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
enum patty_client_call {
|
enum patty_client_call {
|
||||||
PATTY_CLIENT_NONE,
|
PATTY_CLIENT_NONE,
|
||||||
|
PATTY_CLIENT_PING,
|
||||||
PATTY_CLIENT_SOCKET,
|
PATTY_CLIENT_SOCKET,
|
||||||
PATTY_CLIENT_SETSOCKOPT,
|
PATTY_CLIENT_SETSOCKOPT,
|
||||||
PATTY_CLIENT_BIND,
|
PATTY_CLIENT_BIND,
|
||||||
|
@ -29,6 +30,11 @@ patty_client *patty_client_new(const char *path);
|
||||||
|
|
||||||
void patty_client_destroy(patty_client *client);
|
void patty_client_destroy(patty_client *client);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ping()
|
||||||
|
*/
|
||||||
|
int patty_client_ping(patty_client *client);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* socket()
|
* socket()
|
||||||
*/
|
*/
|
||||||
|
|
26
src/client.c
26
src/client.c
|
@ -101,6 +101,32 @@ void patty_client_destroy(patty_client *client) {
|
||||||
free(client);
|
free(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int patty_client_ping(patty_client *client) {
|
||||||
|
int call = PATTY_CLIENT_PING,
|
||||||
|
pong;
|
||||||
|
|
||||||
|
ssize_t len;
|
||||||
|
|
||||||
|
if ((len = write(client->fd, &call, sizeof(call))) < 0 || len == 0) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((len = read(client->fd, &pong, sizeof(pong))) < 0 || len == 0) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pong;
|
||||||
|
|
||||||
|
done:
|
||||||
|
if (errno == 0 || errno == EIO) {
|
||||||
|
errno = 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int patty_client_socket(patty_client *client,
|
int patty_client_socket(patty_client *client,
|
||||||
int proto,
|
int proto,
|
||||||
int type) {
|
int type) {
|
||||||
|
|
|
@ -563,6 +563,12 @@ static int respond_connect(int client, int ret, int eno) {
|
||||||
return write(client, &response, sizeof(response));
|
return write(client, &response, sizeof(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int server_ping(patty_ax25_server *server, int client) {
|
||||||
|
int pong = 1;
|
||||||
|
|
||||||
|
return write(client, &pong, sizeof(pong));
|
||||||
|
}
|
||||||
|
|
||||||
static int server_socket(patty_ax25_server *server, int client) {
|
static int server_socket(patty_ax25_server *server, int client) {
|
||||||
patty_client_socket_request request;
|
patty_client_socket_request request;
|
||||||
patty_client_socket_response response;
|
patty_client_socket_response response;
|
||||||
|
@ -981,6 +987,7 @@ error_io:
|
||||||
|
|
||||||
static patty_ax25_server_call server_calls[PATTY_CLIENT_CALL_COUNT] = {
|
static patty_ax25_server_call server_calls[PATTY_CLIENT_CALL_COUNT] = {
|
||||||
NULL,
|
NULL,
|
||||||
|
server_ping,
|
||||||
server_socket,
|
server_socket,
|
||||||
server_setsockopt,
|
server_setsockopt,
|
||||||
server_bind,
|
server_bind,
|
||||||
|
|
Loading…
Add table
Reference in a new issue