THRIFT-5012 Centralize configuration aspects into a commonly used configuration object [ci skip]
Client: Delphi
Patch: Jens Geyer
This closes #1955
diff --git a/lib/delphi/src/Thrift.Transport.Pipes.pas b/lib/delphi/src/Thrift.Transport.Pipes.pas
index b602b64..635a841 100644
--- a/lib/delphi/src/Thrift.Transport.Pipes.pas
+++ b/lib/delphi/src/Thrift.Transport.Pipes.pas
@@ -29,6 +29,7 @@
{$ELSE}
Winapi.Windows, System.SysUtils, System.Math, Winapi.AccCtrl, Winapi.AclAPI, System.SyncObjs,
{$ENDIF}
+ Thrift.Configuration,
Thrift.Transport,
Thrift.Utils,
Thrift.Stream;
@@ -53,7 +54,6 @@
//procedure Open; override; - see derived classes
procedure Close; override;
procedure Flush; override;
- procedure CheckReadBytesAvailable( const value : Integer); override;
function ReadDirect( const pBuf : Pointer; const buflen : Integer; offset: Integer; count: Integer): Integer; overload;
function ReadOverlapped( const pBuf : Pointer; const buflen : Integer; offset: Integer; count: Integer): Integer; overload;
@@ -65,7 +65,9 @@
public
constructor Create( aEnableOverlapped : Boolean;
const aTimeOut : DWORD = DEFAULT_THRIFT_TIMEOUT;
- const aOpenTimeOut : DWORD = DEFAULT_THRIFT_PIPE_OPEN_TIMEOUT);
+ const aOpenTimeOut : DWORD = DEFAULT_THRIFT_PIPE_OPEN_TIMEOUT
+ ); reintroduce; overload;
+
destructor Destroy; override;
end;
@@ -85,7 +87,8 @@
const aShareMode: DWORD = 0;
const aSecurityAttributes: PSecurityAttributes = nil;
const aTimeOut : DWORD = DEFAULT_THRIFT_TIMEOUT;
- const aOpenTimeOut : DWORD = DEFAULT_THRIFT_PIPE_OPEN_TIMEOUT); overload;
+ const aOpenTimeOut : DWORD = DEFAULT_THRIFT_PIPE_OPEN_TIMEOUT
+ ); reintroduce; overload;
end;
@@ -99,7 +102,9 @@
public
constructor Create( const aPipeHandle : THandle;
const aOwnsHandle, aEnableOverlapped : Boolean;
- const aTimeOut : DWORD = DEFAULT_THRIFT_TIMEOUT); overload;
+ const aTimeOut : DWORD = DEFAULT_THRIFT_TIMEOUT
+ ); reintroduce; overload;
+
destructor Destroy; override;
end;
@@ -113,7 +118,7 @@
TPipeTransportBase = class( TStreamTransportImpl, IPipeTransport)
- public
+ strict protected
// ITransport
function GetIsOpen: Boolean; override;
procedure Open; override;
@@ -127,27 +132,32 @@
constructor Create( const aPipe : THandle;
const aOwnsHandle : Boolean;
const aTimeOut : DWORD;
- const aTransportCtl : ITransportControl); overload;
+ const aConfig : IThriftConfiguration = nil
+ ); reintroduce; overload;
constructor Create( const aPipeName : string;
const aShareMode: DWORD = 0;
const aSecurityAttributes: PSecurityAttributes = nil;
const aTimeOut : DWORD = DEFAULT_THRIFT_TIMEOUT;
const aOpenTimeOut : DWORD = DEFAULT_THRIFT_PIPE_OPEN_TIMEOUT;
- const aTransportCtl : ITransportControl = nil); overload;
+ const aConfig : IThriftConfiguration = nil
+ ); reintroduce; overload;
end;
TNamedPipeTransportServerEndImpl = class( TNamedPipeTransportClientEndImpl)
strict private
FHandle : THandle;
- public
+ strict protected
// ITransport
procedure Close; override;
+ public
constructor Create( const aPipe : THandle;
const aOwnsHandle : Boolean;
const aTimeOut : DWORD = DEFAULT_THRIFT_TIMEOUT;
- const aTransportCtl : ITransportControl = nil); reintroduce;
+ const aConfig : IThriftConfiguration = nil
+ ); reintroduce; overload;
+
end;
@@ -157,7 +167,8 @@
constructor Create( const aPipeRead, aPipeWrite : THandle;
const aOwnsHandles : Boolean;
const aTimeOut : DWORD = DEFAULT_THRIFT_TIMEOUT;
- const aTransportCtl : ITransportControl = nil); overload;
+ const aConfig : IThriftConfiguration = nil
+ ); reintroduce; overload;
end;
@@ -187,7 +198,7 @@
procedure InternalClose; virtual; abstract;
function QueryStopServer : Boolean;
public
- constructor Create;
+ constructor Create( const aConfig : IThriftConfiguration);
destructor Destroy; override;
procedure Listen; override;
procedure Close; override;
@@ -221,7 +232,10 @@
procedure InternalClose; override;
public
- constructor Create(aBufsize : Cardinal = 4096; aTimeOut : DWORD = DEFAULT_THRIFT_TIMEOUT);
+ constructor Create( const aBufsize : Cardinal = 4096;
+ const aTimeOut : DWORD = DEFAULT_THRIFT_TIMEOUT;
+ const aConfig : IThriftConfiguration = nil
+ ); reintroduce; overload;
end;
@@ -245,9 +259,12 @@
procedure InternalClose; override;
public
- constructor Create( aPipename : string; aBufsize : Cardinal = 4096;
- aMaxConns : Cardinal = PIPE_UNLIMITED_INSTANCES;
- aTimeOut : Cardinal = INFINITE);
+ constructor Create( const aPipename : string;
+ const aBufsize : Cardinal = 4096;
+ const aMaxConns : Cardinal = PIPE_UNLIMITED_INSTANCES;
+ const aTimeOut : Cardinal = INFINITE;
+ const aConfig : IThriftConfiguration = nil
+ ); reintroduce; overload;
end;
@@ -278,15 +295,14 @@
{ TPipeStreamBase }
-constructor TPipeStreamBase.Create( aEnableOverlapped : Boolean;
- const aTimeOut, aOpenTimeOut : DWORD);
+constructor TPipeStreamBase.Create( aEnableOverlapped : Boolean; const aTimeOut, aOpenTimeOut : DWORD);
begin
inherited Create;
- ASSERT( aTimeout > 0); // aOpenTimeout may be 0
FPipe := INVALID_HANDLE_VALUE;
FTimeout := aTimeOut;
FOpenTimeOut := aOpenTimeOut;
FOverlapped := aEnableOverlapped;
+ ASSERT( FTimeout > 0); // FOpenTimeout may be 0
end;
@@ -318,12 +334,6 @@
end;
-procedure TPipeStreamBase.CheckReadBytesAvailable( const value : Integer);
-begin
- // can't tell how much we can suck out of the pipe
-end;
-
-
procedure TPipeStreamBase.Write( const pBuf : Pointer; offset, count : Integer);
begin
if FOverlapped
@@ -538,7 +548,7 @@
const aSecurityAttributes: PSecurityAttributes;
const aTimeOut, aOpenTimeOut : DWORD);
begin
- inherited Create( aEnableOverlapped, aTimeout, aOpenTimeOut);
+ inherited Create( aEnableOverlapped, aTimeOut, aOpenTimeOut);
FPipeName := aPipeName;
FShareMode := aShareMode;
@@ -601,7 +611,7 @@
const aOwnsHandle, aEnableOverlapped : Boolean;
const aTimeOut : DWORD);
begin
- inherited Create( aEnableOverlapped, aTimeOut);
+ inherited Create( aEnableOverlapped, aTimeout, aTimeout);
if aOwnsHandle
then FSrcHandle := aPipeHandle
@@ -655,13 +665,14 @@
{ TNamedPipeTransportClientEndImpl }
-constructor TNamedPipeTransportClientEndImpl.Create( const aPipeName : string; const aShareMode: DWORD;
+constructor TNamedPipeTransportClientEndImpl.Create( const aPipeName : string;
+ const aShareMode: DWORD;
const aSecurityAttributes: PSecurityAttributes;
const aTimeOut, aOpenTimeOut : DWORD;
- const aTransportCtl : ITransportControl);
+ const aConfig : IThriftConfiguration);
// Named pipe constructor
begin
- inherited Create( nil, nil, aTransportCtl);
+ inherited Create( nil, nil, aConfig);
FInputStream := TNamedPipeStreamImpl.Create( aPipeName, TRUE, aShareMode, aSecurityAttributes, aTimeOut, aOpenTimeOut);
FOutputStream := FInputStream; // true for named pipes
end;
@@ -670,11 +681,11 @@
constructor TNamedPipeTransportClientEndImpl.Create( const aPipe : THandle;
const aOwnsHandle : Boolean;
const aTimeOut : DWORD;
- const aTransportCtl : ITransportControl);
+ const aConfig : IThriftConfiguration);
// Named pipe constructor
begin
- inherited Create( nil, nil, aTransportCtl);
- FInputStream := THandlePipeStreamImpl.Create( aPipe, TRUE, aOwnsHandle, aTimeOut);
+ inherited Create( nil, nil, aConfig);
+ FInputStream := THandlePipeStreamImpl.Create( aPipe, aOwnsHandle, TRUE, aTimeOut);
FOutputStream := FInputStream; // true for named pipes
end;
@@ -685,11 +696,11 @@
constructor TNamedPipeTransportServerEndImpl.Create( const aPipe : THandle;
const aOwnsHandle : Boolean;
const aTimeOut : DWORD;
- const aTransportCtl : ITransportControl);
+ const aConfig : IThriftConfiguration);
// Named pipe constructor
begin
FHandle := DuplicatePipeHandle( aPipe);
- inherited Create( aPipe, aOwnsHandle, aTimeOut, aTransportCtl);
+ inherited Create( aPipe, aOwnsHandle, aTimeout, aConfig);
end;
@@ -709,22 +720,22 @@
constructor TAnonymousPipeTransportImpl.Create( const aPipeRead, aPipeWrite : THandle;
const aOwnsHandles : Boolean;
const aTimeOut : DWORD;
- const aTransportCtl : ITransportControl);
+ const aConfig : IThriftConfiguration);
// Anonymous pipe constructor
begin
- inherited Create( nil, nil, aTransportCtl);
+ inherited Create( nil, nil, aConfig);
// overlapped is not supported with AnonPipes, see MSDN
- FInputStream := THandlePipeStreamImpl.Create( aPipeRead, aOwnsHandles, FALSE, aTimeOut);
- FOutputStream := THandlePipeStreamImpl.Create( aPipeWrite, aOwnsHandles, FALSE, aTimeOut);
+ FInputStream := THandlePipeStreamImpl.Create( aPipeRead, aOwnsHandles, FALSE, aTimeout);
+ FOutputStream := THandlePipeStreamImpl.Create( aPipeWrite, aOwnsHandles, FALSE, aTimeout);
end;
{ TPipeServerTransportBase }
-constructor TPipeServerTransportBase.Create;
+constructor TPipeServerTransportBase.Create( const aConfig : IThriftConfiguration);
begin
- inherited Create;
+ inherited Create( aConfig);
FStopServer := TEvent.Create(nil,TRUE,FALSE,''); // manual reset
end;
@@ -761,11 +772,12 @@
{ TAnonymousPipeServerTransportImpl }
-
-constructor TAnonymousPipeServerTransportImpl.Create(aBufsize : Cardinal; aTimeOut : DWORD);
+constructor TAnonymousPipeServerTransportImpl.Create( const aBufsize : Cardinal;
+ const aTimeOut : DWORD;
+ const aConfig : IThriftConfiguration);
// Anonymous pipe CTOR
begin
- inherited Create;
+ inherited Create(aConfig);
FBufsize := aBufSize;
FReadHandle := INVALID_HANDLE_VALUE;
FWriteHandle := INVALID_HANDLE_VALUE;
@@ -794,7 +806,7 @@
then raise TTransportExceptionNotOpen.Create('TServerPipe unable to initiate pipe communication');
// create the transport impl
- result := TAnonymousPipeTransportImpl.Create( FReadHandle, FWriteHandle, FALSE, FTimeOut);
+ result := TAnonymousPipeTransportImpl.Create( FReadHandle, FWriteHandle, FALSE, FTimeOut, Configuration);
end;
@@ -872,17 +884,19 @@
{ TNamedPipeServerTransportImpl }
-constructor TNamedPipeServerTransportImpl.Create( aPipename : string; aBufsize, aMaxConns, aTimeOut : Cardinal);
+constructor TNamedPipeServerTransportImpl.Create( const aPipename : string;
+ const aBufsize, aMaxConns, aTimeOut : Cardinal;
+ const aConfig : IThriftConfiguration);
// Named Pipe CTOR
begin
- inherited Create;
- ASSERT( aTimeout > 0);
+ inherited Create( aConfig);
FPipeName := aPipename;
FBufsize := aBufSize;
FMaxConns := Max( 1, Min( PIPE_UNLIMITED_INSTANCES, aMaxConns));
FHandle := INVALID_HANDLE_VALUE;
FTimeout := aTimeOut;
FConnected := FALSE;
+ ASSERT( FTimeout > 0);
if Copy(FPipeName,1,2) <> '\\'
then FPipeName := '\\.\pipe\' + FPipeName; // assume localhost
@@ -951,7 +965,7 @@
hPipe := THandle( InterlockedExchangePointer( Pointer(FHandle), Pointer(INVALID_HANDLE_VALUE)));
try
FConnected := FALSE;
- result := TNamedPipeTransportServerEndImpl.Create( hPipe, TRUE, FTimeout);
+ result := TNamedPipeTransportServerEndImpl.Create( hPipe, TRUE, FTimeout, Configuration);
except
ClosePipeHandle(hPipe);
raise;