diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-07-07 20:05:38 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-07-07 20:05:38 +0000 |
commit | ffb59a6a7fca6e70abfe5b87a997ed9cad989ec5 (patch) | |
tree | 58792ca0ea4ca6c461d0ffea8634b7dcf9f3fc90 /src/statistics | |
parent | 8f0b281a4ec9c9419fb10892b6ffbd12d4bea1a0 (diff) | |
download | gnunet-ffb59a6a7fca6e70abfe5b87a997ed9cad989ec5.tar.gz gnunet-ffb59a6a7fca6e70abfe5b87a997ed9cad989ec5.zip |
cleaning up disk api
Diffstat (limited to 'src/statistics')
-rw-r--r-- | src/statistics/gnunet-service-statistics.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index c7388ebd9..1c0981b80 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.c | |||
@@ -99,7 +99,8 @@ load (struct GNUNET_SERVER_Handle *server, | |||
99 | struct GNUNET_CONFIGURATION_Handle *cfg) | 99 | struct GNUNET_CONFIGURATION_Handle *cfg) |
100 | { | 100 | { |
101 | char *fn; | 101 | char *fn; |
102 | struct GNUNET_IO_Handle *fh, *mh; | 102 | struct GNUNET_DISK_FileHandle *fh; |
103 | struct GNUNET_DISK_MapHandle *mh; | ||
103 | struct stat sb; | 104 | struct stat sb; |
104 | char *buf; | 105 | char *buf; |
105 | size_t off; | 106 | size_t off; |
@@ -124,7 +125,7 @@ load (struct GNUNET_SERVER_Handle *server, | |||
124 | if (NULL == buf) | 125 | if (NULL == buf) |
125 | { | 126 | { |
126 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "mmap", fn); | 127 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "mmap", fn); |
127 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (&fh)); | 128 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); |
128 | GNUNET_free (fn); | 129 | GNUNET_free (fn); |
129 | return; | 130 | return; |
130 | } | 131 | } |
@@ -143,8 +144,8 @@ load (struct GNUNET_SERVER_Handle *server, | |||
143 | } | 144 | } |
144 | off += ntohs (msg->size); | 145 | off += ntohs (msg->size); |
145 | } | 146 | } |
146 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_unmap (&mh, buf, sb.st_size)); | 147 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_unmap (mh)); |
147 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (&fh)); | 148 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh)); |
148 | GNUNET_free (fn); | 149 | GNUNET_free (fn); |
149 | } | 150 | } |
150 | 151 | ||
@@ -160,10 +161,11 @@ save (void *cls, struct GNUNET_CONFIGURATION_Handle *cfg) | |||
160 | { | 161 | { |
161 | struct StatsEntry *pos; | 162 | struct StatsEntry *pos; |
162 | char *fn; | 163 | char *fn; |
163 | struct GNUNET_IO_Handle *fh; | 164 | struct GNUNET_DISK_FileHandle *fh; |
164 | uint16_t size; | 165 | uint16_t size; |
165 | unsigned long long total; | 166 | unsigned long long total; |
166 | 167 | ||
168 | fh = NULL; | ||
167 | fn = GNUNET_DISK_get_home_filename (cfg, | 169 | fn = GNUNET_DISK_get_home_filename (cfg, |
168 | "statistics", "statistics.data", NULL); | 170 | "statistics", "statistics.data", NULL); |
169 | if (fn != NULL) | 171 | if (fn != NULL) |
@@ -174,23 +176,24 @@ save (void *cls, struct GNUNET_CONFIGURATION_Handle *cfg) | |||
174 | while (NULL != (pos = start)) | 176 | while (NULL != (pos = start)) |
175 | { | 177 | { |
176 | start = pos->next; | 178 | start = pos->next; |
177 | if ((pos->persistent) && fh) | 179 | if ((pos->persistent) && (NULL != fh)) |
178 | { | 180 | { |
179 | size = htons (pos->msg->header.size); | 181 | size = htons (pos->msg->header.size); |
180 | if (size != GNUNET_DISK_file_write (fh, pos->msg, size)) | 182 | if (size != GNUNET_DISK_file_write (fh, pos->msg, size)) |
181 | { | 183 | { |
182 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 184 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
183 | "write", fn); | 185 | "write", fn); |
184 | GNUNET_DISK_file_close (&fh); | 186 | GNUNET_DISK_file_close (fh); |
187 | fh = NULL; | ||
185 | } | 188 | } |
186 | else | 189 | else |
187 | total += size; | 190 | total += size; |
188 | } | 191 | } |
189 | GNUNET_free (pos); | 192 | GNUNET_free (pos); |
190 | } | 193 | } |
191 | if (fh) | 194 | if (NULL != fh) |
192 | { | 195 | { |
193 | GNUNET_DISK_file_close (&fh); | 196 | GNUNET_DISK_file_close (fh); |
194 | if (total == 0) | 197 | if (total == 0) |
195 | GNUNET_break (0 == UNLINK (fn)); | 198 | GNUNET_break (0 == UNLINK (fn)); |
196 | else | 199 | else |