• R/O
  • SSH
  • HTTPS

wincs: Commit


Commit MetaInfo

Revisão16 (tree)
Hora2010-06-28 14:40:57
Autorsho1get

Mensagem de Log

Update_20100628

Mudança Sumário

Diff

--- SocketX/RawSocket.cpp (revision 15)
+++ SocketX/RawSocket.cpp (revision 16)
@@ -18,7 +18,7 @@
1818
1919 BOOL CRawSocket::Initialize(SOCKMSG SockMsg, DWORD dwLocalAddress, WORD wPort)
2020 {
21- SOCKADDR_IN siAddr;
21+ SOCKADDR_IN sAddrIn;
2222
2323 if (!CreateSocket(SockMsg))
2424 {
@@ -31,16 +31,16 @@
3131 return FALSE;
3232 }
3333
34- if (!(SetSendBufferSize(SX_UDP_BUFSIZE) && SetSendBufferSize(SX_UDP_BUFSIZE)))
34+ if (!SetBufferSize(SX_UDP_BUFSIZE))
3535 {
3636 CloseSocket();
3737 return FALSE;
3838 }
3939
40- siAddr.sin_family = AF_INET;
41- siAddr.sin_port = htons(wPort);
42- siAddr.sin_addr.s_addr = dwLocalAddress;
43- CopyMemory(&m_LocalAddr, &siAddr, sizeof(m_LocalAddr));
40+ sAddrIn.sin_family = AF_INET;
41+ sAddrIn.sin_port = htons(wPort);
42+ sAddrIn.sin_addr.s_addr = dwLocalAddress;
43+ CopyMemory(&m_LocalAddr, &sAddrIn, sizeof(m_LocalAddr));
4444
4545 m_fInit = TRUE;
4646
@@ -49,26 +49,7 @@
4949
5050 BOOL CRawSocket::CreateSocket(SOCKMSG SockMsg)
5151 {
52- if (!IBaseSocket::CreateSocketWindow())
53- {
54- return FALSE;
55- }
56-
57- SetTargetWnd(SockMsg);
58-
59- m_hSocket = socket(AF_INET, SOCK_RAW, IPPROTO_IP);
60-
61- if (m_hSocket == INVALID_SOCKET)
62- {
63- TRACE1("***** ERROR: socket(%d) *****\n", GetLastError());
64- m_dwError = GetLastError();
65- return FALSE;
66- }
67-
68- SetSendTimeout(m_dwSendTimeout);
69- SetRecieveTimeout(m_dwReceiveTimeout);
70-
71- return TRUE;
52+ return doCreateSocket(SockMsg, SOCK_RAW, IPPROTO_IP);
7253 }
7354
7455 BOOL CRawSocket::SetPromiscuous(BOOL flag)
--- SocketX/PeerSocket.cpp (revision 15)
+++ SocketX/PeerSocket.cpp (revision 16)
@@ -17,26 +17,7 @@
1717
1818 BOOL CPeerSocket::CreateSocket(SOCKMSG SockMsg)
1919 {
20- if (!IBaseSocket::CreateSocketWindow())
21- {
22- return FALSE;
23- }
24-
25- SetTargetWnd(SockMsg);
26-
27- m_hSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
28-
29- if (m_hSocket == INVALID_SOCKET)
30- {
31- TRACE1("***** ERROR: socket(%d) *****\n", GetLastError());
32- m_dwError = GetLastError();
33- return FALSE;
34- }
35-
36- SetSendTimeout(m_dwSendTimeout);
37- SetRecieveTimeout(m_dwReceiveTimeout);
38-
39- return TRUE;
20+ return doCreateSocket(SockMsg, SOCK_DGRAM, IPPROTO_UDP);
4021 }
4122
4223 void CPeerSocket::OnClose(SOCKET hSocket, int nErrorCode)
@@ -52,7 +33,7 @@
5233 if (CloseSocket())
5334 {
5435 ConvertSockAddrToNetAddr(&m_PeerAddr, NetAddr);
55- m_SockMsg.pTgtObj->OnSocketCloseMessage(m_SockMsg.dwSocketID, NetAddr);
36+ m_SockMsg.pCallback->OnSocketCloseMessage(m_SockMsg.dwSocketID, NetAddr);
5637 }
5738 }
5839
@@ -64,13 +45,13 @@
6445 return;
6546 }
6647
67- m_SockMsg.pTgtObj->OnSocketSendMessage(m_SockMsg.dwSocketID);
48+ m_SockMsg.pCallback->OnSocketSendMessage(m_SockMsg.dwSocketID);
6849 }
6950
7051 void CPeerSocket::OnReceive(SOCKET hSocket, int nErrorCode)
7152 {
7253 CByteArray data;
73- SOCKADDR SockAddr;
54+ SOCKADDR sAddr;
7455 NETADDR NetAddr;
7556 int nLenSA = sizeof(SOCKADDR);
7657
@@ -80,18 +61,18 @@
8061 return;
8162 }
8263
83- if (!doReceiveFrom(hSocket, data, &SockAddr, &nLenSA))
64+ if (!doReceiveFrom(hSocket, data, &sAddr, &nLenSA))
8465 {
8566 return;
8667 }
8768
88- ConvertSockAddrToNetAddr(&SockAddr, NetAddr);
89- m_SockMsg.pTgtObj->OnSocketReceiveFromMessage(m_SockMsg.dwSocketID, NetAddr, data);
69+ ConvertSockAddrToNetAddr(&sAddr, NetAddr);
70+ m_SockMsg.pCallback->OnSocketReceiveFromMessage(m_SockMsg.dwSocketID, NetAddr, data);
9071 }
9172
9273 BOOL CPeerSocket::Initialize(SOCKMSG SockMsg, DWORD dwLocalAddress, WORD wPort)
9374 {
94- SOCKADDR_IN siAddr;
75+ SOCKADDR_IN sAddrIn;
9576
9677 if (!CreateSocket(SockMsg))
9778 {
@@ -104,16 +85,16 @@
10485 return FALSE;
10586 }
10687
107- if (!(SetSendBufferSize(SX_UDP_BUFSIZE) && SetSendBufferSize(SX_UDP_BUFSIZE)))
88+ if (!(SetSendBufferSize(SX_UDP_BUFSIZE) && SetReceiveBufferSize(SX_UDP_BUFSIZE)))
10889 {
10990 CloseSocket();
11091 return FALSE;
11192 }
11293
113- siAddr.sin_family = AF_INET;
114- siAddr.sin_port = htons(wPort);
115- siAddr.sin_addr.s_addr = dwLocalAddress;
116- CopyMemory(&m_LocalAddr, &siAddr, sizeof(m_LocalAddr));
94+ sAddrIn.sin_family = AF_INET;
95+ sAddrIn.sin_port = htons(wPort);
96+ sAddrIn.sin_addr.s_addr = dwLocalAddress;
97+ CopyMemory(&m_LocalAddr, &sAddrIn, sizeof(m_LocalAddr));
11798
11899 m_fInit = TRUE;
119100
--- SocketX/BcastSocket.cpp (revision 15)
+++ SocketX/BcastSocket.cpp (revision 16)
@@ -24,7 +24,7 @@
2424
2525 BOOL CBcastSocket::SetBroadcast(DWORD dwBcastAddress, WORD wPort)
2626 {
27- SOCKADDR_IN siAddr;
27+ SOCKADDR_IN sAddrIn;
2828 BOOL flag = TRUE;
2929
3030 if (!SetSockOpt(SO_BROADCAST, (LPSTR)&flag, sizeof(flag)))
@@ -32,11 +32,11 @@
3232 return FALSE;
3333 }
3434
35- siAddr.sin_family = AF_INET;
36- siAddr.sin_port = htons(wPort);
37- siAddr.sin_addr.s_addr = dwBcastAddress;
35+ sAddrIn.sin_family = AF_INET;
36+ sAddrIn.sin_port = htons(wPort);
37+ sAddrIn.sin_addr.s_addr = dwBcastAddress;
3838
39- CopyMemory(&m_BcastAddr, &siAddr, sizeof(m_BcastAddr));
39+ CopyMemory(&m_BcastAddr, &sAddrIn, sizeof(m_BcastAddr));
4040 m_fBcast = TRUE;
4141
4242 return TRUE;
--- SocketX/ServerSocket.cpp (revision 15)
+++ SocketX/ServerSocket.cpp (revision 16)
@@ -26,13 +26,13 @@
2626 return;
2727 }
2828
29- m_SockMsg.pTgtObj->OnSocketSendMessage(m_SockMsg.dwSocketID);
29+ m_SockMsg.pCallback->OnSocketSendMessage(m_SockMsg.dwSocketID);
3030 }
3131
3232 void CServerSocket::OnReceive(SOCKET hSocket, int nErrorCode)
3333 {
3434 CByteArray data, buf;
35- SOCKADDR SockAddr;
35+ SOCKADDR sAddr;
3636 NETADDR NetAddr;
3737 int nRet, nIndex;
3838
@@ -58,18 +58,18 @@
5858 return;
5959 }
6060
61- if (!doGetPeerName(hSocket, &SockAddr) || !doReceive(hSocket, data))
61+ if (!doGetPeerName(hSocket, &sAddr) || !doReceive(hSocket, data))
6262 {
6363 return;
6464 }
6565
66- ConvertSockAddrToNetAddr(&SockAddr, NetAddr);
67- m_SockMsg.pTgtObj->OnSocketReceiveMessage(m_SockMsg.dwSocketID, NetAddr, data);
66+ ConvertSockAddrToNetAddr(&sAddr, NetAddr);
67+ m_SockMsg.pCallback->OnSocketReceiveMessage(m_SockMsg.dwSocketID, NetAddr, data);
6868 }
6969
7070 void CServerSocket::OnAccept(SOCKET hSocket, int nErrorCode)
7171 {
72- SOCKADDR SockAddr;
72+ SOCKADDR sAddr;
7373 NETADDR NetAddr;
7474 int nSockLen = sizeof(SOCKADDR);
7575
@@ -79,7 +79,7 @@
7979 return;
8080 }
8181
82- if (!Accept(&SockAddr, &nSockLen))
82+ if (!Accept(&sAddr, &nSockLen))
8383 {
8484 return;
8585 }
@@ -90,8 +90,8 @@
9090 return;
9191 }
9292
93- ConvertSockAddrToNetAddr(&SockAddr, NetAddr);
94- m_SockMsg.pTgtObj->OnSocketAcceptMessage(m_SockMsg.dwSocketID, NetAddr);
93+ ConvertSockAddrToNetAddr(&sAddr, NetAddr);
94+ m_SockMsg.pCallback->OnSocketAcceptMessage(m_SockMsg.dwSocketID, NetAddr);
9595 }
9696
9797 void CServerSocket::OnClose(SOCKET hSocket, int nErrorCode)
@@ -111,36 +111,12 @@
111111 return;
112112 }
113113
114- m_SockMsg.pTgtObj->OnSocketCloseMessage(m_SockMsg.dwSocketID, NetAddr);
114+ m_SockMsg.pCallback->OnSocketCloseMessage(m_SockMsg.dwSocketID, NetAddr);
115115 }
116116
117117 BOOL CServerSocket::CreateSocket(SOCKMSG SockMsg)
118118 {
119- if (!IBaseSocket::CreateSocketWindow())
120- {
121- return FALSE;
122- }
123-
124- SetTargetWnd(SockMsg);
125-
126- m_hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
127-
128- if (m_hSocket == INVALID_SOCKET)
129- {
130- TRACE1("***** ERROR: socket(%d) *****\n", GetLastError());
131- m_dwError = GetLastError();
132- return FALSE;
133- }
134-
135- if (!AsyncSelect(FD_SERVER))
136- {
137- return FALSE;
138- }
139-
140- SetSendTimeout(m_dwSendTimeout);
141- SetRecieveTimeout(m_dwReceiveTimeout);
142-
143- return TRUE;
119+ return (doCreateSocket(SockMsg, SOCK_STREAM, IPPROTO_TCP) && AsyncSelect(FD_SERVER));
144120 }
145121
146122 BOOL CServerSocket::Initialize(SOCKMSG SockMsg, WORD wPort, DWORD dwBindAddress, int nBacklog)
@@ -204,13 +180,13 @@
204180 return TRUE;
205181 }
206182
207-BOOL CServerSocket::Accept(LPSOCKADDR lpSockAddr, int *lpSockAddrLen)
183+BOOL CServerSocket::Accept(LPSOCKADDR lpsAddr, int *lpsAddrLen)
208184 {
209185 SOCKET hSocket;
210186 BOOL flag = TRUE;
211187 BOOL fSend, fReceive;
212188
213- hSocket = accept(m_hSocket, lpSockAddr, lpSockAddrLen);
189+ hSocket = accept(m_hSocket, lpsAddr, lpsAddrLen);
214190
215191 if (hSocket == INVALID_SOCKET)
216192 {
@@ -219,7 +195,7 @@
219195 return FALSE;
220196 }
221197
222- if (!m_fInternet && !IsLANConnection(lpSockAddr))
198+ if (!m_fInternet && !IsLANConnection(lpsAddr))
223199 {
224200 doCloseSocket(hSocket);
225201 return FALSE;
@@ -261,17 +237,17 @@
261237 return FALSE;
262238 }
263239
264- AddConnection(hSocket, lpSockAddr, *lpSockAddrLen);
240+ AddConnection(hSocket, lpsAddr, *lpsAddrLen);
265241
266242 return TRUE;
267243 }
268244
269-void CServerSocket::AddConnection(SOCKET hSocket, const LPSOCKADDR lpSockAddr, int nSockAddrLen)
245+void CServerSocket::AddConnection(SOCKET hSocket, const LPSOCKADDR lpsAddr, int nSockAddrLen)
270246 {
271247 SOCKETDATA sd;
272248 ZeroMemory(&sd, sizeof(sd));
273249 sd.hSocket = hSocket;
274- ConvertSockAddrToNetAddr(lpSockAddr, sd.NetAddr);
250+ ConvertSockAddrToNetAddr(lpsAddr, sd.NetAddr);
275251 CSingleLock cl(&m_sdList.cs, TRUE);
276252 m_sdList.list.Add(sd);
277253 }
--- SocketX/McastSocket.cpp (revision 15)
+++ SocketX/McastSocket.cpp (revision 16)
@@ -19,12 +19,12 @@
1919
2020 BOOL CMcastSocket::SetReceiveMulticast(DWORD dwMcastAddress)
2121 {
22- SOCKADDR_IN siAddr;
22+ SOCKADDR_IN sAddrIn;
2323 IP_MREQ im;
2424
25- CopyMemory(&siAddr, &m_LocalAddr, sizeof(siAddr));
25+ CopyMemory(&sAddrIn, &m_LocalAddr, sizeof(sAddrIn));
2626 ZeroMemory(&im, sizeof(im));
27- im.imr_interface.s_addr = siAddr.sin_addr.s_addr;
27+ im.imr_interface.s_addr = sAddrIn.sin_addr.s_addr;
2828 im.imr_multiaddr.s_addr = dwMcastAddress;
2929
3030 if (!doSetSockOpt(m_hSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (LPSTR)&im, sizeof(im)))
@@ -36,7 +36,7 @@
3636 return TRUE;
3737 }
3838
39-BOOL CMcastSocket::JoinMulticastGroup(DWORD dwMcastAddress, WORD wPort)
39+BOOL CMcastSocket::AddMembership(DWORD dwMcastAddress, WORD wPort)
4040 {
4141 NETADDR NetAddr;
4242
@@ -55,7 +55,7 @@
5555 return TRUE;
5656 }
5757
58-BOOL CMcastSocket::LeaveMulticastGroup()
58+BOOL CMcastSocket::DropMembership()
5959 {
6060 NETADDR NetAddr;
6161
--- SocketX/BaseSocket.cpp (revision 15)
+++ SocketX/BaseSocket.cpp (revision 16)
@@ -157,33 +157,40 @@
157157
158158 BOOL IBaseSocket::CloseSocket()
159159 {
160- m_fInit = !doCloseSocket(m_hSocket);
161- return m_fInit;
160+ if (!doCloseSocket(m_hSocket))
161+ {
162+ return FALSE;
163+ }
164+
165+ m_lEvent = 0;
166+ m_fInit = FALSE;
167+
168+ return TRUE;
162169 }
163170
164-BOOL IBaseSocket::IsLANConnection(const LPSOCKADDR lpSockAddr)
171+BOOL IBaseSocket::IsLANConnection(const LPSOCKADDR lpsAddr)
165172 {
166- SOCKADDR_IN siAddr;
167- CopyMemory(&siAddr, lpSockAddr, sizeof(siAddr));
168- return (m_LocalNet.dwNet == (m_LocalNet.dwMask & siAddr.sin_addr.s_addr));
173+ SOCKADDR_IN sAddrIn;
174+ CopyMemory(&sAddrIn, lpsAddr, sizeof(sAddrIn));
175+ return (m_LocalNet.dwNet == (m_LocalNet.dwMask & sAddrIn.sin_addr.s_addr));
169176 }
170177
171-void IBaseSocket::MakeSockAddrIN(LPSOCKADDR_IN lpSockAddrIN, DWORD dwAddress,
172- WORD wPort, UINT nAF)
178+void IBaseSocket::MakeSockAddrIN(LPSOCKADDR_IN lpsAddrIn, DWORD dwAddress,
179+ WORD wPort, UINT nFamily)
173180 {
174- ZeroMemory(lpSockAddrIN, sizeof(LPSOCKADDR_IN));
175- lpSockAddrIN->sin_port = htons(wPort);
176- lpSockAddrIN->sin_family = nAF;
177- lpSockAddrIN->sin_addr.s_addr = dwAddress;
181+ ZeroMemory(lpsAddrIn, sizeof(SOCKADDR_IN));
182+ lpsAddrIn->sin_port = htons(wPort);
183+ lpsAddrIn->sin_family = nFamily;
184+ lpsAddrIn->sin_addr.s_addr = dwAddress;
178185 }
179186
180-void IBaseSocket::ConvertSockAddrToNetAddr(const LPSOCKADDR lpSockAddr, NETADDR &NetAddr)
187+void IBaseSocket::ConvertSockAddrToNetAddr(const LPSOCKADDR lpsAddr, NETADDR &NetAddr)
181188 {
182- SOCKADDR_IN siAddr;
183- CopyMemory(&siAddr, lpSockAddr, sizeof(siAddr));
184- NetAddr.wPort = ntohs(siAddr.sin_port);
185- NetAddr.nAF = siAddr.sin_family;
186- NetAddr.dwAddress = siAddr.sin_addr.s_addr;
189+ SOCKADDR_IN sAddrIn;
190+ CopyMemory(&sAddrIn, lpsAddr, sizeof(sAddrIn));
191+ NetAddr.wPort = ntohs(sAddrIn.sin_port);
192+ NetAddr.nFamily = sAddrIn.sin_family;
193+ NetAddr.dwAddress = sAddrIn.sin_addr.s_addr;
187194 }
188195
189196 BOOL IBaseSocket::Shutdown(int nFlag)
@@ -228,17 +235,24 @@
228235
229236 BOOL IBaseSocket::Bind(WORD wPort, DWORD dwAddress)
230237 {
231- return doBind(m_hSocket, wPort, dwAddress);
238+ if (!doBind(m_hSocket, wPort, dwAddress))
239+ {
240+ return FALSE;
241+ }
242+
243+ m_wBindPort = wPort;
244+
245+ return TRUE;
232246 }
233247
234-BOOL IBaseSocket::GetSockName(LPSOCKADDR lpSockAddr)
248+BOOL IBaseSocket::GetSockName(LPSOCKADDR lpsAddr)
235249 {
236- return doGetSockName(m_hSocket, lpSockAddr);
250+ return doGetSockName(m_hSocket, lpsAddr);
237251 }
238252
239-BOOL IBaseSocket::GetPeerName(LPSOCKADDR lpSockAddr)
253+BOOL IBaseSocket::GetPeerName(LPSOCKADDR lpsAddr)
240254 {
241- return doGetPeerName(m_hSocket, lpSockAddr);
255+ return doGetPeerName(m_hSocket, lpsAddr);
242256 }
243257
244258 BOOL IBaseSocket::SetSockOpt(int nOptionName, LPCSTR lpOptionValue,
@@ -265,14 +279,33 @@
265279
266280 BOOL IBaseSocket::SetSendBufferSize(DWORD dwBufSize)
267281 {
268- return doSetSendBufferSize(m_hSocket, dwBufSize);
282+ if (!doSetSendBufferSize(m_hSocket, dwBufSize))
283+ {
284+ return FALSE;
285+ }
286+
287+ m_dwSendBufSize = dwBufSize;
288+
289+ return TRUE;
269290 }
270291
271292 BOOL IBaseSocket::SetReceiveBufferSize(DWORD dwBufSize)
272293 {
273- return doSetReceiveBufferSize(m_hSocket, dwBufSize);
294+ if (!doSetReceiveBufferSize(m_hSocket, dwBufSize))
295+ {
296+ return FALSE;
297+ }
298+
299+ m_dwReceiveBufSize = dwBufSize;
300+
301+ return TRUE;
274302 }
275303
304+BOOL IBaseSocket::SetBufferSize(DWORD dwBufSize)
305+{
306+ return (SetSendBufferSize(dwBufSize) && SetReceiveBufferSize(dwBufSize));
307+}
308+
276309 BOOL IBaseSocket::SetKeepAlive(DWORD dwTime, DWORD dwInterval)
277310 {
278311 return doSetKeepAlive(m_hSocket, dwTime, dwInterval);
@@ -317,14 +350,14 @@
317350 return doReceive(m_hSocket, data);
318351 }
319352
320-BOOL IBaseSocket::SendTo(const CByteArray &data, const LPSOCKADDR lpSockAddr, int nSockAddrLen)
353+BOOL IBaseSocket::SendTo(const CByteArray &data, const LPSOCKADDR lpsAddr, int nSockAddrLen)
321354 {
322- return doSendTo(m_hSocket, data, lpSockAddr, nSockAddrLen);
355+ return doSendTo(m_hSocket, data, lpsAddr, nSockAddrLen);
323356 }
324357
325-BOOL IBaseSocket::ReceiveFrom(CByteArray &data, LPSOCKADDR lpSockAddr, int *lpSockAddrLen)
358+BOOL IBaseSocket::ReceiveFrom(CByteArray &data, LPSOCKADDR lpsAddr, int *lpsAddrLen)
326359 {
327- return doReceiveFrom(m_hSocket, data, lpSockAddr, lpSockAddrLen);
360+ return doReceiveFrom(m_hSocket, data, lpsAddr, lpsAddrLen);
328361 }
329362
330363 //////////////////////////////////////////////////////////////////////////
@@ -339,11 +372,35 @@
339372 return FALSE;
340373 }
341374
342- m_SockMsg.pTgtObj->OnGetHostByNameMessage(lpHostEnt);
375+ m_SockMsg.pCallback->OnGetHostByNameMessage(lpHostEnt);
343376
344377 return TRUE;
345378 }
346379
380+BOOL IBaseSocket::doCreateSocket(SOCKMSG SockMsg, int nType, int nProtocol)
381+{
382+ if (!IBaseSocket::CreateSocketWindow())
383+ {
384+ return FALSE;
385+ }
386+
387+ SetCallback(SockMsg);
388+
389+ m_hSocket = socket(AF_INET, nType, nProtocol);
390+
391+ if (m_hSocket == INVALID_SOCKET)
392+ {
393+ TRACE1("***** ERROR: socket(%d) *****\n", GetLastError());
394+ m_dwError = GetLastError();
395+ return FALSE;
396+ }
397+
398+ SetSendTimeout(m_dwSendTimeout);
399+ SetRecieveTimeout(m_dwReceiveTimeout);
400+
401+ return TRUE;
402+}
403+
347404 BOOL IBaseSocket::doCloseSocket(SOCKET hSocket)
348405 {
349406 if (closesocket(hSocket) != 0)
@@ -354,7 +411,6 @@
354411 }
355412
356413 hSocket = INVALID_SOCKET;
357- m_lEvent = 0;
358414
359415 return TRUE;
360416 }
@@ -407,11 +463,11 @@
407463
408464 BOOL IBaseSocket::doBind(SOCKET hSocket, WORD wPort, DWORD dwAddress)
409465 {
410- SOCKADDR_IN siAddr;
466+ SOCKADDR_IN sAddrIn;
411467
412- MakeSockAddrIN(&siAddr, dwAddress, wPort);
468+ MakeSockAddrIN(&sAddrIn, dwAddress, wPort);
413469
414- if (bind(hSocket, (LPSOCKADDR)&siAddr, sizeof(siAddr)) == SOCKET_ERROR)
470+ if (bind(hSocket, (LPSOCKADDR)&sAddrIn, sizeof(sAddrIn)) == SOCKET_ERROR)
415471 {
416472 TRACE1("***** ERROR: bind(%d) *****\n", GetLastError());
417473 m_dwError = GetLastError();
@@ -418,16 +474,14 @@
418474 return FALSE;
419475 }
420476
421- m_wBindPort = wPort;
422-
423477 return TRUE;
424478 }
425479
426-BOOL IBaseSocket::doGetSockName(SOCKET hSocket, LPSOCKADDR lpSockAddr)
480+BOOL IBaseSocket::doGetSockName(SOCKET hSocket, LPSOCKADDR lpsAddr)
427481 {
428482 int nLenSA = sizeof(SOCKADDR);
429483
430- if (getsockname(hSocket, lpSockAddr, &nLenSA) != 0)
484+ if (getsockname(hSocket, lpsAddr, &nLenSA) != 0)
431485 {
432486 TRACE1("***** ERROR: getsockname(%d) *****\n", GetLastError());
433487 m_dwError = GetLastError();
@@ -437,11 +491,11 @@
437491 return TRUE;
438492 }
439493
440-BOOL IBaseSocket::doGetPeerName(SOCKET hSocket, LPSOCKADDR lpSockAddr)
494+BOOL IBaseSocket::doGetPeerName(SOCKET hSocket, LPSOCKADDR lpsAddr)
441495 {
442496 int nLenSA = sizeof(SOCKADDR);
443497
444- if (getpeername(hSocket, lpSockAddr, &nLenSA) != 0)
498+ if (getpeername(hSocket, lpsAddr, &nLenSA) != 0)
445499 {
446500 TRACE1("***** ERROR: getpeername(%d) *****\n", GetLastError());
447501 m_dwError = GetLastError();
@@ -581,8 +635,8 @@
581635
582636 header.size = dataSize;
583637 snd.SetSize(hdrSize);
638+ snd.FreeExtra();
584639 CopyMemory(snd.GetData(), &header, hdrSize);
585- snd.FreeExtra();
586640
587641 do
588642 {
@@ -733,12 +787,13 @@
733787 return fResult;
734788 }
735789
736-BOOL IBaseSocket::doSendTo(SOCKET hSocket, const CByteArray &data, const LPSOCKADDR lpSockAddr, int nSockAddrLen)
790+BOOL IBaseSocket::doSendTo(SOCKET hSocket, const CByteArray &data, const LPSOCKADDR lpsAddr, int nSockAddrLen)
737791 {
738- int nRet;
792+ int nRet;
793+ DWORD dwBufSize = min(m_dwSendBufSize, static_cast<DWORD>(data.GetSize()));
739794
740795 nRet = sendto(hSocket, reinterpret_cast<LPSTR>(const_cast<BYTE *>(data.GetData())),
741- SX_UDP_BUFSIZE, 0, lpSockAddr, nSockAddrLen);
796+ dwBufSize, 0, lpsAddr, nSockAddrLen);
742797
743798 if (nRet == SOCKET_ERROR)
744799 {
@@ -750,19 +805,16 @@
750805 return TRUE;
751806 }
752807
753-BOOL IBaseSocket::doReceiveFrom(SOCKET hSocket, CByteArray &data, LPSOCKADDR lpSockAddr, int *lpSockAddrLen)
808+BOOL IBaseSocket::doReceiveFrom(SOCKET hSocket, CByteArray &data, LPSOCKADDR lpsAddr, int *lpsAddrLen)
754809 {
755810 int nRet;
756811 int nLenSA = sizeof(SOCKADDR);
757812
758- if (data.GetSize() != SX_UDP_BUFSIZE)
759- {
760- data.RemoveAll();
761- data.SetSize(SX_UDP_BUFSIZE);
762- }
813+ data.SetSize(m_dwReceiveBufSize);
814+ data.FreeExtra();
763815
764816 nRet = recvfrom(hSocket, reinterpret_cast<LPSTR>(data.GetData()),
765- SX_UDP_BUFSIZE, 0, lpSockAddr, lpSockAddrLen);
817+ m_dwReceiveBufSize, 0, lpsAddr, lpsAddrLen);
766818
767819 if (nRet == SOCKET_ERROR)
768820 {
@@ -771,8 +823,6 @@
771823 return FALSE;
772824 }
773825
774- data.FreeExtra();
775-
776826 return TRUE;
777827 }
778828
--- SocketX/SocketX.h (revision 15)
+++ SocketX/SocketX.h (revision 16)
@@ -43,7 +43,7 @@
4343
4444 BOOL SocketXInitialize();
4545
46-class ISocketMessage;
46+class ISocketCallback;
4747 class IBaseSocket;
4848 class CServerSocket;
4949 class CClientSocket;
@@ -63,7 +63,7 @@
6363 {
6464 DWORD dwAddress;
6565 WORD wPort;
66- UINT nAF;
66+ UINT nFamily;
6767 }
6868 NETADDR, *LPNETADDR;
6969
@@ -86,18 +86,18 @@
8686
8787 typedef struct _SOCKMSG
8888 {
89- ISocketMessage *pTgtObj;
90- DWORD dwSocketID;
89+ ISocketCallback *pCallback;
90+ DWORD dwSocketID;
9191 }
9292 SOCKMSG, *LPSOCKMSG;
9393
9494 //////////////////////////////////////////////////////////////////////////
9595
96-class ISocketMessage
96+class ISocketCallback
9797 {
9898 public:
99- ISocketMessage() {}
100- virtual ~ISocketMessage() {}
99+ ISocketCallback() {}
100+ virtual ~ISocketCallback() {}
101101
102102 // Message function
103103 virtual void OnSocketSendMessage(DWORD dwSocketID) {}
@@ -151,20 +151,20 @@
151151 virtual void OnSend(SOCKET hSocket, int nErrorCode) {}
152152 virtual void OnReceive(SOCKET hSocket, int nErrorCode) {}
153153
154- void SetTargetWnd(SOCKMSG SockMsg) { m_SockMsg = SockMsg; }
155- void ConvertSockAddrToNetAddr(const LPSOCKADDR lpSockAddr, NETADDR &NetAddr);
154+ void SetCallback(SOCKMSG SockMsg) { m_SockMsg = SockMsg; }
155+ void ConvertSockAddrToNetAddr(const LPSOCKADDR lpsAddr, NETADDR &NetAddr);
156156 BOOL CloseSocket();
157157 BOOL Send(const CByteArray &data);
158158 BOOL Receive(CByteArray &data);
159- BOOL SendTo(const CByteArray &data, const LPSOCKADDR lpSockAddr, int nSockAddrLen);
160- BOOL ReceiveFrom(CByteArray &data, LPSOCKADDR lpSockAddr, int *lpSockAddrLen);
159+ BOOL SendTo(const CByteArray &data, const LPSOCKADDR lpsAddr, int nSockAddrLen);
160+ BOOL ReceiveFrom(CByteArray &data, LPSOCKADDR lpsAddr, int *lpsAddrLen);
161161 BOOL Shutdown(int nFlag);
162162 BOOL AsyncSelect(LONG lEvent);
163163 BOOL AsyncGetHostByName(const LPCSTR szHostName);
164164 BOOL SetBlocking();
165165 BOOL Bind(WORD wPort, DWORD dwAddress = INADDR_ANY);
166- BOOL GetSockName(LPSOCKADDR lpSockAddr);
167- BOOL GetPeerName(LPSOCKADDR lpSockAddr);
166+ BOOL GetSockName(LPSOCKADDR lpsAddr);
167+ BOOL GetPeerName(LPSOCKADDR lpsAddr);
168168 BOOL SetSockOpt(int nOptionName, LPCSTR lpOptionValue, int nOptionLen, int nLevel = SOL_SOCKET);
169169 BOOL GetSockOpt(int nOptionName, LPSTR lpOptionValue, int *lpOptionLen, int nLevel = SOL_SOCKET);
170170 BOOL SetSendTimeout(DWORD dwTimeout);
@@ -171,6 +171,7 @@
171171 BOOL SetRecieveTimeout(DWORD dwTimeout);
172172 BOOL SetSendBufferSize(DWORD dwBufSize);
173173 BOOL SetReceiveBufferSize(DWORD dwBufSize);
174+ BOOL SetBufferSize(DWORD dwBufSize);
174175 BOOL SetKeepAlive(DWORD dwTime = SX_KA_TIME, DWORD dwInterval = SX_KA_INTERVAL);
175176 BOOL SetReuseAddr(BOOL flag);
176177 BOOL IOCtlSocket(LONG lCommand, DWORD *lpArgument);
@@ -196,15 +197,16 @@
196197 virtual BOOL CreateSocket(SOCKMSG SockMsg) = 0;
197198
198199 BOOL CreateSocketWindow();
199- BOOL IsLANConnection(const LPSOCKADDR lpSockAddr);
200- void MakeSockAddrIN(LPSOCKADDR_IN lpSockAddrIN, DWORD dwAddress, WORD wPort, UINT nAF = AF_INET);
200+ BOOL IsLANConnection(const LPSOCKADDR lpsAddr);
201+ void MakeSockAddrIN(LPSOCKADDR_IN lpsAddrIn, DWORD dwAddress, WORD wPort, UINT nFamily = AF_INET);
201202
203+ BOOL doCreateSocket(SOCKMSG SockMsg, int nType, int nProtocol);
202204 BOOL doCloseSocket(SOCKET hSocket);
203205 BOOL doGetHostByName(HANDLE hTask, int nErrorCode);
204206 BOOL doSend(SOCKET hSocket, const CByteArray &data);
205- BOOL doSendTo(SOCKET hSocket, const CByteArray &data, const LPSOCKADDR lpSockAddr, int nSockAddrLen);
207+ BOOL doSendTo(SOCKET hSocket, const CByteArray &data, const LPSOCKADDR lpsAddr, int nSockAddrLen);
206208 BOOL doReceive(SOCKET hSocket, CByteArray &data);
207- BOOL doReceiveFrom(SOCKET hSocket, CByteArray &data, LPSOCKADDR lpSockAddr, int *lpSockAddrLen);
209+ BOOL doReceiveFrom(SOCKET hSocket, CByteArray &data, LPSOCKADDR lpsAddr, int *lpsAddrLen);
208210 BOOL doSetSendTimeout(SOCKET hSocket, DWORD dwTimeout);
209211 BOOL doSetReceiveTimeout(SOCKET hSocket, DWORD dwTimeout);
210212 BOOL doSetSendBufferSize(SOCKET hSocket, DWORD dwBufSize);
@@ -217,8 +219,8 @@
217219 BOOL doSetBlocking(SOCKET hSocket);
218220 BOOL doSetKeepAlive(SOCKET hSocket, DWORD dwKaTime, DWORD dwInterval);
219221 BOOL doBind(SOCKET hSocket, WORD wPort, DWORD dwAddress);
220- BOOL doGetSockName(SOCKET hSocket, LPSOCKADDR lpSockAddr);
221- BOOL doGetPeerName(SOCKET hSocket, LPSOCKADDR lpSockAddr);
222+ BOOL doGetSockName(SOCKET hSocket, LPSOCKADDR lpsAddr);
223+ BOOL doGetPeerName(SOCKET hSocket, LPSOCKADDR lpsAddr);
222224 BOOL doSetReuseAddr(SOCKET hSocket, BOOL flag);
223225 BOOL doIOCtlSocket(SOCKET hSocket, LONG lCommand, DWORD *lpArgument);
224226 BOOL doWSAIOCtl(SOCKET hSocket, DWORD dwIoCtlCode, LPVOID lpInBuf, DWORD dwInBuf, LPVOID lpOutBuf,
@@ -272,6 +274,8 @@
272274 DWORD m_dwError;
273275 DWORD m_dwSendTimeout;
274276 DWORD m_dwReceiveTimeout;
277+ DWORD m_dwSendBufSize;
278+ DWORD m_dwReceiveBufSize;
275279 LONG m_lEvent;
276280 WORD m_wBindPort;
277281 BOOL m_fBlocking;
@@ -295,7 +299,7 @@
295299 virtual void OnReceive(SOCKET hSocket, int nErrorCode);
296300
297301 BOOL Initialize(SOCKMSG SockMsg, WORD wPort, DWORD dwBindAddress = INADDR_ANY, int nBacklog = 5);
298- BOOL Accept(LPSOCKADDR lpSockAddr, int *lpSockAddrLen);
302+ BOOL Accept(LPSOCKADDR lpsAddr, int *lpsAddrLen);
299303 BOOL Listen(int nBacklog = 5);
300304 BOOL Broadcast(const CByteArray &data);
301305 BOOL SendToClient(const CByteArray &data, DWORD dwAddress, WORD wPort);
@@ -309,7 +313,7 @@
309313 virtual BOOL CreateSocket(SOCKMSG SockMsg);
310314
311315 int SearchSocketConnection(SOCKET hSocket);
312- void AddConnection(SOCKET hSocket, const LPSOCKADDR lpSockAddr, int nSockAddrLen);
316+ void AddConnection(SOCKET hSocket, const LPSOCKADDR lpsAddr, int nSockAddrLen);
313317 void CloseAllSocketConnection();
314318 BOOL ServerReceive(SOCKET hSocket);
315319 BOOL CloseSocketConnection(SOCKET hSocket, LPNETADDR lpNetAddr);
@@ -405,8 +409,8 @@
405409 virtual ~CMcastSocket();
406410
407411 BOOL SetReceiveMulticast(DWORD dwMcastAddress);
408- BOOL JoinMulticastGroup(DWORD dwMcastAddress, WORD wPort);
409- BOOL LeaveMulticastGroup();
412+ BOOL AddMembership(DWORD dwMcastAddress, WORD wPort);
413+ BOOL DropMembership();
410414 BOOL SetTTL(DWORD dwTTL);
411415 BOOL Multicast(const CByteArray &data);
412416
--- SocketX/ClientSocket.cpp (revision 15)
+++ SocketX/ClientSocket.cpp (revision 16)
@@ -18,7 +18,7 @@
1818
1919 void CClientSocket::OnConnect(SOCKET hSocket, int nErrorCode)
2020 {
21- SOCKADDR SockAddr;
21+ SOCKADDR sAddr;
2222 NETADDR NetAddr;
2323
2424 if (nErrorCode != 0)
@@ -27,21 +27,21 @@
2727 return;
2828 }
2929
30- if (!doGetPeerName(hSocket, &SockAddr) || !AsyncSelect(FD_CLIENT))
30+ if (!doGetPeerName(hSocket, &sAddr) || !AsyncSelect(FD_CLIENT))
3131 {
3232 return;
3333 }
3434
35- CopyMemory(&m_PeerAddr, &SockAddr, sizeof(m_PeerAddr));
35+ CopyMemory(&m_PeerAddr, &sAddr, sizeof(m_PeerAddr));
3636
37- ConvertSockAddrToNetAddr(&SockAddr, NetAddr);
38- m_SockMsg.pTgtObj->OnSocketConnectMessage(m_SockMsg.dwSocketID, NetAddr);
37+ ConvertSockAddrToNetAddr(&sAddr, NetAddr);
38+ m_SockMsg.pCallback->OnSocketConnectMessage(m_SockMsg.dwSocketID, NetAddr);
3939 }
4040
4141 void CClientSocket::OnReceive(SOCKET hSocket, int nErrorCode)
4242 {
4343 CByteArray data;
44- SOCKADDR SockAddr;
44+ SOCKADDR sAddr;
4545 NETADDR NetAddr;
4646
4747 if (nErrorCode != 0)
@@ -50,13 +50,13 @@
5050 return;
5151 }
5252
53- if (!doGetPeerName(hSocket, &SockAddr) || !doReceive(hSocket, data))
53+ if (!doGetPeerName(hSocket, &sAddr) || !doReceive(hSocket, data))
5454 {
5555 return;
5656 }
5757
58- ConvertSockAddrToNetAddr(&SockAddr, NetAddr);
59- m_SockMsg.pTgtObj->OnSocketReceiveMessage(m_SockMsg.dwSocketID, NetAddr, data);
58+ ConvertSockAddrToNetAddr(&sAddr, NetAddr);
59+ m_SockMsg.pCallback->OnSocketReceiveMessage(m_SockMsg.dwSocketID, NetAddr, data);
6060 }
6161
6262 void CClientSocket::OnSend(SOCKET hSocket, int nErrorCode)
@@ -67,7 +67,7 @@
6767 return;
6868 }
6969
70- m_SockMsg.pTgtObj->OnSocketSendMessage(m_SockMsg.dwSocketID);
70+ m_SockMsg.pCallback->OnSocketSendMessage(m_SockMsg.dwSocketID);
7171 }
7272
7373 void CClientSocket::OnClose(SOCKET hSocket, int nErrorCode)
@@ -82,31 +82,12 @@
8282 }
8383
8484 ConvertSockAddrToNetAddr(&m_PeerAddr, NetAddr);
85- m_SockMsg.pTgtObj->OnSocketCloseMessage(m_SockMsg.dwSocketID, NetAddr);
85+ m_SockMsg.pCallback->OnSocketCloseMessage(m_SockMsg.dwSocketID, NetAddr);
8686 }
8787
8888 BOOL CClientSocket::CreateSocket(SOCKMSG SockMsg)
8989 {
90- if (!IBaseSocket::CreateSocketWindow())
91- {
92- return FALSE;
93- }
94-
95- SetTargetWnd(SockMsg);
96-
97- m_hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
98-
99- if (m_hSocket == INVALID_SOCKET)
100- {
101- TRACE1("***** ERROR: socket(%d) *****\n", GetLastError());
102- m_dwError = GetLastError();
103- return FALSE;
104- }
105-
106- SetSendTimeout(m_dwSendTimeout);
107- SetRecieveTimeout(m_dwReceiveTimeout);
108-
109- return TRUE;
90+ return doCreateSocket(SockMsg, SOCK_STREAM, IPPROTO_TCP);
11091 }
11192
11293 BOOL CClientSocket::Initialize(SOCKMSG SockMsg)
@@ -231,9 +212,9 @@
231212
232213 BOOL CClientSocket::SyncConnect(const LPCSTR lpDstAddr, WORD wPort, int nLength, DWORD dwTimeout)
233214 {
234- SOCKADDR_IN siAddr;
235- MakeSockAddrIN(&siAddr, inet_addr(lpDstAddr), wPort);
236- return SyncConnect((LPSOCKADDR)&siAddr, sizeof(siAddr), dwTimeout);
215+ SOCKADDR_IN sAddrIn;
216+ MakeSockAddrIN(&sAddrIn, inet_addr(lpDstAddr), wPort);
217+ return SyncConnect((LPSOCKADDR)&sAddrIn, sizeof(sAddrIn), dwTimeout);
237218 }
238219
239220 BOOL CClientSocket::AsyncConnect(const LPSOCKADDR lpDstAddr, int nLength)
@@ -259,9 +240,9 @@
259240
260241 BOOL CClientSocket::AsyncConnect(const LPCSTR lpDstAddr, WORD wPort, int nLength)
261242 {
262- SOCKADDR_IN siAddr;
263- MakeSockAddrIN(&siAddr, inet_addr(lpDstAddr), wPort);
264- return AsyncConnect((LPSOCKADDR)&siAddr, sizeof(siAddr));
243+ SOCKADDR_IN sAddrIn;
244+ MakeSockAddrIN(&sAddrIn, inet_addr(lpDstAddr), wPort);
245+ return AsyncConnect((LPSOCKADDR)&sAddrIn, sizeof(sAddrIn));
265246 }
266247
267248 //////////////////////////////////////////////////////////////////////////
\ No newline at end of file
--- SocketX/SocketHelper.cpp (revision 15)
+++ SocketX/SocketHelper.cpp (revision 16)
@@ -25,14 +25,15 @@
2525
2626 lpData = reinterpret_cast<LPBYTE>(static_cast<LPTSTR>(cs.GetBuffer()));
2727 dst.SetSize(cs.GetLength() * sizeof(TCHAR));
28+ dst.FreeExtra();
2829 CopyMemory(dst.GetData(), lpData, dst.GetSize());
2930 cs.ReleaseBuffer();
30- dst.FreeExtra();
3131 }
3232
3333 void CSocketHelper::Serialize(CByteArray &dst, const LPVOID src, DWORD dwSize)
3434 {
3535 dst.SetSize(dwSize);
36+ dst.FreeExtra();
3637 CopyMemory(dst.GetData(), src, dwSize);
3738 }
3839
--- WinCS/PluginTransferDlg.h (revision 15)
+++ WinCS/PluginTransferDlg.h (revision 16)
@@ -18,7 +18,7 @@
1818 void SetPlugin(const CString &cs) { m_xEditPlugin.SetWindowText(cs); }
1919 void SetSendToSlave(WORD wNodeID, DWORD dwAddress);
2020 void SetProgress(int nPoint);
21- void SetTargetWnd(CWnd *wnd) { m_pTgtWnd = wnd; }
21+ void SetCallback(CWnd *wnd) { m_pTgtWnd = wnd; }
2222 void GetSendList(IntList &list) { list.Copy(m_SendList); }
2323 BOOL IsSending() { return m_fSending; }
2424
--- WinCS/WinCSDlg.cpp (revision 15)
+++ WinCS/WinCSDlg.cpp (revision 16)
@@ -1359,7 +1359,7 @@
13591359 m_dlgTransfer.SetPluginList(m_PluginList.list);
13601360 m_PluginList.cs.Unlock();
13611361
1362- m_dlgTransfer.SetTargetWnd(this);
1362+ m_dlgTransfer.SetCallback(this);
13631363 m_dlgTransfer.DoModal();
13641364 }
13651365 else
@@ -1476,7 +1476,7 @@
14761476 {
14771477 CByteArray data;
14781478 UDP_DATA uReply;
1479- SOCKADDR SockAddr;
1479+ SOCKADDR sAddr;
14801480 int nLenSA = sizeof(SOCKADDR);
14811481
14821482 ZeroMemory(&uReply, sizeof(uReply));
@@ -1495,8 +1495,8 @@
14951495 uReply.wSrcNodeID = m_wcsStatus.wNodeID;
14961496 uReply.wDstNodeID = WCS_DEFAULT_NODE_ID;
14971497 CopyMemory(data.GetData(), &uReply, data.GetSize());
1498- MakeSockAddr(&SockAddr, NetAddr.dwAddress, NetAddr.wPort);
1499- m_pServerPeerSocket->SendTo(data, &SockAddr, nLenSA);
1498+ MakeSockAddr(&sAddr, NetAddr.dwAddress, NetAddr.wPort);
1499+ m_pServerPeerSocket->SendTo(data, &sAddr, nLenSA);
15001500 break;
15011501 }
15021502 }
@@ -2045,18 +2045,18 @@
20452045 return wNodeID;
20462046 }
20472047
2048-DWORD CWinCSDlg::GetSAddrBySockAddr(const LPSOCKADDR lpSockAddr)
2048+DWORD CWinCSDlg::GetSAddrBySockAddr(const LPSOCKADDR lpsAddr)
20492049 {
2050- SOCKADDR_IN siAddr;
2051- CopyMemory(&siAddr, lpSockAddr, sizeof(siAddr));
2052- return siAddr.sin_addr.s_addr;
2050+ SOCKADDR_IN sAddrIn;
2051+ CopyMemory(&sAddrIn, lpsAddr, sizeof(sAddrIn));
2052+ return sAddrIn.sin_addr.s_addr;
20532053 }
20542054
2055-WORD CWinCSDlg::GetPortBySockAddr(const LPSOCKADDR lpSockAddr)
2055+WORD CWinCSDlg::GetPortBySockAddr(const LPSOCKADDR lpsAddr)
20562056 {
2057- SOCKADDR_IN siAddr;
2058- CopyMemory(&siAddr, lpSockAddr, sizeof(siAddr));
2059- return ntohs(siAddr.sin_port);
2057+ SOCKADDR_IN sAddrIn;
2058+ CopyMemory(&sAddrIn, lpsAddr, sizeof(sAddrIn));
2059+ return ntohs(sAddrIn.sin_port);
20602060 }
20612061
20622062 //////////////////////////////////////////////////////////////////////////
@@ -2445,16 +2445,16 @@
24452445
24462446 BOOL CWinCSDlg::StartMaster()
24472447 {
2448- SOCKADDR_IN siAddr;
2448+ SOCKADDR_IN sAddrIn;
24492449 LOCALNET net;
24502450 SOCKMSG SockMsg;
24512451 CString cs, csIP;
24522452 int nLenSA = sizeof(SOCKADDR);
24532453
2454- if (SearchMaster((LPSOCKADDR)&siAddr, &nLenSA))
2454+ if (SearchMaster((LPSOCKADDR)&sAddrIn, &nLenSA))
24552455 {
24562456 cs.LoadString(IDS_WCS_ERROR_MASTER_DUPLICATED);
2457- csIP.Format(_T("\r\nIP: %s"), DwToIPAddress(siAddr.sin_addr.s_addr));
2457+ csIP.Format(_T("\r\nIP: %s"), DwToIPAddress(sAddrIn.sin_addr.s_addr));
24582458 cs += csIP;
24592459 AfxMessageBox(cs);
24602460 return FALSE;
@@ -2484,7 +2484,7 @@
24842484 return FALSE;
24852485 }
24862486
2487- SockMsg.pTgtObj = this;
2487+ SockMsg.pCallback = this;
24882488 SockMsg.dwSocketID = WCS_SOCKID_STREAM_SERVER;
24892489
24902490 if (!m_pServerSocket->Initialize(SockMsg, m_wcsStatus.wTCPPort, m_wcsStatus.dwLocalAddress))
@@ -2512,7 +2512,7 @@
25122512
25132513 BOOL CWinCSDlg::StartSlave()
25142514 {
2515- SOCKADDR_IN siAddr;
2515+ SOCKADDR_IN sAddrIn;
25162516 LOCALNET net;
25172517 SOCKMSG SockMsg;
25182518 CString cs, csIP;
@@ -2520,7 +2520,7 @@
25202520
25212521 if (m_wcsStatus.fDynamic)
25222522 {
2523- if (!SearchMaster((LPSOCKADDR)&siAddr, &nLenSA))
2523+ if (!SearchMaster((LPSOCKADDR)&sAddrIn, &nLenSA))
25242524 {
25252525 // Master can't discover the network.
25262526 cs.LoadString(IDS_WCS_ERROR_MASTER_DISCOVERY);
@@ -2529,15 +2529,15 @@
25292529 }
25302530 else
25312531 {
2532- siAddr.sin_family = AF_INET;
2533- siAddr.sin_port = htons(m_wcsStatus.wTCPPort);
2532+ sAddrIn.sin_family = AF_INET;
2533+ sAddrIn.sin_port = htons(m_wcsStatus.wTCPPort);
25342534 }
25352535 }
25362536 else
25372537 {
2538- siAddr.sin_family = AF_INET;
2539- siAddr.sin_port = htons(m_wcsStatus.wTCPPort);
2540- siAddr.sin_addr.s_addr = m_wcsStatus.dwMasterAddress;
2538+ sAddrIn.sin_family = AF_INET;
2539+ sAddrIn.sin_port = htons(m_wcsStatus.wTCPPort);
2540+ sAddrIn.sin_addr.s_addr = m_wcsStatus.dwMasterAddress;
25412541 }
25422542
25432543 // ClientSocket initialize
@@ -2551,7 +2551,7 @@
25512551 return FALSE;
25522552 }
25532553
2554- SockMsg.pTgtObj = this;
2554+ SockMsg.pCallback = this;
25552555 SockMsg.dwSocketID = WCS_SOCKID_STREAM_CLIENT;
25562556
25572557 if (!m_pClientSocket->Initialize(SockMsg))
@@ -2559,13 +2559,13 @@
25592559 return FALSE;
25602560 }
25612561
2562- if (!ConnectMaster((LPSOCKADDR)&siAddr))
2562+ if (!ConnectMaster((LPSOCKADDR)&sAddrIn))
25632563 {
25642564 m_pClientBcastSocket->CloseSocket();
25652565 m_pClientSocket->CloseSocket();
25662566
25672567 cs.LoadString(IDS_WCS_ERROR_MASTER_CONNECT);
2568- csIP.Format(_T("\r\nIP: %s"), DwToIPAddress(siAddr.sin_addr.s_addr));
2568+ csIP.Format(_T("\r\nIP: %s"), DwToIPAddress(sAddrIn.sin_addr.s_addr));
25692569 cs += csIP;
25702570 AfxMessageBox(cs);
25712571 return FALSE;
@@ -2593,7 +2593,7 @@
25932593 return FALSE;
25942594 }
25952595
2596- m_wcsStatus.dwMasterAddress = siAddr.sin_addr.s_addr;
2596+ m_wcsStatus.dwMasterAddress = sAddrIn.sin_addr.s_addr;
25972597 net.dwAddress = m_wcsStatus.dwLocalAddress;
25982598 net.dwMask = m_wcsStatus.dwMaskAddress;
25992599 net.dwNet = (net.dwAddress & net.dwMask);
@@ -2655,7 +2655,7 @@
26552655 return FALSE;
26562656 }
26572657
2658- SockMsg.pTgtObj = this;
2658+ SockMsg.pCallback = this;
26592659 SockMsg.dwSocketID = WCS_SOCKID_PEER_CLIENT;
26602660
26612661 if (!m_pClientBcastSocket->Initialize(SockMsg, m_wcsStatus.dwLocalAddress, m_wcsStatus.wUDPClientPort))
@@ -2694,7 +2694,7 @@
26942694 return FALSE;
26952695 }
26962696
2697- SockMsg.pTgtObj = this;
2697+ SockMsg.pCallback = this;
26982698 SockMsg.dwSocketID = WCS_SOCKID_PEER_SERVER;
26992699
27002700 if (!m_pServerPeerSocket->Initialize(SockMsg, m_wcsStatus.dwLocalAddress, m_wcsStatus.wUDPServerPort))
@@ -2917,19 +2917,19 @@
29172917 return FALSE;
29182918 }
29192919
2920-void CWinCSDlg::MakeSockAddr(LPSOCKADDR lpSockAddr, DWORD dwAddress, WORD wPort, int nAF)
2920+void CWinCSDlg::MakeSockAddr(LPSOCKADDR lpsAddr, DWORD dwAddress, WORD wPort, int nFamily)
29212921 {
29222922 SOCKADDR_IN addr;
29232923 addr.sin_port = htons(wPort);
2924- addr.sin_family = nAF;
2924+ addr.sin_family = nFamily;
29252925 addr.sin_addr.s_addr = dwAddress;
2926- CopyMemory(lpSockAddr, &addr, sizeof(SOCKADDR));
2926+ CopyMemory(lpsAddr, &addr, sizeof(SOCKADDR));
29272927 }
29282928
2929-void CWinCSDlg::MakeINetAddr(LPDWORD lpAddress, LPWORD lpPort, const LPSOCKADDR lpSockAddr)
2929+void CWinCSDlg::MakeINetAddr(LPDWORD lpAddress, LPWORD lpPort, const LPSOCKADDR lpsAddr)
29302930 {
29312931 SOCKADDR_IN addr;
2932- CopyMemory(&addr, lpSockAddr, sizeof(addr));
2932+ CopyMemory(&addr, lpsAddr, sizeof(addr));
29332933 *lpAddress = addr.sin_addr.s_addr;
29342934 *lpPort = ntohs(addr.sin_port);
29352935 }
@@ -2976,7 +2976,7 @@
29762976 SaveSettings(_T("Retry"), m_wcsStatus.wRetry);
29772977 }
29782978
2979-BOOL CWinCSDlg::SearchMaster(LPSOCKADDR lpSockAddr, int *lpSockAddrLen)
2979+BOOL CWinCSDlg::SearchMaster(LPSOCKADDR lpsAddr, int *lpsAddrLen)
29802980 {
29812981 CByteArray snd, rcv;
29822982 UDP_DATA uData;
@@ -2995,7 +2995,7 @@
29952995 return FALSE;
29962996 }
29972997
2998- if (!m_pClientBcastSocket->ReceiveFrom(rcv, lpSockAddr, lpSockAddrLen))
2998+ if (!m_pClientBcastSocket->ReceiveFrom(rcv, lpsAddr, lpsAddrLen))
29992999 {
30003000 return FALSE;
30013001 }
--- WinCS/WinCSDlg.h (revision 15)
+++ WinCS/WinCSDlg.h (revision 16)
@@ -19,7 +19,7 @@
1919 CDialog,
2020 CStringConvert,
2121 CWcsAPI,
22- ISocketMessage
22+ ISocketCallback
2323 {
2424 public:
2525 CWinCSDlg(CWnd* pParent = NULL);
@@ -122,8 +122,8 @@
122122 WORD SearchNodeID(DWORD dwAddress, WORD wPort);
123123 int SearchNodeListIndex(WORD wNodeID);
124124
125- DWORD GetSAddrBySockAddr(const LPSOCKADDR lpSockAddr);
126- WORD GetPortBySockAddr(const LPSOCKADDR lpSockAddr);
125+ DWORD GetSAddrBySockAddr(const LPSOCKADDR lpsAddr);
126+ WORD GetPortBySockAddr(const LPSOCKADDR lpsAddr);
127127
128128 int SearchPluginIndex(WORD wPluginID);
129129 void SetWcsStatus();
@@ -131,8 +131,8 @@
131131 void SaveWcsSettings();
132132 void OutputNodeData();
133133 void EnableToolBarBtn(int nCtlID, BOOL fEnable);
134- void MakeSockAddr(LPSOCKADDR lpSockAddr, DWORD dwAddress, WORD wPort, int nAF = AF_INET);
135- void MakeINetAddr(LPDWORD lpAddress, LPWORD lpPort, const LPSOCKADDR lpSockAddr);
134+ void MakeSockAddr(LPSOCKADDR lpsAddr, DWORD dwAddress, WORD wPort, int nFamily = AF_INET);
135+ void MakeINetAddr(LPDWORD lpAddress, LPWORD lpPort, const LPSOCKADDR lpsAddr);
136136 void FreePlugin(BOOL fRefresh = TRUE);
137137 BOOL LoadPlugin();
138138 BOOL LoadExcutionPlugin(const CString &csFilePath);
@@ -142,7 +142,7 @@
142142 BOOL ServerPeerSocketInitialize();
143143 BOOL StartMaster();
144144 BOOL StartSlave();
145- BOOL SearchMaster(LPSOCKADDR lpSockAddr, int *lpSockAddrLen);
145+ BOOL SearchMaster(LPSOCKADDR lpsAddr, int *lpsAddrLen);
146146 BOOL ConnectMaster(const LPSOCKADDR lpMasterAddr);
147147 BOOL CreateToolBar(LPTBITEM lpTbItem, SIZE size, UINT nBtnNum);
148148 BOOL SendAckToMaster(WORD wMsg, DWORD dwOption = 0);
Show on old repository browser