added some code to sio to suppoert QSE_SIO_REENTRANT. not completed yet
This commit is contained in:
@ -16,8 +16,6 @@
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
QSE::Mutex g_prt_mutex;
|
||||
|
||||
class ClientHandler
|
||||
{
|
||||
public:
|
||||
@ -28,25 +26,19 @@ public:
|
||||
qse_ssize_t n;
|
||||
|
||||
worker->address.toStrBuf(addrbuf, QSE_COUNTOF(addrbuf));
|
||||
g_prt_mutex.lock();
|
||||
qse_printf (QSE_T("hello word..from %s -> wid %zu\n"), addrbuf, worker->getWid());
|
||||
g_prt_mutex.unlock();
|
||||
|
||||
while (!server->isStopRequested())
|
||||
{
|
||||
if ((n = worker->socket.receive(bb, QSE_COUNTOF(bb))) <= 0)
|
||||
{
|
||||
g_prt_mutex.lock();
|
||||
qse_printf (QSE_T("%zd bytes received from %s\n"), n, addrbuf);
|
||||
g_prt_mutex.unlock();
|
||||
break;
|
||||
}
|
||||
worker->socket.send (bb, n);
|
||||
}
|
||||
|
||||
g_prt_mutex.lock();
|
||||
qse_printf (QSE_T("byte to %s -> wid %zu\n"), addrbuf, worker->getWid());
|
||||
g_prt_mutex.unlock();
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
@ -70,9 +62,7 @@ public:
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
case SIGHUP:
|
||||
g_prt_mutex.lock();
|
||||
qse_printf (QSE_T("requesting to stop server...app %p server %p\n"), this, &this->server);
|
||||
g_prt_mutex.unlock();
|
||||
this->server.stop();
|
||||
break;
|
||||
}
|
||||
|
@ -16,8 +16,6 @@
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
QSE::Mutex g_prt_mutex;
|
||||
|
||||
#if defined(QSE_LANG_CPP11)
|
||||
QSE::TcpServerL<int(QSE::TcpServer::Worker*)>* g_server;
|
||||
#else
|
||||
@ -32,9 +30,7 @@ public:
|
||||
qse_ssize_t n;
|
||||
|
||||
worker->address.toStrBuf(addrbuf, QSE_COUNTOF(addrbuf));
|
||||
g_prt_mutex.lock();
|
||||
qse_printf (QSE_T("hello word..from %s[%zu]\n"), addrbuf, worker->getWid());
|
||||
g_prt_mutex.unlock();
|
||||
|
||||
QSE::Sttp sttp (&worker->socket);
|
||||
QSE::SttpCmd cmd;
|
||||
@ -50,15 +46,11 @@ public:
|
||||
|
||||
if (cmd.name == QSE_T("quit")) break;
|
||||
|
||||
g_prt_mutex.lock();
|
||||
qse_printf (QSE_T("received command %s\n"), cmd.name.getBuffer());
|
||||
g_prt_mutex.unlock();
|
||||
sttp.sendCmd(cmd);
|
||||
}
|
||||
|
||||
g_prt_mutex.lock();
|
||||
qse_printf (QSE_T("byte to %s -> wid %zu\n"), addrbuf, worker->getWid());
|
||||
g_prt_mutex.unlock();
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
@ -81,9 +73,7 @@ static int test1 (void)
|
||||
qse_ssize_t n;
|
||||
|
||||
worker->address.toStrBuf(addrbuf, QSE_COUNTOF(addrbuf));
|
||||
g_prt_mutex.lock();
|
||||
qse_printf (QSE_T("hello word..from %s --> wid %zu\n"), addrbuf, worker->getWid());
|
||||
g_prt_mutex.unlock();
|
||||
|
||||
QSE::Sttp sttp (&worker->socket);
|
||||
QSE::SttpCmd cmd;
|
||||
@ -98,16 +88,12 @@ static int test1 (void)
|
||||
else if (n == 0) break;
|
||||
|
||||
if (cmd.name == QSE_T("quit")) break;
|
||||
|
||||
g_prt_mutex.lock();
|
||||
|
||||
qse_printf (QSE_T("%s<%zu> --> received command %s\n"), addrbuf, worker->getWid(), cmd.name.getBuffer());
|
||||
g_prt_mutex.unlock();
|
||||
sttp.sendCmd(cmd);
|
||||
}
|
||||
|
||||
g_prt_mutex.lock();
|
||||
qse_printf (QSE_T("byte to %s -> wid %zu\n"), addrbuf, worker->getWid());
|
||||
g_prt_mutex.unlock();
|
||||
return 0;
|
||||
}),
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include <string.h>
|
||||
|
||||
static int g_stopreq = 0;
|
||||
static qse_mtx_t* g_prmtx = QSE_NULL;
|
||||
|
||||
QSE::HeapMmgr g_heap_mmgr (QSE::Mmgr::getDFL(), 30000);
|
||||
|
||||
@ -29,9 +28,7 @@ public:
|
||||
|
||||
while (!this->stopreq)
|
||||
{
|
||||
qse_mtx_lock (g_prmtx, QSE_NULL);
|
||||
qse_printf (QSE_T("m %p -> %d\n"), this, i);
|
||||
qse_mtx_unlock (g_prmtx);
|
||||
i++;
|
||||
sleep (1);
|
||||
}
|
||||
@ -52,9 +49,7 @@ public:
|
||||
|
||||
while (!*stopreqptr)
|
||||
{
|
||||
qse_mtx_lock (g_prmtx, QSE_NULL);
|
||||
qse_printf (QSE_T("fc %p -> %d\n"), this, i);
|
||||
qse_mtx_unlock (g_prmtx);
|
||||
i++;
|
||||
sleep (1);
|
||||
}
|
||||
@ -70,9 +65,7 @@ static int func_ptr (QSE::Thread* thr)
|
||||
|
||||
while (!*stopreqptr)
|
||||
{
|
||||
qse_mtx_lock (g_prmtx, QSE_NULL);
|
||||
qse_printf (QSE_T("fp %p -> %d\n"), thr, i);
|
||||
qse_mtx_unlock (g_prmtx);
|
||||
i++;
|
||||
sleep (1);
|
||||
}
|
||||
@ -84,8 +77,6 @@ static int test1 (void)
|
||||
{
|
||||
int localstopreq = 0;
|
||||
|
||||
g_prmtx = qse_mtx_open (QSE_MMGR_GETDFL(), 0);
|
||||
|
||||
#if defined(QSE_LANG_CPP11)
|
||||
auto lambda = [](QSE::Thread* thr)->int
|
||||
{
|
||||
@ -94,9 +85,7 @@ static int test1 (void)
|
||||
|
||||
while (!*stopreqptr)
|
||||
{
|
||||
qse_mtx_lock (g_prmtx, QSE_NULL);
|
||||
qse_printf (QSE_T("l %p -> %d\n"), thr, i);
|
||||
qse_mtx_unlock (g_prmtx);
|
||||
i++;
|
||||
sleep (1);
|
||||
}
|
||||
@ -110,9 +99,7 @@ static int test1 (void)
|
||||
|
||||
while (!localstopreq)
|
||||
{
|
||||
qse_mtx_lock (g_prmtx, QSE_NULL);
|
||||
qse_printf (QSE_T("lc %p -> %d\n"), thr, i);
|
||||
qse_mtx_unlock (g_prmtx);
|
||||
i++;
|
||||
sleep (1);
|
||||
}
|
||||
@ -171,9 +158,7 @@ static int test1 (void)
|
||||
|
||||
while (!localstopreq)
|
||||
{
|
||||
qse_mtx_lock (g_prmtx, QSE_NULL);
|
||||
qse_printf (QSE_T("tl %p -> %d\n"), thr, i);
|
||||
qse_mtx_unlock (g_prmtx);
|
||||
i++;
|
||||
sleep (1);
|
||||
}
|
||||
@ -234,7 +219,6 @@ static int test1 (void)
|
||||
#endif
|
||||
qse_printf (QSE_T("thread6 ended with retcode %d\n"), thr6.getReturnCode());
|
||||
|
||||
qse_mtx_close (g_prmtx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include <string.h>
|
||||
|
||||
static int g_stopreq = 0;
|
||||
static qse_mtx_t* g_prmtx = QSE_NULL;
|
||||
|
||||
QSE::HeapMmgr g_heap_mmgr (QSE::Mmgr::getDFL(), 30000);
|
||||
|
||||
@ -43,9 +42,7 @@ public:
|
||||
#else
|
||||
while (!rqdata->mtx.trylock())
|
||||
{
|
||||
qse_mtx_lock (g_prmtx, QSE_NULL);
|
||||
qse_printf (QSE_T("[%p] -> retrying to lock\n"), this, i);
|
||||
qse_mtx_unlock (g_prmtx);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -57,23 +54,17 @@ public:
|
||||
rqdata->cnd.wait(rqdata->mtx);
|
||||
rqdata->mtx.unlock ();
|
||||
|
||||
qse_mtx_lock (g_prmtx, QSE_NULL);
|
||||
qse_printf (QSE_T("[%p] -> loop %d\n"), this, i);
|
||||
qse_mtx_unlock (g_prmtx);
|
||||
i++;
|
||||
}
|
||||
|
||||
qse_mtx_lock (g_prmtx, QSE_NULL);
|
||||
qse_printf (QSE_T("[%p] -> exiting\n"), this);
|
||||
qse_mtx_unlock (g_prmtx);
|
||||
return i;
|
||||
}
|
||||
};
|
||||
|
||||
static int test1 (void)
|
||||
{
|
||||
g_prmtx = qse_mtx_open (QSE_MMGR_GETDFL(), 0);
|
||||
|
||||
rq_data_t rqdata;
|
||||
QSE::ThreadF<Waiter> thr[3];
|
||||
|
||||
@ -92,9 +83,7 @@ static int test1 (void)
|
||||
{
|
||||
if (g_stopreq)
|
||||
{
|
||||
qse_mtx_lock (g_prmtx, QSE_NULL);
|
||||
qse_printf (QSE_T("broadcasting stop ---> 1\n"));
|
||||
qse_mtx_unlock (g_prmtx);
|
||||
|
||||
rqdata.mtx.lock ();
|
||||
rqdata.stop = 1;
|
||||
@ -109,9 +98,7 @@ static int test1 (void)
|
||||
}
|
||||
if (nterm == 3) break;
|
||||
|
||||
qse_mtx_lock (g_prmtx, QSE_NULL);
|
||||
qse_printf (QSE_T("signalling ....(nterm = %d)\n"), nterm);
|
||||
qse_mtx_unlock (g_prmtx);
|
||||
|
||||
rqdata.cnd.signal ();
|
||||
sleep (1);
|
||||
@ -128,7 +115,6 @@ static int test1 (void)
|
||||
qse_printf (QSE_T("thread%d ended with retcode %d\n"), i, thr[i].getReturnCode());
|
||||
}
|
||||
|
||||
qse_mtx_close (g_prmtx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user