diff options
author | Alessio Vanni <vannilla@firemail.cc> | 2020-05-14 16:03:10 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-05-19 02:41:47 +0200 |
commit | f4771fcc1c3fda21a46d0cb85d8b29e012254696 (patch) | |
tree | 012df74ed2cf44cb20605b239e1b88dab6edc645 /src/statistics/gnunet-service-statistics.c | |
parent | 6a52ce5f9bc35a852b215e7073f3a0d2665ca8de (diff) | |
download | gnunet-f4771fcc1c3fda21a46d0cb85d8b29e012254696.tar.gz gnunet-f4771fcc1c3fda21a46d0cb85d8b29e012254696.zip |
Improved BIO API
BIO now supports reading from and writing to in-memory buffers.
For reading, an allocated buffer (array) and a size is passed as arguments to
the function opening the handle.
For writing, a GNUNET_Buffer is created and used internally. The buffer
contents can be extracted using the relevant function.
There is a new API in addition to the existing read/write: this new API is
more "declarative" in nature and is meant to mimic APIs like GNUNET_SQ.
The read/write operations are defined in an array of specs which are then
"commited" in a single (non-atomic) operation, rather than explicitly
executing multiple function calls and checking their return value.
Also there are small changes to GNUNET_Buffer to account for BIO's new
features.
Signed-off-by: Christian Grothoff <christian@grothoff.org>
Diffstat (limited to 'src/statistics/gnunet-service-statistics.c')
-rw-r--r-- | src/statistics/gnunet-service-statistics.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index 5d58c3743..d40f74aaf 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.c | |||
@@ -263,7 +263,7 @@ save () | |||
263 | return; | 263 | return; |
264 | } | 264 | } |
265 | (void) GNUNET_DISK_directory_create_for_file (fn); | 265 | (void) GNUNET_DISK_directory_create_for_file (fn); |
266 | wh = GNUNET_BIO_write_open (fn); | 266 | wh = GNUNET_BIO_write_open_file (fn); |
267 | total = 0; | 267 | total = 0; |
268 | while (NULL != (se = sub_head)) | 268 | while (NULL != (se = sub_head)) |
269 | { | 269 | { |
@@ -290,10 +290,10 @@ save () | |||
290 | msg->flags = | 290 | msg->flags = |
291 | htonl (pos->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0); | 291 | htonl (pos->persistent ? GNUNET_STATISTICS_SETFLAG_PERSISTENT : 0); |
292 | msg->value = GNUNET_htonll (pos->value); | 292 | msg->value = GNUNET_htonll (pos->value); |
293 | if (GNUNET_OK != GNUNET_BIO_write (wh, msg, size)) | 293 | if (GNUNET_OK != GNUNET_BIO_write (wh, "statistics-save-msg", msg, size)) |
294 | { | 294 | { |
295 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); | 295 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); |
296 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 296 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
297 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn); | 297 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn); |
298 | wh = NULL; | 298 | wh = NULL; |
299 | } | 299 | } |
@@ -309,7 +309,7 @@ save () | |||
309 | } | 309 | } |
310 | if (NULL != wh) | 310 | if (NULL != wh) |
311 | { | 311 | { |
312 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) | 312 | if (GNUNET_OK != GNUNET_BIO_write_close (wh, NULL)) |
313 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn); | 313 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn); |
314 | if (0 == total) | 314 | if (0 == total) |
315 | GNUNET_break (0 == unlink (fn)); | 315 | GNUNET_break (0 == unlink (fn)); |
@@ -964,7 +964,7 @@ load () | |||
964 | return; | 964 | return; |
965 | } | 965 | } |
966 | buf = GNUNET_malloc (fsize); | 966 | buf = GNUNET_malloc (fsize); |
967 | rh = GNUNET_BIO_read_open (fn); | 967 | rh = GNUNET_BIO_read_open_file (fn); |
968 | if (! rh) | 968 | if (! rh) |
969 | { | 969 | { |
970 | GNUNET_free (buf); | 970 | GNUNET_free (buf); |