blcksock.pas - Added TBlockSocket.ConnectionTimeout
git-svn-id: https://svn.code.sf.net/p/synalist/code/trunk@160 7c85be65-684b-0410-a082-b2ed4fbef004
This commit is contained in:
parent
faf75a79d3
commit
7723c48a4d
23
blcksock.pas
23
blcksock.pas
@ -1,5 +1,5 @@
|
|||||||
{==============================================================================|
|
{==============================================================================|
|
||||||
| Project : Ararat Synapse | 009.008.005 |
|
| Project : Ararat Synapse | 009.009.000 |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
| Content: Library base |
|
| Content: Library base |
|
||||||
|==============================================================================|
|
|==============================================================================|
|
||||||
@ -314,6 +314,7 @@ type
|
|||||||
FStopFlag: Boolean;
|
FStopFlag: Boolean;
|
||||||
FNonblockSendTimeout: Integer;
|
FNonblockSendTimeout: Integer;
|
||||||
FHeartbeatRate: integer;
|
FHeartbeatRate: integer;
|
||||||
|
FConnectionTimeout: integer;
|
||||||
{$IFNDEF ONCEWINSOCK}
|
{$IFNDEF ONCEWINSOCK}
|
||||||
FWsaDataOnce: TWSADATA;
|
FWsaDataOnce: TWSADATA;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -831,6 +832,10 @@ type
|
|||||||
{:Timeout for data sending by non-blocking socket mode.}
|
{:Timeout for data sending by non-blocking socket mode.}
|
||||||
property NonblockSendTimeout: Integer read FNonblockSendTimeout Write FNonblockSendTimeout;
|
property NonblockSendTimeout: Integer read FNonblockSendTimeout Write FNonblockSendTimeout;
|
||||||
|
|
||||||
|
{:Timeout for @link(Connect) call. Default value 0 means default system timeout.
|
||||||
|
Non-zero value means timeout in millisecond.}
|
||||||
|
property ConnectionTimeout: Integer read FConnectionTimeout write FConnectionTimeout;
|
||||||
|
|
||||||
{:This event is called by various reasons. It is good for monitoring socket,
|
{:This event is called by various reasons. It is good for monitoring socket,
|
||||||
create gauges for data transfers, etc.}
|
create gauges for data transfers, etc.}
|
||||||
property OnStatus: THookSocketStatus read FOnStatus write FOnStatus;
|
property OnStatus: THookSocketStatus read FOnStatus write FOnStatus;
|
||||||
@ -1547,6 +1552,7 @@ begin
|
|||||||
FStopFlag := False;
|
FStopFlag := False;
|
||||||
FNonblockSendTimeout := 15000;
|
FNonblockSendTimeout := 15000;
|
||||||
FHeartbeatRate := 0;
|
FHeartbeatRate := 0;
|
||||||
|
FConnectionTimeout := 0;
|
||||||
FOwner := nil;
|
FOwner := nil;
|
||||||
{$IFNDEF ONCEWINSOCK}
|
{$IFNDEF ONCEWINSOCK}
|
||||||
if Stub = '' then
|
if Stub = '' then
|
||||||
@ -1914,13 +1920,26 @@ end;
|
|||||||
procedure TBlockSocket.Connect(IP, Port: string);
|
procedure TBlockSocket.Connect(IP, Port: string);
|
||||||
var
|
var
|
||||||
Sin: TVarSin;
|
Sin: TVarSin;
|
||||||
|
b: boolean;
|
||||||
begin
|
begin
|
||||||
SetSin(Sin, IP, Port);
|
SetSin(Sin, IP, Port);
|
||||||
if FLastError = 0 then
|
if FLastError = 0 then
|
||||||
begin
|
begin
|
||||||
if FSocket = INVALID_SOCKET then
|
if FSocket = INVALID_SOCKET then
|
||||||
InternalCreateSocket(Sin);
|
InternalCreateSocket(Sin);
|
||||||
SockCheck(synsock.Connect(FSocket, Sin));
|
if FConnectionTimeout > 0 then
|
||||||
|
begin
|
||||||
|
// connect in non-blocking mode
|
||||||
|
b := NonBlockMode;
|
||||||
|
NonBlockMode := true;
|
||||||
|
SockCheck(synsock.Connect(FSocket, Sin));
|
||||||
|
if (FLastError = WSAEINPROGRESS) OR (FLastError = WSAEWOULDBLOCK) then
|
||||||
|
if not CanWrite(FConnectionTimeout) then
|
||||||
|
FLastError := WSAETIMEDOUT;
|
||||||
|
NonBlockMode := b;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
SockCheck(synsock.Connect(FSocket, Sin));
|
||||||
if FLastError = 0 then
|
if FLastError = 0 then
|
||||||
GetSins;
|
GetSins;
|
||||||
FBuffer := '';
|
FBuffer := '';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user