diff options
author | Yunchih Chen <yunchih.cat@gmail.com> | 2017-12-01 11:03:20 +0800 |
---|---|---|
committer | Yunchih Chen <yunchih.cat@gmail.com> | 2017-12-01 11:03:20 +0800 |
commit | 73b99a356db73745e8a70c1442ed3fbdbc0c7317 (patch) | |
tree | 6a5cdeda13d481bfb120791e22f88c627867837d /commit.c | |
parent | 15f0360911c3ff0a25f36820c41f54d265ccbd81 (diff) | |
download | nfcollect-73b99a356db73745e8a70c1442ed3fbdbc0c7317.tar nfcollect-73b99a356db73745e8a70c1442ed3fbdbc0c7317.tar.gz nfcollect-73b99a356db73745e8a70c1442ed3fbdbc0c7317.tar.bz2 nfcollect-73b99a356db73745e8a70c1442ed3fbdbc0c7317.tar.lz nfcollect-73b99a356db73745e8a70c1442ed3fbdbc0c7317.tar.xz nfcollect-73b99a356db73745e8a70c1442ed3fbdbc0c7317.tar.zst nfcollect-73b99a356db73745e8a70c1442ed3fbdbc0c7317.zip |
Use simple fwrite
Diffstat (limited to 'commit.c')
-rw-r--r-- | commit.c | 28 |
1 files changed, 10 insertions, 18 deletions
@@ -13,30 +13,22 @@ void nfl_commit_init() { void nfl_commit_worker(nflog_header_t* header, nflog_entry_t* store) { FILE* f; char filename[1024]; - uint32_t id = header->id; + uint32_t written, id = header->id; sprintf(filename, "%s/%s_%d", storage_dir, storage_prefix, id); debug("Comm worker #%u: commit to file %s\n", header->id, filename); - fd = open ERR((f = fopen(filename, "wb")) == NULL, strerror(errno)); - fwrite(header, sizeof(nflog_header_t), 1, f); - - uint32_t total_size = sizeof(nflog_entry_t) * header->max_n_entries; - uint32_t total_blk = total_size / write_blk_size; - uint32_t i, written = 0; - for(i = 0; i < total_blk; ++i) { - written = fwrite(store, 1, write_blk_size, f); - - while(written < write_blk_size) { - written += fwrite(store, 1, write_blk_size - written, f); - } - } - int remain = total_size - total_blk*write_blk_size; - while(remain > 0) { - remain -= fwrite(store, 1, remain, f); - } + // commit header + written = fwrite(header, 1, sizeof(nflog_header_t), f); + ERR(written != sizeof(nflog_header_t), strerror(errno)); + // commit store + uint32_t store_size = sizeof(nflog_entry_t) * header->max_n_entries; + written = fwrite(store, 1, store_size, f); + ERR(written != store_size, strerror(errno)); + + // Do fsync ? fclose(f); } |