TNB Library
TnbSocketXp.h
[詳解]
1#pragma once
21#ifndef _TnbWINSOCK2_ENABLE
22 #error
23#endif
24
25#include "TnbSocket.h"
26
27
28
29//TNB Library
30namespace TNB
31{
32
33
34
46{
47public:
48
50 CSocketXp(void) : m_isInit(true), m_lpfnTransmitPackets(NULL)
51 {
52 }
53
62 bool Send(SOCKET so, size_t dataSize, LPCVOID lpcvData)
63 {
64 if ( m_Init(so) )
65 {
66 TRANSMIT_PACKETS_ELEMENT packets;
67 packets.dwElFlags = TP_ELEMENT_MEMORY;
68 packets.cLength = dataSize;
69 packets.pBuffer = const_cast<void* const>(lpcvData);
70 return !! m_lpfnTransmitPackets(so, &packets, 1, 0, NULL, 0);
71 }
72 int r = ::send(so, static_cast<const char*>(lpcvData), dataSize, 0);
73 TRACE2("::send(%u) result = %d\n", dataSize, r);
74 return r == ToInt(dataSize);
75 }
76
77private:
78 bool m_isInit;
79 LPFN_TRANSMITPACKETS m_lpfnTransmitPackets;
81 bool m_Init(SOCKET so)
82 {
83 if ( ! m_isInit )
84 {
85 m_isInit = true;
86 DWORD dwBytes;
87 GUID guidTransmitPackets = WSAID_TRANSMITPACKETS;
88 ::WSAIoctl(so, SIO_GET_EXTENSION_FUNCTION_POINTER, &guidTransmitPackets, sizeof(GUID), &m_lpfnTransmitPackets, sizeof(LPVOID), &dwBytes, NULL, NULL);
89 }
90 return m_lpfnTransmitPackets != NULL;
91 }
92};
93
94
95
111{
112 DEFSUPER(CSocketClient);
113protected:
114
123 virtual bool m_Send(SOCKET so, size_t dataSize, LPCVOID lpcvData)
124 {
125 _super::m_OnSend(dataSize, lpcvData);
126 if ( so == INVALID_SOCKET )
127 {
128 return false;
129 }
130 return m_xp.Send(so, dataSize, lpcvData);
131 }
132private:
133 CSocketXp m_xp;
134};
135
136
137
158{
159 DEFSUPER(CSocketServer);
160protected:
161
170 virtual bool m_Send(SOCKET so, size_t dataSize, LPCVOID lpcvData)
171 {
172 _super::m_OnSend(dataSize, lpcvData);
173 if ( so == INVALID_SOCKET )
174 {
175 return false;
176 }
177 return m_xp.Send(so, dataSize, lpcvData);
178 }
179private:
180 CSocketXp m_xp;
181};
182
183
184
185#ifndef _TnbDOXYGEN //Document作成用シンボル
186 #define CSocketClient CSocketClientXp
187 #define CSocketServer CSocketServerXp
188#endif
189
190
191
192};
ソケットのアクセス関係のヘッダ
Socketクライアントクラス
Definition: TnbSocketXp.h:111
virtual bool m_Send(SOCKET so, size_t dataSize, LPCVOID lpcvData)
送信
Definition: TnbSocketXp.h:123
Socketクライアントクラス
Definition: TnbSocket.h:841
Socketサーバクラス
Definition: TnbSocketXp.h:158
virtual bool m_Send(SOCKET so, size_t dataSize, LPCVOID lpcvData)
送信
Definition: TnbSocketXp.h:170
Socketサーバクラス
Definition: TnbSocket.h:1259
XP以上用 Socketサポートクラス
Definition: TnbSocketXp.h:46
CSocketXp(void)
コンストラクタ
Definition: TnbSocketXp.h:50
bool Send(SOCKET so, size_t dataSize, LPCVOID lpcvData)
[送信] 送信.
Definition: TnbSocketXp.h:62
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
Definition: TnbStrLib.h:367
TNB Library
Definition: TnbDoxyTitle.txt:2