Add an advance function to step through the mmaped buffer
This commit is contained in:
parent
4ace6bda60
commit
c539f7ebb6
@ -8,6 +8,7 @@ set(HEADERS
|
||||
raw_socket.hxx
|
||||
sg_binobj.hxx
|
||||
sg_file.hxx
|
||||
sg_mmap.hxx
|
||||
sg_netBuffer.hxx
|
||||
sg_netChannel.hxx
|
||||
sg_netChat.hxx
|
||||
@ -29,6 +30,7 @@ set(SOURCES
|
||||
raw_socket.cxx
|
||||
sg_binobj.cxx
|
||||
sg_file.cxx
|
||||
sg_mmap.cxx
|
||||
sg_netBuffer.cxx
|
||||
sg_netChannel.cxx
|
||||
sg_netChat.cxx
|
||||
|
@ -180,6 +180,23 @@ int SGMMapFile::read( char *buf, int length ) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const char* SGMMapFile::advance(size_t len) {
|
||||
if (len >= size - offset)
|
||||
return nullptr;
|
||||
|
||||
const char *ptr = buffer + offset;
|
||||
offset += len;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
int SGMMapFile::read( char *buf, int length, int num ) {
|
||||
if (length == 0)
|
||||
return 0;
|
||||
|
||||
size_t size = num*length;
|
||||
return read(buf, size)/length;
|
||||
}
|
||||
|
||||
// read a line of data, length is max size of input buffer
|
||||
int SGMMapFile::readline( char *buf, int length ) {
|
||||
|
@ -92,6 +92,9 @@ public:
|
||||
// read a block of data of specified size
|
||||
int read( char *buf, int length );
|
||||
|
||||
// read a block of data of specified size
|
||||
int read( char *buf, int length, int num );
|
||||
|
||||
// read a line of data, length is max size of input buffer
|
||||
int readline( char *buf, int length );
|
||||
|
||||
@ -99,7 +102,11 @@ public:
|
||||
// note: this really defeats the purpose of mmapping a file
|
||||
std::string read_all();
|
||||
|
||||
inline const char* get() { return buffer; }
|
||||
// get the pointer to the start of the buffer
|
||||
inline const char *get() { return buffer; }
|
||||
|
||||
// get the pointer at the current offset and increase the offset by len
|
||||
const char* advance(size_t len);
|
||||
|
||||
inline size_t get_size() { return size; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user