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.
|
/// Updates the downbuffer internal variable.
|
||||||
/// Returns true if new data was received, false otherwise.
|
/// 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.
|
/// \todo Provide better mechanism to prevent overbuffering.
|
||||||
if (downbuffer.size() > 10000){
|
if (!strictMode && downbuffer.size() > 10000){
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
return iread(downbuffer);
|
return iread(downbuffer);
|
||||||
|
|
|
@ -139,7 +139,7 @@ namespace Socket{
|
||||||
bool isAddress(const std::string &addr);
|
bool isAddress(const std::string &addr);
|
||||||
bool isLocal(); ///< Returns true if remote address is a local address.
|
bool isLocal(); ///< Returns true if remote address is a local address.
|
||||||
// buffered i/o methods
|
// 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
|
bool peek(); ///< Clears the downbuffer and fills it with peek
|
||||||
Buffer &Received(); ///< Returns a reference to the download buffer.
|
Buffer &Received(); ///< Returns a reference to the download buffer.
|
||||||
const Buffer &Received() const; ///< 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){
|
while (true){
|
||||||
// Check if we can receive the minimum frame size (2 header bytes, 0 payload)
|
// Check if we can receive the minimum frame size (2 header bytes, 0 payload)
|
||||||
if (!C.Received().available(2)){
|
if (!C.Received().available(2)){
|
||||||
if (C.spool()){continue;}
|
if (C.spool(true)){continue;}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::string head = C.Received().copy(2);
|
std::string head = C.Received().copy(2);
|
||||||
|
@ -141,7 +141,7 @@ namespace HTTP{
|
||||||
if (headSize > 2){
|
if (headSize > 2){
|
||||||
// Check if we can receive the whole header
|
// Check if we can receive the whole header
|
||||||
if (!C.Received().available(headSize)){
|
if (!C.Received().available(headSize)){
|
||||||
if (C.spool()){continue;}
|
if (C.spool(true)){continue;}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Read entire header, re-read real payload length
|
// Read entire header, re-read real payload length
|
||||||
|
@ -154,7 +154,7 @@ namespace HTTP{
|
||||||
}
|
}
|
||||||
// Check if we can receive the whole frame (header + payload)
|
// Check if we can receive the whole frame (header + payload)
|
||||||
if (!C.Received().available(headSize + payLen)){
|
if (!C.Received().available(headSize + payLen)){
|
||||||
if (C.spool()){continue;}
|
if (C.spool(true)){continue;}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
C.Received().remove(headSize); // delete the header
|
C.Received().remove(headSize); // delete the header
|
||||||
|
|
Loading…
Add table
Reference in a new issue