Permalink
Browse files

websocket, feat: lock the Buffer individually to send the buffer as s…

…oon as possible.
  • Loading branch information...
xicilion committed Oct 25, 2017
1 parent dbff1aa commit 29862020896f453d9144afb009b91b3593f8ee90
Showing with 13 additions and 5 deletions.
  1. +1 −0 fibjs/include/WebSocket.h
  2. +12 −5 fibjs/src/websocket/WebSocket.cpp
@@ -75,6 +75,7 @@ class WebSocket : public WebSocket_base {
AsyncEvent* m_ac;
obj_ptr<SeekableStream_base> m_buffer;
exlib::Locker m_lockEncode;
exlib::Locker m_lockBuffer;
exlib::Locker m_lockSend;
@@ -81,11 +81,18 @@ class asyncSend : public AsyncState {
void start()
{
set(encode);
if (m_this->m_lockBuffer.lock(this))
set(lock_buffer_for_encode);
if (m_this->m_lockEncode.lock(this))
apost(0);
}
static int32_t lock_buffer_for_encode(AsyncState* pState, int32_t n)
{
asyncSend* pThis = (asyncSend*)pState;
pThis->set(encode);
return pThis->lock(pThis->m_this->m_lockBuffer);
}
static int32_t encode(AsyncState* pState, int32_t n)
{
asyncSend* pThis = (asyncSend*)pState;
@@ -101,12 +108,13 @@ class asyncSend : public AsyncState {
{
asyncSend* pThis = (asyncSend*)pState;
pThis->unlock(pThis->m_this->m_lockBuffer);
pThis->unlock(pThis->m_this->m_lockEncode);
pThis->set(lock_buffer);
pThis->set(lock_buffer_for_send);
return pThis->lock(pThis->m_this->m_lockSend);
}
static int32_t lock_buffer(AsyncState* pState, int32_t n)
static int32_t lock_buffer_for_send(AsyncState* pState, int32_t n)
{
asyncSend* pThis = (asyncSend*)pState;
pThis->set(send);
@@ -116,7 +124,6 @@ class asyncSend : public AsyncState {
static int32_t send(AsyncState* pState, int32_t n)
{
asyncSend* pThis = (asyncSend*)pState;
static int32_t cnt;
pThis->m_buffer = pThis->m_this->m_buffer;
pThis->m_this->m_buffer.Release();

0 comments on commit 2986202

Please sign in to comment.