diff options
author | Nils Durner <durner@gnunet.org> | 2009-06-15 20:11:51 +0000 |
---|---|---|
committer | Nils Durner <durner@gnunet.org> | 2009-06-15 20:11:51 +0000 |
commit | 1088905b5a89a24706d2c1877d289589e3f3c222 (patch) | |
tree | 38ec7cdc1b80502aa950c68ebefe1e3f42efa14b /src/statistics/gnunet-service-statistics.c | |
parent | 7e3df72d6b8a32b15b02110b54c77f77e28928a2 (diff) | |
download | gnunet-1088905b5a89a24706d2c1877d289589e3f3c222.tar.gz gnunet-1088905b5a89a24706d2c1877d289589e3f3c222.zip |
more complete DISK API
Diffstat (limited to 'src/statistics/gnunet-service-statistics.c')
-rw-r--r-- | src/statistics/gnunet-service-statistics.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index 42ff8d927..c7388ebd9 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.c | |||
@@ -99,7 +99,7 @@ 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 | int fd; | 102 | struct GNUNET_IO_Handle *fh, *mh; |
103 | struct stat sb; | 103 | struct stat sb; |
104 | char *buf; | 104 | char *buf; |
105 | size_t off; | 105 | size_t off; |
@@ -114,17 +114,17 @@ load (struct GNUNET_SERVER_Handle *server, | |||
114 | GNUNET_free (fn); | 114 | GNUNET_free (fn); |
115 | return; | 115 | return; |
116 | } | 116 | } |
117 | fd = GNUNET_DISK_file_open (fn, O_RDONLY); | 117 | fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ); |
118 | if (fd == -1) | 118 | if (!fh) |
119 | { | 119 | { |
120 | GNUNET_free (fn); | 120 | GNUNET_free (fn); |
121 | return; | 121 | return; |
122 | } | 122 | } |
123 | buf = MMAP (NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0); | 123 | buf = GNUNET_DISK_file_map (fh, &mh, GNUNET_DISK_MAP_READ, sb.st_size); |
124 | if (MAP_FAILED == buf) | 124 | if (NULL == buf) |
125 | { | 125 | { |
126 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "mmap", fn); | 126 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "mmap", fn); |
127 | GNUNET_break (0 == CLOSE (fd)); | 127 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (&fh)); |
128 | GNUNET_free (fn); | 128 | GNUNET_free (fn); |
129 | return; | 129 | return; |
130 | } | 130 | } |
@@ -143,8 +143,8 @@ load (struct GNUNET_SERVER_Handle *server, | |||
143 | } | 143 | } |
144 | off += ntohs (msg->size); | 144 | off += ntohs (msg->size); |
145 | } | 145 | } |
146 | GNUNET_break (0 == MUNMAP (buf, sb.st_size)); | 146 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_unmap (&mh, buf, sb.st_size)); |
147 | GNUNET_break (0 == CLOSE (fd)); | 147 | GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (&fh)); |
148 | GNUNET_free (fn); | 148 | GNUNET_free (fn); |
149 | } | 149 | } |
150 | 150 | ||
@@ -160,39 +160,37 @@ save (void *cls, struct GNUNET_CONFIGURATION_Handle *cfg) | |||
160 | { | 160 | { |
161 | struct StatsEntry *pos; | 161 | struct StatsEntry *pos; |
162 | char *fn; | 162 | char *fn; |
163 | int fd; | 163 | struct GNUNET_IO_Handle *fh; |
164 | uint16_t size; | 164 | uint16_t size; |
165 | unsigned long long total; | 165 | unsigned long long total; |
166 | 166 | ||
167 | fd = -1; | ||
168 | fn = GNUNET_DISK_get_home_filename (cfg, | 167 | fn = GNUNET_DISK_get_home_filename (cfg, |
169 | "statistics", "statistics.data", NULL); | 168 | "statistics", "statistics.data", NULL); |
170 | if (fn != NULL) | 169 | if (fn != NULL) |
171 | fd = | 170 | fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_WRITE |
172 | GNUNET_DISK_file_open (fn, O_WRONLY | O_CREAT | O_TRUNC, | 171 | | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_TRUNCATE, |
173 | S_IRUSR | S_IWUSR); | 172 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); |
174 | total = 0; | 173 | total = 0; |
175 | while (NULL != (pos = start)) | 174 | while (NULL != (pos = start)) |
176 | { | 175 | { |
177 | start = pos->next; | 176 | start = pos->next; |
178 | if ((pos->persistent) && (fd != -1)) | 177 | if ((pos->persistent) && fh) |
179 | { | 178 | { |
180 | size = htons (pos->msg->header.size); | 179 | size = htons (pos->msg->header.size); |
181 | if (size != WRITE (fd, pos->msg, size)) | 180 | if (size != GNUNET_DISK_file_write (fh, pos->msg, size)) |
182 | { | 181 | { |
183 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 182 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
184 | "write", fn); | 183 | "write", fn); |
185 | GNUNET_DISK_file_close (fn, fd); | 184 | GNUNET_DISK_file_close (&fh); |
186 | fd = -1; | ||
187 | } | 185 | } |
188 | else | 186 | else |
189 | total += size; | 187 | total += size; |
190 | } | 188 | } |
191 | GNUNET_free (pos); | 189 | GNUNET_free (pos); |
192 | } | 190 | } |
193 | if (fd != -1) | 191 | if (fh) |
194 | { | 192 | { |
195 | GNUNET_DISK_file_close (fn, fd); | 193 | GNUNET_DISK_file_close (&fh); |
196 | if (total == 0) | 194 | if (total == 0) |
197 | GNUNET_break (0 == UNLINK (fn)); | 195 | GNUNET_break (0 == UNLINK (fn)); |
198 | else | 196 | else |