From cc164fe01bf910e9801b7f413a5e469b023ec6d0 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 8 Nov 2008 17:57:04 +0100 Subject: [PATCH] libcollectdclient: Implemented `lcc_flush'. --- src/libcollectdclient/client.c | 54 ++++++++++++++++++++++++++++++++++++++++-- src/libcollectdclient/client.h | 3 ++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/libcollectdclient/client.c b/src/libcollectdclient/client.c index 76855449..2ec27742 100644 --- a/src/libcollectdclient/client.c +++ b/src/libcollectdclient/client.c @@ -744,8 +744,58 @@ int lcc_putval (lcc_connection_t *c, const lcc_value_list_t *vl) /* {{{ */ return (0); } /* }}} int lcc_putval */ -/* TODO: Implement lcc_flush */ -int lcc_flush (lcc_connection_t *c, lcc_identifier_t *ident, int timeout); +int lcc_flush (lcc_connection_t *c, const char *plugin, /* {{{ */ + lcc_identifier_t *ident, int timeout) +{ + char command[1024]; + lcc_response_t res; + int status; + + if (c == NULL) + { + lcc_set_errno (c, EINVAL); + return (-1); + } + + SSTRCPY (command, "FLUSH"); + + if (timeout > 0) + SSTRCATF (command, " timeout=%i", timeout); + + if (plugin != NULL) + { + char buffer[2 * LCC_NAME_LEN]; + SSTRCATF (command, " plugin=%s", + lcc_strescape (buffer, plugin, sizeof (buffer))); + } + + if (ident != NULL) + { + char ident_str[6 * LCC_NAME_LEN]; + char ident_esc[12 * LCC_NAME_LEN]; + + status = lcc_identifier_to_string (c, ident_str, sizeof (ident_str), ident); + if (status != 0) + return (status); + + SSTRCATF (command, " identifier=%s", + lcc_strescape (ident_esc, ident_str, sizeof (ident_esc))); + } + + status = lcc_sendreceive (c, command, &res); + if (status != 0) + return (status); + + if (res.status != 0) + { + LCC_SET_ERRSTR (c, "Server error: %s", res.message); + lcc_response_free (&res); + return (-1); + } + + lcc_response_free (&res); + return (0); +} /* }}} int lcc_flush */ /* TODO: Implement lcc_putnotif */ diff --git a/src/libcollectdclient/client.h b/src/libcollectdclient/client.h index c54e3b7a..a0ab94c7 100644 --- a/src/libcollectdclient/client.h +++ b/src/libcollectdclient/client.h @@ -90,7 +90,8 @@ int lcc_getval (lcc_connection_t *c, lcc_identifier_t *ident, int lcc_putval (lcc_connection_t *c, const lcc_value_list_t *vl); -int lcc_flush (lcc_connection_t *c, lcc_identifier_t *ident, int timeout); +int lcc_flush (lcc_connection_t *c, const char *plugin, + lcc_identifier_t *ident, int timeout); int lcc_listval (lcc_connection_t *c, lcc_identifier_t **ret_ident, size_t *ret_ident_num); -- 2.11.0