diff --git a/include/patty/client.h b/include/patty/client.h index 59fe9dd..0c78dc5 100644 --- a/include/patty/client.h +++ b/include/patty/client.h @@ -3,6 +3,7 @@ enum patty_client_call { PATTY_CLIENT_NONE, + PATTY_CLIENT_PING, PATTY_CLIENT_SOCKET, PATTY_CLIENT_SETSOCKOPT, PATTY_CLIENT_BIND, @@ -29,6 +30,11 @@ patty_client *patty_client_new(const char *path); void patty_client_destroy(patty_client *client); +/* + * ping() + */ +int patty_client_ping(patty_client *client); + /* * socket() */ diff --git a/src/client.c b/src/client.c index f71c322..6229ccd 100644 --- a/src/client.c +++ b/src/client.c @@ -101,6 +101,32 @@ void patty_client_destroy(patty_client *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 proto, int type) { diff --git a/src/server.c b/src/server.c index 19a6d52..2c9c0db 100644 --- a/src/server.c +++ b/src/server.c @@ -563,6 +563,12 @@ static int respond_connect(int client, int ret, int eno) { 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) { patty_client_socket_request request; patty_client_socket_response response; @@ -981,6 +987,7 @@ error_io: static patty_ax25_server_call server_calls[PATTY_CLIENT_CALL_COUNT] = { NULL, + server_ping, server_socket, server_setsockopt, server_bind,