Jump to content
Hafedh TRIMECHE

Check port in use exception

Recommended Posts

This code raised an EIdNotASocket exception.
 

function PortInUse(const APort:Integer;const Address:string='localhost'):Boolean;
var
  LTcpClient : TIdTCPClient;
begin
  LTcpClient := TIdTCPClient.Create(nil);
  try
    try
      LTcpClient.Host           := Address;
      LTcpClient.Port           := APort;
      LTcpClient.ConnectTimeout := 200;
      LTcpClient.Connect;
      Result := True;
    except
      Result := False;
    end;
  finally
    freeAndNil(LTcpClient);
  end;
end;

 

 
===============================================================================
Application Name      : DSFInterface.exe
Memory manager        : FastMM
Compiler Version      : Delphi: 34
Indy Version          : 10.6.2.0
Zeos Version          : 7.2.14-release
Report Unique ID      : {9E064C95-AA3D-4658-BF59-FFE405865C5C}
Start Time            : 2021-08-05 11:45:18.843
Exception Time        : 2021-08-05 11:46:20.381
Application up time   :  1 minute 1 second 538 milliseconds
===============================================================================
Processor             : LENOVO, LNVNB161216, AMD64 Family 21 Model 112 Stepping 0, AMD A4-9125 RADEON R3, 4 COMPUTE CORES 2C+2G   , 2.3 GHz
System                : Windows 10 (Version 10.0, Build 19043, 64-bit Edition)
Display               : 1680x1050 pixels, 96 bpp
Total Physical Memory :   6.608 GB
Free Physical Memory  :   2.137 GB
Max used Memory       :   201.594 MB
===============================================================================
Exception class       : EIdNotASocket
Socket Error # 10038
Socket operation on non-socket.
Exception address     : 000000000095CAD1
Exception trigger     : ExceptionAcquired
-------------------------------------------------------------------------------
Module                : JclDebug
Command Line          : D:\Applications-Folder\DSFInterface\DSFInterface.exe
Procedure             : JclDebug.TJclStackInfoList.Create
Unit                  : JclDebug.pas
Line                  : 5509
-------------------------------------------------------------------------------
[00000000009075B1] JclDebug.TJclStackInfoList.Create (Line 5509, "JclDebug.pas" + 34) + $0
[00000000009070D2] JclDebug.JclCreateStackList (Line 5351, "JclDebug.pas" + 1) + $3E
[0000000000906FB4] JclDebug.DoExceptionStackTrace (Line 5292, "JclDebug.pas" + 20) + $1F
[0000000000909E0C] JclDebug.DoExceptNotify (Line 6741, "JclDebug.pas" + 7) + $0
[00000000008F54C2] JclHookExcept.TNotifierItem.DoNotify (Line 272, "JclHookExcept.pas" + 5) + $1D
[00000000008F5793] JclHookExcept.DoExceptNotify (Line 347, "JclHookExcept.pas" + 21) + $2B
[00000000008F5890] JclHookExcept.HookedRaiseException (Line 381, "JclHookExcept.pas" + 14) + $0
[0000000000410EE3] System.@RaiseAtExcept (Line 22019, "System.pas" + 32) + $0
[0000000000410F01] System.@RaiseExcept (Line 22108, "System.pas" + 2) + $0
[000000000095CAD1] IdStack.TIdStack.RaiseSocketError (Line 976, "IdStack.pas" + 54) + $0
[000000000095CA61] IdStack.TIdStack.RaiseLastSocketError (Line 900, "IdStack.pas" + 2) + $0
[000000000095C98E] IdStack.TIdStack.CheckForSocketError (Line 875, "IdStack.pas" + 4) + $0
[00000000009568E2] IdStackWindows.TIdStackWindows.Connect (Line 2072, "IdStackWindows.pas" + 21) + $0
[000000000099BE3B] IdSocketHandle.TIdSocketHandle.Connect (Line 296, "IdSocketHandle.pas" + 2) + $0
[00000000009A1763] IdIOHandlerStack.TIdConnectThread.Execute (Line 488, "IdIOHandlerStack.pas" + 2) + $11
[000000000054E4A3] System.Classes.ThreadProc (Line 15573, "System.Classes.pas" + 18) + $E
[0000000000411A1D] System.ThreadWrapper (Line 25380, "System.pas" + 9) + $7
[00007FFC6CC67034] BaseThreadInitThunk + $14
[00007FFC6CE02651] RtlUserThreadStart + $21

 

Share this post


Link to post
4 hours ago, Hafedh TRIMECHE said:

This code raised an EIdNotASocket exception.

Under normal conditions, that particular exception class should not be getting raised in this code, as a connect attempt should never report a WSAENOTSOCK error.  On the other hand, 200ms is a fairly short timeout, and Indy does use a worker thread internally to implement a timed connect, so it is likely that the timeout is elapsing and closing the socket before the thread even has a chance to attempt to connect.  However, in that scenario, the code that is calling TIdTCPClient.Connect() would receive an EIdConnectTimeout exception instead of an EIdNotASocket, The thread would raise EIdNotASocket internally and swallow it, but your JCL debugging does not appear to be taking that into account.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×