Skip to content

Commit

Permalink
moved two common methods to base class
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Kraynyukhov committed Aug 20, 2018
1 parent b8dce40 commit 099122a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
22 changes: 20 additions & 2 deletions include/WSStreamParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,20 @@ namespace WSStreamProcessing
};
}



auto getBuffer()
{
AtomicLock sync(mBQMutex);
if(mBufferQueue.empty())
{
return std::make_shared<MSGBufferType>(mOutMSGPreSize);
}else{
auto tmp=std::move(mBufferQueue.front());
tmp->resize(mOutMSGPreSize);
mBufferQueue.pop();
return tmp;
}
}

public:
explicit WSStreamParser(const size_t& presz)
: mPLBytesReady{0},cursor{0},mMaxMSGSize{0},
Expand All @@ -439,6 +451,12 @@ namespace WSStreamProcessing
WSStreamParser(const WSStreamParser&)=delete;
WSStreamParser(WSStreamParser&)=delete;

void returnBuffer(std::remove_reference<const std::shared_ptr<MSGBufferType>&>::type buff)
{
AtomicLock sync(mBQMutex);
mBufferQueue.push(std::move(buff));
}

void setMaxMSGSize(const size_t& mms)
{
mMaxMSGSize=mms;
Expand Down
21 changes: 2 additions & 19 deletions include/WSStreamServerParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,26 +286,9 @@ namespace WSStreamProcessing
throw std::logic_error("WSStreamParser::decideOnDone() switch is out of options, never should have happened. Blame the programmer");
}

auto getBuffer()
{
AtomicLock sync(mBQMutex);
if(mBufferQueue.empty())
{
return std::make_shared<MSGBufferType>(mOutMSGPreSize);
}else{
auto tmp=std::move(mBufferQueue.front());
tmp->resize(mOutMSGPreSize);
mBufferQueue.pop();
return tmp;
}
}
public:
void returnBuffer(std::remove_reference<const std::shared_ptr<MSGBufferType>&>::type buff)
{
AtomicLock sync(mBQMutex);
mBufferQueue.push(std::move(buff));
}
const Result parse(const uint8_t* stream, const size_t& limit, const size_t& offset)

const Result parse(const uint8_t* stream, const size_t& limit, const size_t& offset)
{
cursor=offset;

Expand Down

0 comments on commit 099122a

Please # to comment.