Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
NyLPC_cHttpdThread.c
00001 #include "NyLPC_cHttpd_protected.h" 00002 #include "NyLPC_cHttpdConnection.h" 00003 #include "NyLPC_cHttpdConnection_protected.h" 00004 #include "NyLPC_cHttpdThread_protected.h" 00005 00006 00007 static int server(void* p); 00008 00009 NyLPC_TBool NyLPC_cHttpdThread_initialize(NyLPC_TcHttpdThread_t* i_inst,NyLPC_TcHttpd_t* i_parent,NyLPC_TInt32 i_prio) 00010 { 00011 if(!NyLPC_cHttpdConnection_initialize(&(i_inst->_connection),i_parent)){ 00012 return NyLPC_TBool_FALSE; 00013 } 00014 NyLPC_cThread_initialize(&(i_inst->_super),NyLPC_cHttpdThread_SIZE_OF_THREAD_STACK,i_prio); 00015 return NyLPC_TBool_TRUE; 00016 } 00017 void NyLPC_cHttpdThread_finalize(NyLPC_TcHttpdThread_t* i_inst) 00018 { 00019 NyLPC_cThread_finalize(&i_inst->_super); 00020 NyLPC_cHttpdConnection_finalize(&(i_inst->_connection)); 00021 } 00022 00023 NyLPC_TBool NyLPC_cHttpdThread_start(NyLPC_TcHttpdThread_t* i_inst,NyLPC_TiTcpListener_t* i_listener) 00024 { 00025 //停止中? 00026 if(!NyLPC_cThread_isTerminated(&(i_inst->_super))){ 00027 return NyLPC_TBool_FALSE; 00028 } 00029 //リスニング 00030 if(!NyLPC_cHttpdConnection_listenSocket(&(i_inst->_connection),i_listener)){ 00031 return NyLPC_TBool_FALSE; 00032 } 00033 //Accept可能なので開始。 00034 NyLPC_cThread_start(&(i_inst->_super),server,&i_inst->_connection); 00035 return NyLPC_TBool_TRUE; 00036 00037 } 00038 00039 00040 00041 00042 //Httpのセッション関数 00043 static int server(void* p) 00044 { 00045 NyLPC_TcHttpdConnection_t* inst=(NyLPC_TcHttpdConnection_t*)p; 00046 //コネクションをAccept 00047 if(!NyLPC_cHttpdConnection_acceptSocket(inst)){ 00048 NyLPC_OnErrorGoto(Error); 00049 } 00050 //コネクション数の追加 00051 NyLPC_cHttpd_incNumOfConnection(inst->_parent_httpd); 00052 00053 00054 //サブネットアクセスの確認 00055 for(;;){ 00056 //リクエストのプレフィクスを取得 00057 if(!NyLPC_cHttpdConnection_prefetch(inst)){ 00058 //Prefetch出来ないならループ終了。 00059 break; 00060 } 00061 //持続性接続の初期モードを設定 00062 if(NyLPC_cHttpd_getNumOfConnection(inst->_parent_httpd)>NyLPC_cHttpd_MAX_PERSISTENT_CONNECTION){ 00063 NyLPC_cHttpdConnection_setConnectionMode(inst,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE); 00064 }else{ 00065 NyLPC_cHttpdConnection_setConnectionMode(inst,NyLPC_TcHttpdConnection_CONNECTION_MODE_CONTINUE); 00066 } 00067 {//handler 00068 (inst->_parent_httpd->function.onRequest)(inst); 00069 } 00070 //HTTP層のクローズ 00071 if(!NyLPC_cHttpdConnection_closeResponse(inst)){ 00072 break; 00073 } 00074 //次のプリフェッチを準備。 00075 if(!NyLPC_cHttpdConnection_prevNextPrefetch(inst)){ 00076 break; 00077 } 00078 } 00079 NyLPC_cHttpd_decNumOfConnection(inst->_parent_httpd); 00080 NyLPC_cHttpdConnection_closeSocket(inst); 00081 return 0; 00082 Error: 00083 NyLPC_cHttpdConnection_closeSocket(inst); 00084 return -1; 00085 } 00086
Generated on Tue Jul 12 2022 16:22:57 by
