Added socket lib strict mode spool, used in WebSocket::readFrame
This commit is contained in:
parent
829c8b7948
commit
fe6a0777a5
3 changed files with 6 additions and 6 deletions
|
@ -932,9 +932,9 @@ uint64_t Socket::Connection::dataDown(){
|
|||
|
||||
/// Updates the downbuffer internal variable.
|
||||
/// Returns true if new data was received, false otherwise.
|
||||
bool Socket::Connection::spool(){
|
||||
bool Socket::Connection::spool(bool strictMode){
|
||||
/// \todo Provide better mechanism to prevent overbuffering.
|
||||
if (downbuffer.size() > 10000){
|
||||
if (!strictMode && downbuffer.size() > 10000){
|
||||
return true;
|
||||
}else{
|
||||
return iread(downbuffer);
|
||||
|
|
|
@ -139,7 +139,7 @@ namespace Socket{
|
|||
bool isAddress(const std::string &addr);
|
||||
bool isLocal(); ///< Returns true if remote address is a local address.
|
||||
// buffered i/o methods
|
||||
bool spool(); ///< Updates the downbufferinternal variables.
|
||||
bool spool(bool strictMode = false); ///< Updates the downbufferinternal variables.
|
||||
bool peek(); ///< Clears the downbuffer and fills it with peek
|
||||
Buffer &Received(); ///< Returns a reference to the download buffer.
|
||||
const Buffer &Received() const; ///< Returns a reference to the download buffer.
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace HTTP{
|
|||
while (true){
|
||||
// Check if we can receive the minimum frame size (2 header bytes, 0 payload)
|
||||
if (!C.Received().available(2)){
|
||||
if (C.spool()){continue;}
|
||||
if (C.spool(true)){continue;}
|
||||
return false;
|
||||
}
|
||||
std::string head = C.Received().copy(2);
|
||||
|
@ -141,7 +141,7 @@ namespace HTTP{
|
|||
if (headSize > 2){
|
||||
// Check if we can receive the whole header
|
||||
if (!C.Received().available(headSize)){
|
||||
if (C.spool()){continue;}
|
||||
if (C.spool(true)){continue;}
|
||||
return false;
|
||||
}
|
||||
// Read entire header, re-read real payload length
|
||||
|
@ -154,7 +154,7 @@ namespace HTTP{
|
|||
}
|
||||
// Check if we can receive the whole frame (header + payload)
|
||||
if (!C.Received().available(headSize + payLen)){
|
||||
if (C.spool()){continue;}
|
||||
if (C.spool(true)){continue;}
|
||||
return false;
|
||||
}
|
||||
C.Received().remove(headSize); // delete the header
|
||||
|
|
Loading…
Add table
Reference in a new issue