From dfd4c1cd6ffd06bba91efeb9cb70efbc38d6263c Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Sun, 12 Jun 2016 22:27:15 +0200 Subject: [PATCH] Remove unused reader subclasses --- Frameworks/document/src/reader.cc | 178 ------------------------------ Frameworks/document/src/reader.h | 68 ------------ 2 files changed, 246 deletions(-) delete mode 100644 Frameworks/document/src/reader.cc delete mode 100644 Frameworks/document/src/reader.h diff --git a/Frameworks/document/src/reader.cc b/Frameworks/document/src/reader.cc deleted file mode 100644 index 38293b48..00000000 --- a/Frameworks/document/src/reader.cc +++ /dev/null @@ -1,178 +0,0 @@ -#include "reader.h" - -#define BLOCK_SIZE (8 * 1024) -#define MAP_SIZE (32 * 1024 * 1024) - -namespace reader -{ - // ============ - // = Async IO = - // ============ - - async_t::async_t (std::string const& path) - { - if((fd = open(path.c_str(), O_RDONLY|O_CLOEXEC)) != -1) - { - fcntl(fd, F_NOCACHE, 1); - - struct stat buf; - fstat(fd, &buf); - offset = 0; - file_size = buf.st_size; - - setup_request(); - } - } - - async_t::~async_t () - { - if(fd != -1) - close(fd); - } - - void async_t::setup_request () - { - request = NULL; - if(off_t len = std::min(BLOCK_SIZE, file_size - offset)) - { - request = new aiocb; - bzero(request, sizeof(*request)); - - request->aio_fildes = fd; - request->aio_offset = offset; - request->aio_buf = new char[len]; - request->aio_nbytes = len; - aio_read(request); - } - } - - io::bytes_ptr async_t::next () - { - if(fd == -1 || !request) - return io::bytes_ptr(); - - int rc = aio_suspend(&request, 1, NULL); - if(rc == -1) - return io::bytes_ptr(); - ssize_t len = aio_return(request); - if(len == -1) - return io::bytes_ptr(); - - offset += request->aio_nbytes; - auto res = std::make_shared((char const*)request->aio_buf, request->aio_nbytes); - - delete request; - setup_request(); - - return res; - } - - // ================= - // = Memory Mapped = - // ================= - - mapped_t::mapped_t (std::string const& path) - { - offset = 0; - mapped_size = 0; - if((fd = open(path.c_str(), O_RDONLY|O_CLOEXEC)) != -1) - { - fcntl(fd, F_NOCACHE, 1); - - struct stat buf; - fstat(fd, &buf); - file_size = buf.st_size; - } - } - - mapped_t::~mapped_t () - { - if(mapped_size) - { - if(munmap(memory, mapped_size) != 0) - perror("munmap"); - } - - if(fd != -1) - close(fd); - } - - io::bytes_ptr mapped_t::next () - { - if(fd == -1) - return io::bytes_ptr(); - - if(mapped_size) - { - if(munmap(memory, mapped_size) != 0) - perror("munmap"); - } - - offset += mapped_size; - mapped_size = std::min(MAP_SIZE, file_size - offset); - - if(mapped_size == 0) - return io::bytes_ptr(); - - memory = (char*)mmap(NULL, mapped_size, PROT_READ, MAP_PRIVATE, fd, offset); - return std::make_shared(memory, mapped_size, false); - } - - // =========== - // = fopen() = - // =========== - - fopen_t::fopen_t (std::string const& path) - { - if(fp = fopen(path.c_str(), "r")) - fcntl(fileno(fp), F_NOCACHE, 1); - } - - fopen_t::~fopen_t () - { - if(fp) - fclose(fp); - } - - io::bytes_ptr fopen_t::next () - { - if(!fp) - return io::bytes_ptr(); - - char* buf = new char[BLOCK_SIZE]; - if(size_t len = fread(buf, 1, BLOCK_SIZE, fp)) - return std::make_shared(buf, len); - delete[] buf; - return io::bytes_ptr(); - } - - // ========== - // = open() = - // ========== - - open_t::open_t (std::string const& path) - { - if((fd = open(path.c_str(), O_RDONLY|O_CLOEXEC)) != -1) - fcntl(fd, F_NOCACHE, 1); - } - - open_t::~open_t () - { - if(fd != -1) - close(fd); - } - - io::bytes_ptr open_t::next () - { - if(fd == -1) - return io::bytes_ptr(); - - char* buf = new char[BLOCK_SIZE]; - ssize_t len = read(fd, buf, BLOCK_SIZE); - if(len > 0) - return std::make_shared(buf, len); - delete[] buf; - return io::bytes_ptr(); - } - -} /* reader */ diff --git a/Frameworks/document/src/reader.h b/Frameworks/document/src/reader.h deleted file mode 100644 index 0ba5ba80..00000000 --- a/Frameworks/document/src/reader.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef READER_H_DD5U5J92 -#define READER_H_DD5U5J92 - -#include "document.h" // document::document_t::reader_t -#include -#include -#include -#include - -namespace reader -{ - struct async_t : document::document_t::reader_t - { - WATCH_LEAKS(async_t); - - async_t (std::string const& path); - ~async_t (); - io::bytes_ptr next (); - - private: - void setup_request (); - aiocb* request; - - int fd; - off_t offset, file_size; - }; - - struct mapped_t : document::document_t::reader_t - { - WATCH_LEAKS(mapped_t); - - mapped_t (std::string const& path); - ~mapped_t (); - io::bytes_ptr next (); - - private: - char* memory; - int fd; - off_t offset, file_size, mapped_size; - }; - - struct fopen_t : document::document_t::reader_t - { - WATCH_LEAKS(fopen_t); - - fopen_t (std::string const& path); - ~fopen_t (); - io::bytes_ptr next (); - - private: - FILE* fp; - }; - - struct open_t : document::document_t::reader_t - { - WATCH_LEAKS(open_t); - - open_t (std::string const& path); - ~open_t (); - io::bytes_ptr next (); - - protected: - int fd; - }; - -} /* reader */ - -#endif /* end of include guard: READER_H_DD5U5J92 */