OSDN Git Service

一部のコンフィギュレーションを外部指定できるように変更
[mimic/MiMicSDK.git] / lib / src / net / httpd / NyLPC_cHttpdThread.c
1 #include "NyLPC_cHttpd_protected.h"\r
2 #include "NyLPC_cHttpdConnection.h"\r
3 #include "NyLPC_cHttpdConnection_protected.h"\r
4 #include "NyLPC_cHttpdThread_protected.h"\r
5 \r
6 \r
7 static int server(void* p);\r
8 \r
9 void NyLPC_cHttpdThread_initialize(NyLPC_TcHttpdThread_t* i_inst,NyLPC_TcHttpd_t* i_parent,NyLPC_TInt32 i_prio)\r
10 {\r
11         NyLPC_cHttpdConnection_initialize(&(i_inst->_connection),i_parent);\r
12         NyLPC_cThread_initialize(&(i_inst->_super),NyLPC_cHttpdThread_SIZE_OF_THREAD_STACK,i_prio);\r
13 }\r
14 void NyLPC_cHttpdThread_finalize(NyLPC_TcHttpdThread_t* i_inst)\r
15 {\r
16         NyLPC_cThread_finalize(&i_inst->_super);\r
17         NyLPC_cHttpdConnection_finalize(&(i_inst->_connection));\r
18 }\r
19 \r
20 NyLPC_TBool NyLPC_cHttpdThread_start(NyLPC_TcHttpdThread_t* i_inst,NyLPC_TcTcpListener_t* i_listener)\r
21 {\r
22         //停止中?\r
23         if(!NyLPC_cThread_isTerminated(&(i_inst->_super))){\r
24                 return NyLPC_TBool_FALSE;\r
25         }\r
26         //リスニング\r
27         if(!NyLPC_cHttpdConnection_listenSocket(&(i_inst->_connection),i_listener)){\r
28                 return NyLPC_TBool_FALSE;\r
29         }\r
30         //Accept可能なので開始。\r
31         NyLPC_cThread_start(&(i_inst->_super),server,&i_inst->_connection);\r
32         return NyLPC_TBool_TRUE;\r
33 \r
34 }\r
35 \r
36 \r
37 \r
38 \r
39 //Httpのセッション関数\r
40 static int server(void* p)\r
41 {\r
42         NyLPC_TcHttpdConnection_t* inst=(NyLPC_TcHttpdConnection_t*)p;\r
43         //コネクションをAccept\r
44         if(!NyLPC_cHttpdConnection_acceptSocket(inst)){\r
45                 NyLPC_OnErrorGoto(Error);\r
46         }\r
47         //コネクション数の追加\r
48         NyLPC_cHttpd_incNumOfConnection(inst->_parent_httpd);\r
49 \r
50 \r
51         //サブネットアクセスの確認\r
52         for(;;){\r
53                 //リクエストのプレフィクスを取得\r
54                 if(!NyLPC_cHttpdConnection_prefetch(inst)){\r
55                         //Prefetch出来ないならループ終了。\r
56                         break;\r
57                 }\r
58                 //持続性接続の初期モードを設定\r
59                 if(NyLPC_cHttpd_getNumOfConnection(inst->_parent_httpd)>NyLPC_cHttpd_MAX_PERSISTENT_CONNECTION){\r
60                         NyLPC_cHttpdConnection_setConnectionMode(inst,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE);\r
61                 }else{\r
62                         NyLPC_cHttpdConnection_setConnectionMode(inst,NyLPC_TcHttpdConnection_CONNECTION_MODE_CONTINUE);\r
63                 }\r
64                 {//handler\r
65                         (inst->_parent_httpd->function.onRequest)(inst);\r
66                 }\r
67                 //HTTP層のクローズ\r
68                 if(!NyLPC_cHttpdConnection_closeResponse(inst)){\r
69                         break;\r
70                 }\r
71                 //次のプリフェッチを準備。\r
72                 if(!NyLPC_cHttpdConnection_prevNextPrefetch(inst)){\r
73                         break;\r
74                 }\r
75         }\r
76         NyLPC_cHttpd_decNumOfConnection(inst->_parent_httpd);\r
77         NyLPC_cHttpdConnection_closeSocket(inst);\r
78         return 0;\r
79 Error:\r
80         NyLPC_cHttpdConnection_closeSocket(inst);\r
81         return -1;\r
82 }\r
83 \r