aboutsummaryrefslogtreecommitdiff
path: root/src/util/bio.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-06 09:28:24 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-06 09:28:24 +0000
commitaee28f4afd42710aba0c37d8ec86572aef092044 (patch)
treef20d80516465620c1fbcdbcc9b8df5d73ebf3568 /src/util/bio.c
parent2876ec10bbd2ffb912d3064a809d2f0a8fa044a8 (diff)
downloadgnunet-aee28f4afd42710aba0c37d8ec86572aef092044.tar.gz
gnunet-aee28f4afd42710aba0c37d8ec86572aef092044.zip
-improving docs
Diffstat (limited to 'src/util/bio.c')
-rw-r--r--src/util/bio.c74
1 files changed, 64 insertions, 10 deletions
diff --git a/src/util/bio.c b/src/util/bio.c
index b4f33f589..0c62021b5 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2006, 2009 Christian Grothoff (and other contributing authors) 3 (C) 2006, 2009, 2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -28,20 +28,51 @@
28 28
29#define LOG(kind,...) GNUNET_log_from (kind, "util",__VA_ARGS__) 29#define LOG(kind,...) GNUNET_log_from (kind, "util",__VA_ARGS__)
30 30
31/**
32 * Size for I/O buffers.
33 */
31#define BIO_BUFFER_SIZE 65536 34#define BIO_BUFFER_SIZE 65536
32 35
36/**
37 * Maximum size allowed for meta data written/read from disk.
38 * File-sharing limits to 64k, so this should be rather generous.
39 */
33#define MAX_META_DATA (1024 * 1024) 40#define MAX_META_DATA (1024 * 1024)
34 41
42
35/** 43/**
36 * Handle for buffered reading. 44 * Handle for buffered reading.
37 */ 45 */
38struct GNUNET_BIO_ReadHandle 46struct GNUNET_BIO_ReadHandle
39{ 47{
48 /**
49 * Underlying file abstraction.
50 */
40 struct GNUNET_DISK_FileHandle *fd; 51 struct GNUNET_DISK_FileHandle *fd;
52
53 /**
54 * Error message, NULL if there were no errors.
55 */
41 char *emsg; 56 char *emsg;
57
58 /**
59 * I/O buffer. Allocated at the end of the struct, do not free!
60 */
42 char *buffer; 61 char *buffer;
62
63 /**
64 * Number of bytes available in read @e buffer.
65 */
43 size_t have; 66 size_t have;
67
68 /**
69 * Total size of @e buffer.
70 */
44 size_t size; 71 size_t size;
72
73 /**
74 * Current read offset in @e buffer.
75 */
45 off_t pos; 76 off_t pos;
46}; 77};
47 78
@@ -78,7 +109,8 @@ GNUNET_BIO_read_open (const char *fn)
78 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 109 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
79 */ 110 */
80int 111int
81GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg) 112GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h,
113 char **emsg)
82{ 114{
83 int err; 115 int err;
84 116
@@ -103,7 +135,8 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
103 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 135 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
104 */ 136 */
105int 137int
106GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what, 138GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
139 const char *what,
107 void *result, size_t len) 140 void *result, size_t len)
108{ 141{
109 char *dst = result; 142 char *dst = result;
@@ -166,8 +199,11 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what,
166 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 199 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
167 */ 200 */
168int 201int
169GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file, int line, 202GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h,
170 void *result, size_t len) 203 const char *file,
204 int line,
205 void *result,
206 size_t len)
171{ 207{
172 char what[1024]; 208 char what[1024];
173 209
@@ -306,7 +342,8 @@ GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
306 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 342 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
307 */ 343 */
308int 344int
309GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, const char *file, 345GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
346 const char *file,
310 int line, int64_t * i) 347 int line, int64_t * i)
311{ 348{
312 int64_t big; 349 int64_t big;
@@ -323,9 +360,24 @@ GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
323 */ 360 */
324struct GNUNET_BIO_WriteHandle 361struct GNUNET_BIO_WriteHandle
325{ 362{
363 /**
364 * Underlying file handle.
365 */
326 struct GNUNET_DISK_FileHandle *fd; 366 struct GNUNET_DISK_FileHandle *fd;
367
368 /**
369 * I/O buffer. Do not free, allocated at the end of the struct.
370 */
327 char *buffer; 371 char *buffer;
372
373 /**
374 * Number of bytes already in @e buffer.
375 */
328 size_t have; 376 size_t have;
377
378 /**
379 * Total size of @e buffer.
380 */
329 size_t size; 381 size_t size;
330}; 382};
331 383
@@ -503,10 +555,11 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
503 * 555 *
504 * @param h hande to open file 556 * @param h hande to open file
505 * @param i 32-bit integer to write 557 * @param i 32-bit integer to write
506 * @return GNUNET_OK on success, GNUNET_SYSERR on error 558 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
507 */ 559 */
508int 560int
509GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i) 561GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
562 int32_t i)
510{ 563{
511 int32_t big; 564 int32_t big;
512 565
@@ -520,10 +573,11 @@ GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i)
520 * 573 *
521 * @param h hande to open file 574 * @param h hande to open file
522 * @param i 64-bit integer to write 575 * @param i 64-bit integer to write
523 * @return GNUNET_OK on success, GNUNET_SYSERR on error 576 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
524 */ 577 */
525int 578int
526GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i) 579GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h,
580 int64_t i)
527{ 581{
528 int64_t big; 582 int64_t big;
529 583