1 #include "NyLPC_cHttpdThread.h"
\r
2 #include "NyLPC_cHttpd.h"
\r
3 #include "NyLPC_cHttpdConnection_protected.h"
\r
5 #define LIMIT_OF_PERSISTENT_CONNECTION (NyLPC_cNet_NUMBER_OF_THREAD-1)
\r
7 static int server(void* p);
\r
9 void NyLPC_cHttpdThread_initialize(NyLPC_TcHttpdThread_t* i_inst,NyLPC_TcHttpd_t* i_parent,NyLPC_TInt32 i_prio)
\r
11 NyLPC_cHttpdConnection_initialize(&(i_inst->_connection),i_parent);
\r
12 NyLPC_cThread_initialize(&(i_inst->_super),NyLPC_TcHttpdThread_SIZE_OF_THREAD_STACK,i_prio);
\r
14 void NyLPC_cHttpdThread_finalize(NyLPC_TcHttpdThread_t* i_inst)
\r
16 NyLPC_cThread_finalize(&i_inst->_super);
\r
17 NyLPC_cHttpdConnection_finalize(&(i_inst->_connection));
\r
20 NyLPC_TBool NyLPC_cHttpdThread_start(NyLPC_TcHttpdThread_t* i_inst,NyLPC_TcTcpListener_t* i_listener)
\r
23 if(!NyLPC_cThread_isTerminated(&(i_inst->_super))){
\r
24 return NyLPC_TBool_FALSE;
\r
27 if(!NyLPC_cHttpdConnection_listenSocket(&(i_inst->_connection),i_listener)){
\r
28 return NyLPC_TBool_FALSE;
\r
31 NyLPC_cThread_start(&(i_inst->_super),server,&i_inst->_connection);
\r
32 return NyLPC_TBool_TRUE;
\r
40 static int server(void* p)
\r
42 NyLPC_TcHttpdConnection_t* inst=(NyLPC_TcHttpdConnection_t*)p;
\r
44 if(!NyLPC_cHttpdConnection_acceptSocket(inst)){
\r
45 NyLPC_OnErrorGoto(Error);
\r
48 NyLPC_cHttpd_incNumOfConnection(inst->_parent_httpd);
\r
54 if(!NyLPC_cHttpdConnection_prefetch(inst)){
\r
55 //Prefetch出来ないならループ終了。
\r
59 NyLPC_cHttpdConnection_setConnectionMode(inst,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE);
\r
62 (inst->_parent_httpd->function._handler)(inst);
\r
64 //コネクションが増えすぎたら持続性接続を停止するためにCLOSEDにする。
\r
65 if(NyLPC_cHttpd_getNumOfConnection(inst->_parent_httpd)>LIMIT_OF_PERSISTENT_CONNECTION){
\r
66 NyLPC_cHttpdConnection_setConnectionMode(inst,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE);
\r
69 if(!NyLPC_cHttpdConnection_closeResponse(inst)){
\r
73 if(!NyLPC_cHttpdConnection_prevNextPrefetch(inst)){
\r
77 NyLPC_cHttpd_decNumOfConnection(inst->_parent_httpd);
\r
78 NyLPC_cHttpdConnection_closeSocket(inst);
\r
81 NyLPC_cHttpdConnection_closeSocket(inst);
\r