Add an advance function to step through the mmaped buffer
This commit is contained in:
@@ -8,6 +8,7 @@ set(HEADERS
|
|||||||
raw_socket.hxx
|
raw_socket.hxx
|
||||||
sg_binobj.hxx
|
sg_binobj.hxx
|
||||||
sg_file.hxx
|
sg_file.hxx
|
||||||
|
sg_mmap.hxx
|
||||||
sg_netBuffer.hxx
|
sg_netBuffer.hxx
|
||||||
sg_netChannel.hxx
|
sg_netChannel.hxx
|
||||||
sg_netChat.hxx
|
sg_netChat.hxx
|
||||||
@@ -29,6 +30,7 @@ set(SOURCES
|
|||||||
raw_socket.cxx
|
raw_socket.cxx
|
||||||
sg_binobj.cxx
|
sg_binobj.cxx
|
||||||
sg_file.cxx
|
sg_file.cxx
|
||||||
|
sg_mmap.cxx
|
||||||
sg_netBuffer.cxx
|
sg_netBuffer.cxx
|
||||||
sg_netChannel.cxx
|
sg_netChannel.cxx
|
||||||
sg_netChat.cxx
|
sg_netChat.cxx
|
||||||
|
|||||||
@@ -180,6 +180,23 @@ int SGMMapFile::read( char *buf, int length ) {
|
|||||||
return result;
|
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
|
// read a line of data, length is max size of input buffer
|
||||||
int SGMMapFile::readline( char *buf, int length ) {
|
int SGMMapFile::readline( char *buf, int length ) {
|
||||||
|
|||||||
@@ -92,6 +92,9 @@ public:
|
|||||||
// read a block of data of specified size
|
// read a block of data of specified size
|
||||||
int read( char *buf, int length );
|
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
|
// read a line of data, length is max size of input buffer
|
||||||
int readline( char *buf, int length );
|
int readline( char *buf, int length );
|
||||||
|
|
||||||
@@ -99,7 +102,11 @@ public:
|
|||||||
// note: this really defeats the purpose of mmapping a file
|
// note: this really defeats the purpose of mmapping a file
|
||||||
std::string read_all();
|
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; }
|
inline size_t get_size() { return size; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user