THRIFT-2415 Named pipes server performance & message mode

Patch: Jens Geyer
diff --git a/lib/delphi/src/Thrift.Utils.pas b/lib/delphi/src/Thrift.Utils.pas
index 72c0dc1..ec8190c 100644
--- a/lib/delphi/src/Thrift.Utils.pas
+++ b/lib/delphi/src/Thrift.Utils.pas
@@ -21,10 +21,40 @@
 

 interface

 

+uses

+  Classes, Windows, SysUtils, SyncObjs;

+

+type

+  IOverlappedHelper = interface

+    ['{A1832EFA-2E02-4884-8F09-F0A0277157FA}']

+    function Overlapped : TOverlapped;

+    function OverlappedPtr : POverlapped;

+    function WaitHandle : THandle;

+    function WaitFor(dwTimeout: DWORD) : DWORD;

+  end;

+

+  TOverlappedHelperImpl = class( TInterfacedObject, IOverlappedHelper)

+  strict protected

+    FOverlapped : TOverlapped;

+    FEvent      : TEvent;

+

+    // IOverlappedHelper

+    function Overlapped : TOverlapped;

+    function OverlappedPtr : POverlapped;

+    function WaitHandle : THandle;

+    function WaitFor(dwTimeout: DWORD) : DWORD;

+  public

+    constructor Create;

+    destructor Destroy;  override;

+  end;

+

+

+

 function IfValue(B: Boolean; const TrueValue, FalseValue: WideString): string;

 

 implementation

 

+

 function IfValue(B: Boolean; const TrueValue, FalseValue: WideString): string;

 begin

   if B then

@@ -33,4 +63,56 @@
     Result := FalseValue;

 end;

 

+

+{ TOverlappedHelperImpl }

+

+constructor TOverlappedHelperImpl.Create;

+begin

+  inherited Create;

+  FillChar( FOverlapped, SizeOf(FOverlapped), 0);

+  FEvent := TEvent.Create( nil, TRUE, FALSE, '');  // always ManualReset, see MSDN

+  FOverlapped.hEvent := FEvent.Handle;

+end;

+

+

+

+destructor TOverlappedHelperImpl.Destroy;

+begin

+  try

+    FOverlapped.hEvent := 0;

+    FreeAndNil( FEvent);

+

+  finally

+    inherited Destroy;

+  end;

+

+end;

+

+

+function TOverlappedHelperImpl.Overlapped : TOverlapped;

+begin

+  result := FOverlapped;

+end;

+

+

+function TOverlappedHelperImpl.OverlappedPtr : POverlapped;

+begin

+  result := @FOverlapped;

+end;

+

+

+function TOverlappedHelperImpl.WaitHandle : THandle;

+begin

+  result := FOverlapped.hEvent;

+end;

+

+

+function TOverlappedHelperImpl.WaitFor( dwTimeout : DWORD) : DWORD;

+begin

+  result := WaitForSingleObject( FOverlapped.hEvent, dwTimeout);

+end;

+

+

+

+

 end.