struct Client;
struct ConfItem;
+/** Tracks state of a UDP ping to some other server. */
struct UPing
{
- struct UPing* next; /* next ping in list, usually null */
- int fd; /* socket file descriptor */
- struct irc_sockaddr addr; /* socket name (ip addr, port, family ) */
- char count; /* number of pings requested */
- char sent; /* pings sent */
- char received; /* pings received */
- char active; /* ping active flag */
- struct Client* client; /* who requested the pings */
- time_t lastsent; /* when last ping was sent */
- int ms_min; /* minimum time in milliseconds */
- int ms_ave; /* average time in milliseconds */
- int ms_max; /* maximum time in milliseconds */
- int index; /* index into poll array */
- struct Socket socket; /* socket structure */
- struct Timer sender; /* timer telling when next to send a ping */
- struct Timer killer; /* timer to kill us */
- unsigned int freeable; /* zero when structure can be free()'d */
- char name[HOSTLEN + 1]; /* server name to poing */
- char buf[BUFSIZE]; /* buffer to hold ping times */
+ struct UPing* next; /**< next ping in list */
+ int fd; /**< socket file descriptor */
+ struct irc_sockaddr addr; /**< socket name (ip addr, port, family ) */
+ char count; /**< number of pings requested */
+ char sent; /**< pings sent */
+ char received; /**< pings received */
+ char active; /**< ping active flag */
+ struct Client* client; /**< who requested the pings */
+ time_t lastsent; /**< when last ping was sent */
+ int ms_min; /**< minimum time in milliseconds */
+ int ms_ave; /**< average time in milliseconds */
+ int ms_max; /**< maximum time in milliseconds */
+ struct Socket socket; /**< socket structure */
+ struct Timer sender; /**< timer telling when next to send a ping */
+ struct Timer killer; /**< timer to kill us */
+ unsigned int freeable; /**< zero when structure can be free()'d */
+ char name[HOSTLEN + 1]; /**< server name to poing */
+ char buf[BUFSIZE]; /**< buffer to hold ping times */
};
-#define UPING_PENDING_SOCKET 0x01 /* pending socket destruction event */
-#define UPING_PENDING_SENDER 0x02 /* pending sender destruction event */
-#define UPING_PENDING_KILLER 0x04 /* pending killer destruction event */
-
-extern int UPingFileDescriptor;
+#define UPING_PENDING_SOCKET 0x01 /**< pending socket destruction event */
+#define UPING_PENDING_SENDER 0x02 /**< pending sender destruction event */
+#define UPING_PENDING_KILLER 0x04 /**< pending killer destruction event */
extern int uping_init(void);
extern void uping_send(struct UPing* pptr);
#include <sys/time.h>
#include <unistd.h>
-#define UPINGTIMEOUT 60 /* Timeout waiting for ping responses */
+#define UPINGTIMEOUT 60 /**< Timeout waiting for ping responses */
-static struct UPing* pingList = 0;
-int UPingFileDescriptor = -1; /* UDP listener socket for upings */
+static struct UPing* pingList = 0; /**< Linked list of UPing structs */
+static int UPingFileDescriptor = -1; /**< UDP listener socket for upings */
+static struct Socket upingSock; /**< Socket struct for upings */
-static struct Socket upingSock;
-
-/*
- * pings_begin - iterator function for ping list
+/** Start iteration of uping list.
+ * @return Start of uping list.
*/
struct UPing* uping_begin(void)
{
return pingList;
}
-/*
- * pings_erase - removes ping struct from ping list
+/** Removes \a p from uping list.
+ * @param[in,out] p UPing to remove from list.
*/
static void uping_erase(struct UPing* p)
{
struct UPing* last = 0;
assert(0 != p);
-
+
for (it = pingList; it; last = it, it = it->next) {
if (p == it) {
if (last)
}
}
-/* Called when the event engine detects activity on the UPing socket */
+/** Callback for uping listener socket.
+ * @param[in] ev I/O event for uping socket.
+ */
static void uping_echo_callback(struct Event* ev)
{
assert(ev_type(ev) == ET_READ || ev_type(ev) == ET_ERROR);
uping_echo();
}
-/*
- * Setup a UDP socket and listen for incoming packets
+/** Initialize a UDP socket for upings.
+ * @returns File descriptor of UDP socket (-1 on error).
*/
int uping_init(void)
{
}
-/*
- * max # of pings set to 15/sec.
+/** Read a uping from the socket and respond (but not more than 10
+ * times per second).
*/
void uping_echo()
{
}
-/* Callback when socket has data to read */
+/** Callback for socket activity on an outbound uping socket.
+ * @param[in] ev I/O event for socket.
+ */
static void uping_read_callback(struct Event* ev)
{
struct UPing *pptr;
}
}
-/* Callback to send another ping */
+/** Timer callback to send another outbound uping.
+ * @param[in] ev Event for uping timer.
+ */
static void uping_sender_callback(struct Event* ev)
{
struct UPing *pptr;
}
}
-/* Callback to kill a ping */
+/** Timer callback to stop upings.
+ * @param[in] ev Event for uping expiration.
+ */
static void uping_killer_callback(struct Event* ev)
{
struct UPing *pptr;
}
}
-/*
- * start_ping
+/** Start a uping.
+ * This sets up the timers, UPing flags, and sends a notice to the
+ * requesting client.
*/
static void uping_start(struct UPing* pptr)
{
pptr->active = 1;
}
-/*
- * uping_send
- *
+/** Send a uping to another server.
+ * @param[in] pptr Descriptor for uping.
*/
void uping_send(struct UPing* pptr)
{
++pptr->sent;
}
-/*
- * read_ping
+/** Read the response from an outbound uping.
+ * @param[in] pptr UPing to check.
*/
void uping_read(struct UPing* pptr)
{
return;
}
+/** Start sending upings to a server.
+ * @param[in] sptr Client requesting the upings.
+ * @param[in] aconf ConfItem containing the address to ping.
+ * @param[in] port Port number to ping.
+ * @param[in] count Number of times to ping (should be at least 20).
+ * @return Zero.
+ */
int uping_server(struct Client* sptr, struct ConfItem* aconf, int port, int count)
{
int fd;
pptr->addr.port = port;
pptr->count = IRCD_MIN(20, count);
pptr->client = sptr;
- pptr->index = -1;
pptr->freeable = UPING_PENDING_SOCKET;
strcpy(pptr->name, aconf->name);
return 0;
}
-
+/** Clean up a UPing structure, reporting results to the requester.
+ * @param[in,out] pptr UPing results.
+ */
void uping_end(struct UPing* pptr)
{
Debug((DEBUG_DEBUG, "uping_end: %p", pptr));
timer_del(&pptr->killer);
}
+/** Change notifications for any upings by \a sptr.
+ * @param[in] sptr Client to stop notifying.
+ * @param[in] acptr New client to notify (or NULL).
+ */
void uping_cancel(struct Client *sptr, struct Client* acptr)
{
struct UPing* ping;