From: beware Date: Fri, 24 Feb 2012 02:57:51 +0000 (+0000) Subject: dnssync lookup retry to listen in case port is in use X-Git-Url: http://www.lcore.org/git/lcore.git/commitdiff_plain/2579cad7a973072619a7fc17ff6af9cc75264972 dnssync lookup retry to listen in case port is in use git-svn-id: file:///svnroot/lcore/trunk@113 b1de8a11-f9be-4011-bde0-cc7ace90066a --- diff --git a/dnssync.pas b/dnssync.pas index 60af580..79ace01 100644 --- a/dnssync.pas +++ b/dnssync.pas @@ -132,7 +132,8 @@ procedure setupsocket; var inAddrtemp : TInetSockAddrV; biniptemp:tbinip; - a:integer; + a,retrycount:integer; + bindresult:boolean; begin biniptemp := getcurrentsystemnameserverbin(id); //must get the DNS server here so we know to init v4 or v6 @@ -141,11 +142,16 @@ begin for a := 0 to numsockused-1 do begin - makeinaddrv(biniptemp,inttostr( 1024 + randominteger(65536 - 1024) ),inaddrtemp); + retrycount := 5; + repeat + makeinaddrv(biniptemp,inttostr( 1024 + randominteger(65536 - 1024) ),inaddrtemp); - fd[a] := Socket(biniptemp.family,SOCK_DGRAM,0); + fd[a] := Socket(biniptemp.family,SOCK_DGRAM,0); + bindresult := {$ifdef win32}Not{$endif} Bind(fd[a],inAddrtemp,inaddrsize(inaddrtemp)); + dec(retrycount); + until (retrycount <= 0) or (bindresult); - If {$ifndef win32}Not{$endif} Bind(fd[a],inAddrtemp,inaddrsize(inaddrtemp)) Then begin + If (not bindresult) Then begin {$ifdef win32} raise Exception.create('unable to bind '+inttostr(WSAGetLastError)); {$else}