From 8693eef8febde4df90b7fbd1fb9ac813b132fa50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 20 Jul 2020 01:50:14 -0300 Subject: Wrap external functionality into classes --- src/server/buffer.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/server/buffer.cpp') diff --git a/src/server/buffer.cpp b/src/server/buffer.cpp index 7b4c92d..62c7ea9 100644 --- a/src/server/buffer.cpp +++ b/src/server/buffer.cpp @@ -14,9 +14,9 @@ struct Buffer { void read_file(const char *pathname) { free_storage(); - int file = open(pathname, O_RDONLY); + File file(pathname, O_RDONLY); storage = new Page(); - int bytes_read = read(file, storage->elements, PAGE_SIZE); + int bytes_read = file.recv(storage->elements, PAGE_SIZE); Page *iter = storage; while (bytes_read > 0) { iter->gap_start = bytes_read; @@ -24,22 +24,20 @@ struct Buffer { iter->next = new Page(); iter->next->prev = iter; iter = iter->next; - bytes_read = read(file, iter->elements, PAGE_SIZE); + bytes_read = file.recv(iter->elements, PAGE_SIZE); } if (iter->element_count == 0) { delete iter; } - close(file); } void write_file(const char *pathname) { - int file = open(pathname, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + File file(pathname, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); Page *iter = storage; while (iter) { - write(file, iter->elements, iter->gap_start); - write(file, iter->elements + iter->gap_end, PAGE_SIZE - iter->gap_end); + file.send(iter->elements, iter->gap_start); + file.send(iter->elements + iter->gap_end, PAGE_SIZE - iter->gap_end); iter = iter->next; } - close(file); } }; -- cgit v1.2.3