OSDN Git Service

try Ajax-powered popup window of mp4 files on mode=list
[rec10/rec10-git.git] / b25-remote / CasProxy.cpp
1 // CasProxy.cpp: CCasProxy クラスのインプリメンテーション
2 //
3 //////////////////////////////////////////////////////////////////////
4
5
6 #include "CasProxy.h"
7 #include <stdio.h>
8
9 #define TCP_TIMEOUT     1000UL  // 1秒
10
11
12 DWORD CCasProxy::dwErrorDelayTime = 0UL;
13
14
15 CCasProxy::CCasProxy(void)
16 {
17
18 }
19
20 CCasProxy::~CCasProxy(void)
21 {
22         // サーバから切断
23         m_Socket.Close();
24 }
25
26 const BOOL CCasProxy::Connect(void)
27 {
28 /*
29         // エラー発生時のガードインターバル
30         if(dwErrorDelayTime){
31                 if((::GetTickCount() - dwErrorDelayTime) < TCP_TIMEOUT)return FALSE;
32                 else dwErrorDelayTime = 0UL;
33                 }
34 */
35         // サーバに接続
36         char* env = getenv("B25_SERVER_IP");
37         LPCTSTR lpszHost;
38         WORD wPort;
39         if (env) {
40                 lpszHost = env;
41         }
42         else {
43                 lpszHost = "127.0.0.1";
44         }
45         env = getenv("B25_SERVER_PORT");
46         if (env) {
47                 wPort = atoi(env);
48         }
49         else {
50                 wPort = 6900;
51         }
52
53         if(m_Socket.Connect(lpszHost, wPort, TCP_TIMEOUT)){
54                 return TRUE;
55         }
56         else{
57                 //dwErrorDelayTime = ::GetTickCount();
58                 return FALSE;
59         }
60 }
61
62 const DWORD CCasProxy::TransmitCommand(const BYTE *pSendData, const DWORD dwSendSize, BYTE *pRecvData)
63 {
64         // 送信データ準備
65         BYTE SendBuf[256];
66         SendBuf[0] = (BYTE)dwSendSize;
67         memcpy(&SendBuf[1], pSendData, dwSendSize);
68
69         try{
70                 // リクエスト送信
71                 if(!m_Socket.Send(SendBuf, dwSendSize + 1UL, TCP_TIMEOUT))throw (const DWORD)__LINE__;
72         
73                 // レスポンスヘッダ受信
74                 if(!m_Socket.Recv(SendBuf, 1UL, TCP_TIMEOUT))throw (const DWORD)__LINE__;
75
76                 // レスポンスデータ受信
77                 if(!m_Socket.Recv(pRecvData, SendBuf[0], TCP_TIMEOUT))throw (const DWORD)__LINE__;
78                 }
79         catch(const DWORD dwLine){
80                 // 通信エラー発生
81                 m_Socket.Close();
82                 return 0UL;
83                 }
84                 
85         return SendBuf[0];
86 }
87