You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2016/04/19 23:36:58 UTC

[2/3] thrift git commit: THRIFT-3790 Fix Delphi named pipe client to use timeout even when pipe doesn't yet exist Client: Delphi Patch: Kyle Johnson & Jens Geyer

THRIFT-3790 Fix Delphi named pipe client to use timeout even when pipe doesn't yet exist
Client: Delphi
Patch: Kyle Johnson & Jens Geyer


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/b89b5b9d
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/b89b5b9d
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/b89b5b9d

Branch: refs/heads/master
Commit: b89b5b9d03f322043f70c552b1a56b5fdb57ef84
Parents: 5988f48
Author: Jens Geyer <je...@apache.org>
Authored: Tue Apr 19 23:09:41 2016 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Tue Apr 19 23:36:27 2016 +0200

----------------------------------------------------------------------
 lib/delphi/src/Thrift.Transport.Pipes.pas | 27 ++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/b89b5b9d/lib/delphi/src/Thrift.Transport.Pipes.pas
----------------------------------------------------------------------
diff --git a/lib/delphi/src/Thrift.Transport.Pipes.pas b/lib/delphi/src/Thrift.Transport.Pipes.pas
index 37adf0f..cb89a95 100644
--- a/lib/delphi/src/Thrift.Transport.Pipes.pas
+++ b/lib/delphi/src/Thrift.Transport.Pipes.pas
@@ -494,15 +494,34 @@ end;
 
 procedure TNamedPipeStreamImpl.Open;
 var hPipe    : THandle;
+    retries, timeout, dwErr : DWORD;
+const INTERVAL = 10; // ms
 begin
   if IsOpen then Exit;
 
-  // open that thingy
+  retries := Max( 1, Round( 1.0 * FTimeOut / INTERVAL));
+  timeout := FTimeOut;
+
+  // if the server hasn't gotten to the point where the pipe has been created, at least wait the timeout
+  // According to MSDN, if no instances of the specified named pipe exist, the WaitNamedPipe function
+  // returns IMMEDIATELY, regardless of the time-out value.
+  while not WaitNamedPipe( PChar(FPipeName), INTERVAL) do begin
+    dwErr := GetLastError;
+    if dwErr <> ERROR_FILE_NOT_FOUND
+    then raise TTransportException.Create( TTransportException.TExceptionType.NotOpen,
+                                           'Unable to open pipe, '+SysErrorMessage(dwErr));
+
+    if timeout <> INFINITE then begin
+      if (retries > 0)
+      then Dec(retries)
+      else raise TTransportException.Create( TTransportException.TExceptionType.NotOpen,
+                                             'Unable to open pipe, timed out');
+    end;
 
-  if not WaitNamedPipe( PChar(FPipeName), FTimeout)
-  then raise TTransportException.Create( TTransportException.TExceptionType.NotOpen,
-                                         'Unable to open pipe, '+SysErrorMessage(GetLastError));
+    Sleep(INTERVAL)
+  end;
 
+  // open that thingy
   hPipe := CreateFile( PChar( FPipeName),
                        GENERIC_READ or GENERIC_WRITE,
                        FShareMode,        // sharing