![]() |
Connect() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
| Public Function |
Declared in: TCPSocket.h |
Declaration
virtual BOOL Connect(
unsigned short usSourcePort,
IP aDestinationAddress,
unsigned short usDestinationPort);
DescriptionConnect to a remote system Choose the source address explicitly usSourcePort - OS will allocate source port
Function Body
try
{
//Quit if not ok
if (!CheckSocketValid())
return FALSE;
///Special handling for raw sockets
if (IsRaw())
return SendRaw(usSourcePort,
aDestinationAddress,
usDestinationPort,
NULL,
0,
TCPFlag_SYN);
else
{
//Set async notification
int iResult;
//Create the address
sockaddr_in aSrc;
//Set to 0
memset(&aSrc,
0,
sizeof(aSrc));
aSrc.sin_family=AF_INET;
aSrc.sin_addr.s_addr=aDestinationAddress;
aSrc.sin_port=htons(usDestinationPort);
//Connect
iResult=connect(GetHandle(),
(sockaddr*)&aSrc,
sizeof(aSrc));
//Did we have a blocked error
BOOL bBlocked;
bBlocked=FALSE;
//Check the result
if (iResult==GetErrorCode())
{
//Check is it blocking error so we can ignore
if (WSAGetLastError()!=WSAEWOULDBLOCK)
SetLastError("Connect");
else
{
//Indicate it's blocked error
bBlocked=TRUE;
iResult=!GetErrorCode();
}
}
else
//Report the error
SetLastError("Connect");
if (iResult!=GetErrorCode())
{
//Check if we are a sync socket
if (!IsAsyncClass())
SetConnectionStatus(TRUE);
//Save where we are connected
SetConnectedTo(aSrc);
}
//Done
if (!bBlocked)
return iResult!=GetErrorCode();
else
return FALSE;
}
}
ERROR_HANDLER_RETURN("Connect",FALSE)
See Also
This web site was generated
using Surveyor V4.50.811.1. Click
here
for more information. |
Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003. |