summaryrefslogtreecommitdiff
path: root/src/server/buffer.cpp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-20 01:50:14 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-20 01:50:14 -0300
commit8693eef8febde4df90b7fbd1fb9ac813b132fa50 (patch)
tree088258d6333d54a6b90f331d3b723ae824110679 /src/server/buffer.cpp
parent7620a0b1c080f7b6315e796d29e324bdca98484b (diff)
downloadjet-8693eef8febde4df90b7fbd1fb9ac813b132fa50.tar.gz
jet-8693eef8febde4df90b7fbd1fb9ac813b132fa50.zip
Wrap external functionality into classes
Diffstat (limited to 'src/server/buffer.cpp')
-rw-r--r--src/server/buffer.cpp14
1 files changed, 6 insertions, 8 deletions
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);
}
};