40 _SELECTANY
bool s_boIsInitSock =
false;
41 _SELECTANY
int s_iMaxUdpDg = 0;
71 CSocketAddress(WORD portNo = 0, DWORD ipAddress = 0) : m_portNo(portNo), m_isNameMode(false)
73 m_inaddr.s_addr =
::htonl(ipAddress);
82 CSocketAddress(WORD portNo, LPCTSTR lpszIpAddressName) : m_portNo(portNo), m_isNameMode(true)
85 m_ipAddressName = lpszIpAddressName;
94 void Set(WORD portNo, DWORD ipAddress = 0)
97 m_inaddr.s_addr =
::htonl(ipAddress);
98 m_ipAddressName.
Empty();
109 void Set(WORD portNo, LPCTSTR lpszIpAddressName)
114 m_ipAddressName = lpszIpAddressName;
123 void Set(
const SOCKADDR_IN& sockaddr)
125 m_isNameMode =
false;
126 m_inaddr = sockaddr.sin_addr;
127 m_ipAddressName.
Empty();
128 m_portNo =
::ntohs(sockaddr.sin_port);
135 void Get(IN_ADDR& _inaddr)
const
137 if ( ! m_isNameMode )
143 DWORD ad = ::inet_addr(m_ipAddressName);
144 if ( ad == INADDR_NONE )
147 LPHOSTENT ptHost = ::gethostbyname(m_ipAddressName);
148 if ( ptHost == NULL )
150 TRACE2(
"::gethostbyname(%s) error = %d\n",
CStr(m_ipAddressName), ::WSAGetLastError() );
155 ad = *(
reinterpret_cast<DWORD*
>(ptHost->h_addr));
167 void Get(SOCKADDR_IN& _sockaddr)
const
169 Get(_sockaddr.sin_addr);
170 _sockaddr.sin_port =
::htons(m_portNo);
184 hostent* P = ::gethostbyaddr(
reinterpret_cast<const char*
>(&inaddr),
sizeof(inaddr), AF_INET);
187 return CStr(P->h_name);
200 if ( ! m_isNameMode )
202 if ( withDns && m_inaddr.s_addr != INADDR_ANY)
204 hostent* P = ::gethostbyaddr(
reinterpret_cast<const char*
>(&m_inaddr),
sizeof(m_inaddr), AF_INET);
207 return CStr(P->h_name);
210 return CStr(::inet_ntoa(m_inaddr));
214 return CStr(m_ipAddressName);
226 return ::htonl(addr.s_addr);
257 return ::htonl(hostlong);
269 return ::htons(hostshort);
281 return ::ntohl(netlong);
293 return ::ntohl(netshort);
345 virtual bool Send(
size_t dataSize, LPCVOID lpcvData)
const;
357 return static_cast<DWORD
>(m_soData) | 0x80000000;
451 m_lpcBuffer =
new char[E_BufferSize];
457 delete[] m_lpcBuffer;
468 m_piSocketListner = piSocketListener;
480 if ( s_boIsInitSock )
484 s_boIsInitSock =
true;
486 SOCKET so = ::socket(AF_INET, SOCK_STREAM, 0);
487 if ( so != SOCKET_ERROR )
492 if ( ::WSAGetLastError() == WSANOTINITIALISED )
496 if ( ::WSAStartup(E_DefaultVersion, &wsaData) == SOCKET_ERROR )
498 ASSERT1(
false,
"WSAStartup",
"error = %d\n", ::WSAGetLastError() );
502 static CCleanup s_cleanup;
503 if ( LOBYTE(wsaData.wVersion) == 1 )
505 s_iMaxUdpDg = wsaData.iMaxUdpDg;
526 hostent* pHostEnt = ::gethostbyname(na);
527 if ( pHostEnt != NULL )
531 DWORD* p =
reinterpret_cast<DWORD*
>(pHostEnt->h_addr_list[i]);
547 struct TSockAddr : SOCKADDR_IN
550 void Init(
void) { memset(
this, 0,
sizeof(SOCKADDR_IN)); }
552 static int GetSize(
void) {
return sizeof(SOCKADDR_IN); }
554 operator LPSOCKADDR(
void) {
return reinterpret_cast<LPSOCKADDR
>(
this); }
559 #ifdef _TnbWINSOCK2_ENABLE
560 E_DefaultVersion = WINSOCK_VERSION,
562 E_DefaultVersion = MAKEWORD(1, 1),
564 E_BufferSize = 10000,
566 E_SelectTimeout = 2000,
567 E_ConnectTimeout = 2000,
569 TSockAddr m_sockaddrPartner;
570 IListener * m_piSocketListner;
577 public:~CCleanup(
void) { ::WSACleanup(); }
587 static bool ms_AddressToIp(IN_ADDR& _addr, LPCTSTR lpszAddress)
592 return (_addr.s_addr != INADDR_NONE);
603 bool m_SetAddress(LPCTSTR lpszAddress, WORD wPortNo)
606 m_sockaddrPartner.Init();
607 m_sockaddrPartner.sin_family = AF_INET;
609 a.Get(m_sockaddrPartner);
610 return m_sockaddrPartner.sin_addr.s_addr != INADDR_NONE;
623 m_sockaddrPartner.Init();
624 m_sockaddrPartner.sin_family = AF_INET;
625 address.
Get(m_sockaddrPartner);
626 return m_sockaddrPartner.sin_addr.s_addr != INADDR_NONE;
636 bool m_Recv(SOCKET so)
638 int iLen = ::recv(so, m_lpcBuffer, E_BufferSize, 0);
639 if ( iLen == SOCKET_ERROR )
641 int iError = ::WSAGetLastError();
642 TRACE2(
"::recv(%d) error = %d\n", so, iError );
643 if ( iError != WSAENOTSOCK && iError != WSAESHUTDOWN )
649 else if ( iLen == 0 )
651 TTRACE0(
"CSocket:Closed Connection\n");
657 s.SetData(iLen, m_lpcBuffer);
658 if ( ! m_OnSocketEvent(s) )
673 static bool ms_SetDelayMode(SOCKET so,
bool boIsDelay)
675 BOOL boValue = ! boIsDelay;
676 int iRc = ::setsockopt(
680 reinterpret_cast<const char*
>(&boValue),
683 if ( iRc != 0) { TRACE2(
"::setsockopt(%d) error = %d\n ", so, ::WSAGetLastError()); }
687 ::setsockopt(so, SOL_SOCKET, SO_REUSEADDR,
reinterpret_cast<const char*
>(&yes),
sizeof(yes));
700 virtual bool m_Send(SOCKET so,
size_t dataSize, LPCVOID lpcvData)
702 if ( so == INVALID_SOCKET )
706 int iRc = ::send(so,
static_cast<const char*
>(lpcvData),
ToInt(dataSize), 0);
707 TRACE2(
"::send(%u) result = %d\n", dataSize, iRc);
708 return iRc ==
ToInt(dataSize);
721 int iLen = addr.GetSize();
722 if ( ::getpeername(so, addr, &iLen) == SOCKET_ERROR )
724 TRACE2(
"::getpeername(%d) error = %d\n", so, ::WSAGetLastError() );
740 if ( m_piSocketListner != NULL )
742 r &= m_piSocketListner->OnSocketEvent(e);
744 r &= _super::m_OnEvent(e);
752 WORD m_GetMaxUdpDg(SOCKET s)
754 ASSERTLIB(s_iMaxUdpDg >= 0);
755 #ifdef _TnbWINSOCK2_ENABLE
756 if ( s_iMaxUdpDg == 0 )
759 int iOptLen =
sizeof(iOptVal);
760 int r = ::getsockopt(s, SOL_SOCKET, SO_MAX_MSG_SIZE,
reinterpret_cast<char*
>(&iOptVal), &iOptLen);
761 return static_cast<WORD
>((r == SOCKET_ERROR) ? 0 : iOptVal);
764 return static_cast<WORD
>(s_iMaxUdpDg);
773 : _super(static_cast<
IReport*>(pcSocket), eEvent, dwError)
776 m_pcSocket = pcSocket;
782 return m_pcSocket->
Send(dataSize, lpcvData);
789 return m_pcSocket->m_GetPeerName(_address, m_soData);
795 CAbstractSocket::TSockAddr addr;
796 int iLen = addr.GetSize();
797 if ( ::getsockname(m_soData, addr, &iLen) == SOCKET_ERROR )
799 TRACE2(
"::getpeername(%d) error = %d\n", m_soData, ::WSAGetLastError() );
852 : _super(), m_soData(INVALID_SOCKET), m_isAutoReconnect(isAutoReconnect), m_wServerPortNo(0)
861 m_threadReceiver.
Stop();
872 m_boIsDelay = boIsDelay;
882 return CStr::Fmt(_T(
"SocketClient[%u]:"), m_soData);
893 return TNBVIW_KIND_SOCK_C + (m_soData & 0xFFFF);
928 if ( ! m_SetAddress(m_strServerAddress, m_wServerPortNo) )
930 if ( ! m_isAutoReconnect )
935 if ( ! m_isAutoReconnect )
937 if ( ! m_ConnectSub() )
943 m_threadReceiver.
Start(
CStr::Fmt(_T(
"Client(p=%d)監視"), m_wServerPortNo));
945 m_threadReceiver.
Start();
971 return m_threadReceiver.
IsAlive();
981 return m_soData != INVALID_SOCKET;
991 virtual bool Send(
size_t dataSize, LPCVOID lpcvData)
993 TTRACE1(
"CSocket[Client%d]:Send\n", m_soData);
994 _super::m_OnSend(dataSize, lpcvData);
995 return m_Send(m_soData, dataSize, lpcvData);
1005 m_CloseDataSocket();
1007 m_threadReceiver.
Stop();
1024 return m_threadReceiver;
1029 bool Connect(LPCTSTR lpszAddress, WORD wPortNo)
1038 bool m_isAutoReconnect;
1040 CStr m_strServerAddress;
1041 WORD m_wServerPortNo;
1050 bool m_ConnectWithTimeout(SOCKET so, DWORD dwTimeout)
1053 ::ioctlsocket(so, FIONBIO, &dwOpt);
1054 int iCntRst = ::connect(so, m_sockaddrPartner, m_sockaddrPartner.GetSize());
1055 if ( iCntRst == SOCKET_ERROR )
1057 DWORD dwError = ::WSAGetLastError();
1058 if ( dwError != WSAEWOULDBLOCK )
1060 TRACE2(
"::connect(%d) error = %d\n", so, dwError);
1062 ::ioctlsocket(so, FIONBIO, &dwOpt);
1067 FD_SET(so, &tFdSet);
1068 timeval tTimeVal = { dwTimeout / 1000, dwTimeout % 1000 };
1069 ::select(FD_SETSIZE, NULL, &tFdSet, NULL, &tTimeVal);
1070 if ( ! FD_ISSET(so, &tFdSet) )
1073 ::ioctlsocket(so, FIONBIO, &dwOpt);
1078 ::ioctlsocket(so, FIONBIO, &dwOpt);
1089 bool m_ConnectSub(
void)
1091 if ( m_soData != INVALID_SOCKET )
1095 SOCKET so = ::socket(AF_INET, SOCK_STREAM, 0);
1096 if ( so == SOCKET_ERROR )
1098 TRACE1(
"::socket() error = %d\n", ::WSAGetLastError() );
1101 if ( ! ms_AddressToIp(m_sockaddrPartner.sin_addr, m_strServerAddress) )
1103 ::shutdown(so, SD_BOTH);
1107 if ( ! m_ConnectWithTimeout(so, E_ConnectTimeout) )
1109 ::shutdown(so, SD_BOTH);
1113 TTRACE1(
"CSocket[Client%d]:Connected\n", so);
1117 m_CloseDataSocket();
1120 ms_SetDelayMode(m_soData, m_boIsDelay);
1125 void m_CloseDataSocket(
void)
1127 if ( m_soData != INVALID_SOCKET )
1129 SOCKET so = m_soData;
1130 m_soData = INVALID_SOCKET;
1131 TTRACE1(
"CSocket[Client%d]:Closed\n", so);
1133 ::shutdown(so, SD_BOTH);
1142 virtual DWORD Run(
void)
1146 if ( ! m_ConnectSub() )
1154 ::Sleep(E_RetryDelay / 20);
1165 FD_SET(m_soData, &tFdSet);
1166 int iSelTime = E_SelectTimeout;
1167 int iInterval = _super::GetIdleInterval();
1168 if ( iInterval > 0 )
1170 iSelTime = iInterval;
1172 timeval tTimeVal = { iSelTime / 1000, iSelTime % 1000 };
1173 ::select(
ToInt(m_soData + 1), &tFdSet, NULL, NULL, &tTimeVal);
1174 if ( ! FD_ISSET(m_soData, &tFdSet) )
1179 if ( ! m_GetPeerName(adds, m_soData) )
1193 if ( ! m_Recv(m_soData) )
1197 TTRACE1(
"CSocket[Client%d]:受信成功\n", m_soData);
1201 TTRACE1(
"CSocket[Client%d]:受信停止\n", m_soData);
1202 m_CloseDataSocket();
1203 if ( ! m_isAutoReconnect )
1213 ::Sleep(E_RetryDelay / 20);
1264 CSocketServer(
void) : _super(), m_soListen(INVALID_SOCKET), m_connectMax(1), m_wOpenPortNo(0)
1283 m_boIsDelay = boIsDelay;
1293 return CStr::Fmt(_T(
"SocketServer[%08X]:"),
this);
1304 return TNBVIW_KIND_SOCK_S + (
reinterpret_cast<DWORD
>(
this) & 0xFFFF);
1350 if ( m_strAwaitAddress.
IsEmpty() )
1352 m_strAwaitAddress = _T(
"0.0.0.0");
1354 if ( ! m_SetAddress(m_strAwaitAddress, m_wOpenPortNo) )
1358 if ( m_OpenListenSocket() == 10048 )
1363 m_threadReceiver.
Start(
CStr::Fmt(_T(
"Server(p=%d)監視"), m_wOpenPortNo));
1365 m_threadReceiver.
Start();
1409 if ( m_vsoData[i] == so ){
return true; }
1422 bool Send(SOCKET so,
size_t dataSize, LPCVOID lpcvData)
1424 TTRACE1(
"CSocket[Server%d]:Send\n", so);
1425 _super::m_OnSend(dataSize, lpcvData);
1426 return m_Send(so, dataSize, lpcvData);
1438 return m_GetPeerName(_address, so);
1447 m_CloseDataSocket(so);
1458 return m_threadReceiver.
IsAlive();
1479 virtual bool Send(
size_t dataSize, LPCVOID lpcvData)
1481 TTRACE0(
"CSocket[Server%d]:Send<All>\n");
1486 boRc &=
Send(m_vsoData[i], dataSize, lpcvData);
1498 m_CloseAllDataSockets();
1499 m_OpenListenSocket();
1515 TTRACE0(
"CSocket[Server]:サーバクローズ\n");
1516 m_CloseAllDataSockets();
1517 m_CloseListenSocket();
1518 m_threadReceiver.
Stop();
1527 return m_threadReceiver;
1535 size_t m_connectMax;
1537 CStr m_strAwaitAddress;
1543 void m_CloseAllDataSockets(
void)
1546 size_t iLen = m_vsoData.
GetSize();
1549 TTRACE0(
"CSocket[Server]:全クローズ\n");
1552 if ( m_vsoData[i] != INVALID_SOCKET )
1554 SOCKET so = m_vsoData[i];
1555 TTRACE1(
"CSocket[Server%d]:クローズ\n", so);
1557 ::shutdown(so, SD_BOTH);
1569 void m_CloseDataSocket(SOCKET so)
1574 if ( m_vsoData[i] == so )
1576 TTRACE1(
"CSocket[Server%d]:クローズ\n", so);
1579 ::shutdown(so, SD_BOTH);
1581 m_OpenListenSocket();
1592 int m_OpenListenSocket(
void)
1594 if ( m_soListen == INVALID_SOCKET )
1596 m_soListen = ::socket(AF_INET, SOCK_STREAM, 0);
1597 if ( m_soListen == INVALID_SOCKET )
1599 int r = ::WSAGetLastError();
1601 TRACE1(
"::socket() error = %d\n", r );
1604 if ( ::bind(m_soListen, m_sockaddrPartner, m_sockaddrPartner.GetSize()) == SOCKET_ERROR )
1606 int r = ::WSAGetLastError();
1608 TRACE2(
"::bind(%d) error = %d\n", m_soListen, r );
1611 TTRACE0(
"CSocket[Server]:リスナーSOCKETオープン\n");
1612 if ( ::listen(m_soListen, 5) == SOCKET_ERROR )
1614 int r = ::WSAGetLastError();
1616 TRACE2(
"::listen(%d) error = %d\n", m_soListen, r );
1617 m_CloseListenSocket();
1625 void m_CloseListenSocket(
void)
1627 if ( m_soListen != INVALID_SOCKET )
1629 SOCKET so = m_soListen;
1630 m_soListen = INVALID_SOCKET;
1631 TTRACE0(
"CSocket[Server]:リスナーSOCKETクローズ\n");
1632 ::shutdown(so, SD_BOTH);
1641 virtual DWORD Run(
void)
1645 if ( m_OpenListenSocket() != 0 )
1653 ::Sleep(E_RetryDelay / 20);
1666 if ( iConnectedCount > 0 )
1668 loop ( i, iConnectedCount )
1670 FD_SET(vsoBack[i], &tFdSet);
1673 if ( m_soListen != INVALID_SOCKET )
1675 FD_SET(m_soListen, &tFdSet);
1677 int iSelTime = E_SelectTimeout;
1678 int iInterval = _super::GetIdleInterval();
1679 if ( iInterval > 0 )
1681 iSelTime = iInterval;
1683 timeval tTimeVal = { iSelTime / 1000, iSelTime % 1000 };
1684 if ( ::select(FD_SETSIZE, &tFdSet, NULL, NULL, &tTimeVal) == SOCKET_ERROR )
1686 DWORD dwError = ::WSAGetLastError();
1687 TRACE1(
"::select() error = %d\n", dwError );
1688 if ( dwError == WSAEINVAL )
1690 ::Sleep(E_SelectTimeout);
1694 if ( FD_ISSET(m_soListen, &tFdSet) )
1696 FD_CLR(m_soListen, &tFdSet);
1698 int iFromlen = addrFrom.GetSize();
1699 SOCKET so = ::accept(m_soListen, addrFrom, &iFromlen);
1700 if ( so == INVALID_SOCKET )
1702 TRACE2(
"::accept(%d) error = %d\n", m_soListen, ::WSAGetLastError() );
1703 m_CloseListenSocket();
1705 else if ( m_vsoData.
GetSize() >= m_connectMax )
1707 TTRACE1(
"CSocket[Server%d]:接続依頼、拒否\n", so );
1708 m_CloseListenSocket();
1709 ::shutdown(so, SD_BOTH);
1714 TTRACE1(
"CSocket[Server%d]:接続\n", so);
1715 ms_SetDelayMode(so, m_boIsDelay);
1718 m_vsoData.
AddEx(so);
1719 if ( m_vsoData.
GetSize() >= m_connectMax )
1721 m_CloseListenSocket();
1726 TTRACE1(
"CSocket[Server%d]:切断\n", so);
1727 m_CloseDataSocket(so);
1728 m_OpenListenSocket();
1732 if ( iConnectedCount == 0 )
1736 if ( tFdSet.fd_count == 0 )
1741 loop ( i, iConnectedCount )
1743 if ( ! m_GetPeerName(adds, vsoBack[i]) )
1745 m_CloseDataSocket(vsoBack[i]);
1746 m_OpenListenSocket();
1752 loop ( i, iConnectedCount )
1756 TTRACE1(
"CSocket[Server%d]:切断\n", vsoBack[i]);
1757 m_CloseDataSocket(vsoBack[i]);
1758 m_OpenListenSocket();
1765 loop ( i, iConnectedCount )
1767 if ( ! FD_ISSET(vsoBack[i], &tFdSet) )
1771 if ( ! m_Recv(vsoBack[i]) )
1773 TTRACE1(
"CSocket[Server%d]:切断(Recvによる)\n", vsoBack[i]);
1774 m_CloseDataSocket(vsoBack[i]);
1775 m_OpenListenSocket();
1779 TTRACE1(
"CSocket[Server%d]:データ受信\n", vsoBack[i]);
#define loop(VAR, CNT)
loop構文.
static void StartUp(void)
[設定] SOCKET初期化.
virtual ~CAbstractSocket(void)
デストラクタ
friend class CSocketEvent
フレンドクラス定義
static CDwordVector GetMyAddress(void)
[取得] 自IPアドレス取得.
virtual void SetSocketListener(IListener *piSocketListener)
[設定] リスナー登録
CAbstractSocket(void)
コンストラクタ
void Set(WORD portNo, DWORD ipAddress=0)
[設定] アドレス設定.
CSocketAddress(WORD portNo=0, DWORD ipAddress=0)
コンストラクタ
void Set(WORD portNo, LPCTSTR lpszIpAddressName)
[設定] アドレス設定.
static DWORD ntohl(DWORD netlong)
[変換] バイトオーダー変換(network to host) unsigned long (32bit) を Network Byte Order から Host Byte Order に変換します。
CStr GetHostName(void) const
[取得] ホスト名取得.
static DWORD ntohs(DWORD netshort)
[変換] バイトオーダー変換(network to host) unsigned short (16bit) を Network Byte Order から Host Byte Order に変換します...
WORD GetPortNo(void) const
[取得] ポートNo取得.
static DWORD htonl(DWORD hostlong)
[変換] バイトオーダー変換(host to network) unsigned long (32bit) を Host Byte Order から Network Byte Order に変換します。
CStr GetAddressString(bool withDns=true) const
[取得] IP アドレス文字列取得.
DWORD GetAddress(void) const
[取得] IP アドレス取得.
bool IsBroadcast(void) const
[確認] ブロードキャスト?.
CSocketAddress(WORD portNo, LPCTSTR lpszIpAddressName)
コンストラクタ.
void Get(SOCKADDR_IN &_sockaddr) const
[取得] IP アドレス&ポート No 取得.
void Get(IN_ADDR &_inaddr) const
[取得] IPアドレス取得.
static WORD htons(WORD hostshort)
[変換] バイトオーダー変換(host to network) unsigned short (16bit) を Host Byte Order から Network Byte Order に変換します...
void Set(const SOCKADDR_IN &sockaddr)
[設定] アドレス設定.
CThreadStatus & ReferThreadStatus(void)
[設定] 受信スレッド状態種取得.
CSocketClient(bool isAutoReconnect=true)
コンストラクタ
virtual void Stop(void)
[実行] 切断
virtual bool Send(size_t dataSize, LPCVOID lpcvData)
[実行] 送信
virtual CStr GetReportName(void) const
[取得] コミュニケーション名.
SOCKET GetSocket(void) const
[取得] ソケット取得
virtual ~CSocketClient(void)
デストラクタ
virtual DWORD GetReportID(void) const
[取得] コミュニケーションID.
void SetDelayMode(bool boIsDelay)
[設定] 送信遅延モード設定
void Disconnect(void)
[実行] 切断
virtual bool IsConnect(void) const
[確認] 接続確認
virtual bool IsAlive(void) const
[確認] Aliveチェック.
bool Connect(const CSocketAddress &address)
[実行] 開始
void SetServer(const CSocketAddress &address)
[設定] サーバ設定
virtual bool Start(void)
[実行] 開始
SOCKET GetSocket(void) const
[取得] ソケット取得
bool GetSockName(CSocketAddress &_address) const
[取得] 受信側情報取得
bool GetPeerName(CSocketAddress &_address) const
[取得] 送信元情報取得
CSocketEvent(CAbstractSocket *pcSocket, SOCKET so, EReportEvent eEvent=ReportEvent_Non, DWORD dwError=0)
コンストラクタ
virtual bool Send(size_t dataSize, LPCVOID lpcvData) const
[送信] データ送信
virtual DWORD GetInterfaceId(void) const
[取得] インターフェースID取得
CThreadStatus & ReferThreadStatus(void)
[参照] 受信スレッド状態参照.
void SetConnectMax(size_t max)
[設定] 接続可能数.
INT_PTR GetConnectedSockets(CSocketVector *P=NULL) const
[取得] 接続ソケット一覧と数を取得
virtual void Stop(void)
[実行] サーバをクローズ
virtual bool Send(size_t dataSize, LPCVOID lpcvData)
[実行] 全部に送信.
virtual CStr GetReportName(void) const
[取得] コミュニケーション名.
void SetParameter(const CSocketAddress &address)
[設定] サーバ設定
virtual ~CSocketServer(void)
デストラクタ
virtual DWORD GetReportID(void) const
[取得] コミュニケーションID.
void SetDelayMode(bool boIsDelay)
[設定] 送信遅延モード設定
CSocketServer(void)
コンストラクタ
void Disconnect(SOCKET so)
[実行] 指定ソケットの切断
void Disconnect(void)
[実行] 全ソケットの切断.
bool GetPeerName(CSocketAddress &_address, SOCKET so)
[取得] 指定ソケットの接続情報取得
void Close(void)
[実行] サーバをクローズ
bool Open(const CSocketAddress &address)
[実行] オープン.
virtual bool IsConnect(void) const
[確認] 接続チェック
bool IsConnect(SOCKET so) const
[確認] 指定ソケットの接続確認
virtual bool IsAlive(void) const
[確認] Aliveチェック.
bool Send(SOCKET so, size_t dataSize, LPCVOID lpcvData)
[実行] データ送信
virtual bool Start(void)
[実行] 開始.
bool IsEmpty(void) const
[確認] 空チェック
void ReleaseBuffer(void)
[操作] 割り当てたバッファを開放.
static CStrT Fmt(const TCHAR *lpszFormat,...)
[作成] 書式付き文字列作成
TYP * GetBuffer(size_t iLength=0)
[操作] 書き込みバッファ要求.
bool IsAlive(void) const
[確認] スレッドが生きているか
bool SetRunner(IRunner *pRunner)
[設定] ランナー、設定
bool Stop(DWORD dwWait=15000)
[設定] スレッド停止 スレッドに対して停止要求します。
bool Start(LPCTSTR lpszName=NULL)
[設定] スレッド開始
bool IsPassedAndReset(DWORD dwTime, bool isNow=true)
[確認] 経過確認&リセット.
void Reset(void)
[設定] リセット.
virtual size_t GetSize(void) const
[取得] サイズ取得
virtual bool Remove(INDEX index)
[削除] 要素一つ削除.
virtual bool RemoveAll(void)
[削除] 空化
virtual INDEX Add(const TYP &t)
[追加] 要素一つ追加.
TNB::CStrT< TCHAR > CStr
文字列クラス
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
#define EXCLUSIVE(CLS)
簡易排他制御マクロ.
WORD SwapEndian(WORD val)
[変換] エンディアン変換.
TNB::CVectorT< SOCKET > CSocketVector
SOCKETの配列型宣言
@ ReportEvent_Disconnect
切断.
virtual ~IListener(void)
デストラクタ
virtual bool OnSocketEvent(const CSocketEvent &ev)=0
[通知] イベント発生.
bool IsRunnable(void) const
[確認] 実行可能か否か
INDEX AddEx(const TYP &t)
[追加] 要素一つ追加.
virtual bool Send(size_t dataSize, LPCVOID lpcData)=0
[送信] データ送信