Skip to content

Commit 22ee2f8

Browse files
committed
lirc: Add support for client pings.
Currently, LIRC only supports server pings (server pings us, we pong back), but clients can send pings too and get pongs back (typically to measure lag). Add support for this. PONG is intentionally being added right after PING in the enum, so this does NOT preserve ABI across versions.
1 parent 905d2c4 commit 22ee2f8

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ master, dev ]
66
pull_request:
77
branches: [ master ]
88

irc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,11 @@ int irc_client_notice(struct irc_client *client, const char *channel, const char
870870
return irc_send(client, "NOTICE %s :%s", channel, msg);
871871
}
872872

873+
int irc_client_ping(struct irc_client *client, const char *pingmsg)
874+
{
875+
return irc_send(client, "PING :%s", pingmsg);
876+
}
877+
873878
int irc_client_pong(struct irc_client *client, struct irc_msg *msg)
874879
{
875880
/* Reply with the same data that it sent us (some servers may actually require that) */
@@ -1035,6 +1040,8 @@ int irc_parse_msg_type(struct irc_msg *msg)
10351040
}
10361041
} else if (!strcasecmp(c, "PING")) {
10371042
msg->type = IRC_CMD_PING;
1043+
} else if (!strcasecmp(c, "PONG")) {
1044+
msg->type = IRC_CMD_PONG;
10381045
} else if (!strcasecmp(c, "JOIN")) {
10391046
msg->type = IRC_CMD_JOIN;
10401047
PARSE_CHANNEL();

irc.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
*/
1212

1313
#define LIRC_VERSION_MAJOR 1
14-
#define LIRC_VERSION_MINOR 0
15-
#define LIRC_VERSION_PATCH 1
14+
#define LIRC_VERSION_MINOR 1
15+
#define LIRC_VERSION_PATCH 0
1616

1717
/*! \brief Maximum length of an IRC message, including trailing CR LF */
1818
#define IRC_MAX_MSG_LEN 512
@@ -29,6 +29,7 @@ enum irc_msg_type {
2929
IRC_CMD_PRIVMSG,
3030
IRC_CMD_NOTICE, /*!< Same as PRIVMSG, but should never be acknowledged, to prevent loops */
3131
IRC_CMD_PING,
32+
IRC_CMD_PONG,
3233
IRC_CMD_JOIN,
3334
IRC_CMD_PART,
3435
IRC_CMD_QUIT,
@@ -204,6 +205,18 @@ int irc_client_msg(struct irc_client *client, const char *channel, const char *m
204205
*/
205206
int irc_client_notice(struct irc_client *client, const char *channel, const char *msg);
206207

208+
/*!
209+
* \brief Send a PING message to the server
210+
* \param client
211+
* \param pingmsg A user-provided message that will be echoed back in the PONG reply
212+
* \retval 0 on success, -1 on failure
213+
* \note Servers are responsible for pinging clients, so normally, clients don't
214+
* need to initiate pings to the server. However, this can be useful
215+
* if the client wants to measure lag (by processing IRC_CMD_PONG).
216+
* Note the PONG response has format '<hostname> :<ping message>'
217+
*/
218+
int irc_client_ping(struct irc_client *client, const char *pingmsg);
219+
207220
/*!
208221
* \brief Send a PONG reply to a PING message
209222
* \param client

0 commit comments

Comments
 (0)