| 1 |
#include "stdafx.h" |
| 2 |
#include "WinCS.h" |
| 3 |
#include "ClientSocket.h" |
| 4 |
#include "WinCSDlg.h" |
| 5 |
|
| 6 |
////////////////////////////////////////////////////////////////////////// |
| 7 |
|
| 8 |
CSocketEx::CSocketEx() |
| 9 |
{ |
| 10 |
m_hTimer = NULL; |
| 11 |
} |
| 12 |
|
| 13 |
CSocketEx::~CSocketEx() |
| 14 |
{ |
| 15 |
} |
| 16 |
|
| 17 |
BOOL CSocketEx::SetTimeOut(DWORD dwTimeout) |
| 18 |
{ |
| 19 |
return CreateTimerQueueTimer(&m_hTimer, NULL, CSocketEx::WaitTimer, |
| 20 |
this, dwTimeout, dwTimeout, 0); |
| 21 |
} |
| 22 |
|
| 23 |
BOOL CSocketEx::KillTimeOut() |
| 24 |
{ |
| 25 |
if (m_hTimer != NULL) |
| 26 |
{ |
| 27 |
DeleteTimerQueueTimer(NULL, m_hTimer, NULL); |
| 28 |
CancelBlockingCall(); |
| 29 |
m_hTimer = NULL; |
| 30 |
} |
| 31 |
return TRUE; |
| 32 |
} |
| 33 |
|
| 34 |
BOOL CSocketEx::Connect(const SOCKADDR* lpSockAddr, int nSockAddrLen, DWORD dwTimeout) |
| 35 |
{ |
| 36 |
|
| 37 |
if (dwTimeout > 0) |
| 38 |
SetTimeOut(dwTimeout); |
| 39 |
|
| 40 |
// 基本クラスの関数を呼び出す |
| 41 |
BOOL fRet = CSocket::Connect(lpSockAddr, nSockAddrLen); |
| 42 |
|
| 43 |
// タイムアウト値が設定してある場合 |
| 44 |
if (dwTimeout > 0) |
| 45 |
{ |
| 46 |
KillTimeOut(); |
| 47 |
// 操作がタイムアウトになった場合は、 |
| 48 |
// もっと自然なエラーメッセージを表示する |
| 49 |
if (GetLastError() == WSAEINTR) |
| 50 |
SetLastError(WSAETIMEDOUT); |
| 51 |
} |
| 52 |
return fRet; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
////////////////////////////////////////////////////////////////////////// |
| 57 |
|
| 58 |
CClientSocket::CClientSocket() |
| 59 |
{ |
| 60 |
} |
| 61 |
|
| 62 |
CClientSocket::~CClientSocket() |
| 63 |
{ |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
void CClientSocket::OnConnect(int nErrorCode) |
| 68 |
{ |
| 69 |
((CWinCSDlg *)AfxGetApp()->m_pMainWnd)->OnClientConnect(nErrorCode); |
| 70 |
} |
| 71 |
|
| 72 |
void CClientSocket::OnSend(int nErrorCode) |
| 73 |
{ |
| 74 |
((CWinCSDlg *)AfxGetApp()->m_pMainWnd)->OnClientSend(nErrorCode); |
| 75 |
} |
| 76 |
|
| 77 |
void CClientSocket::OnReceive(int nErrorCode) |
| 78 |
{ |
| 79 |
((CWinCSDlg *)AfxGetApp()->m_pMainWnd)->OnClientRecieve(nErrorCode); |
| 80 |
} |
| 81 |
|
| 82 |
void CClientSocket::OnClose(int nErrorCode) |
| 83 |
{ |
| 84 |
((CWinCSDlg *)AfxGetApp()->m_pMainWnd)->OnClientClose(nErrorCode); |
| 85 |
} |