dnssync lookup retry to listen in case port is in use
authorbeware <beware@bircd.org>
Fri, 24 Feb 2012 02:57:51 +0000 (02:57 +0000)
committerbeware <beware@bircd.org>
Fri, 24 Feb 2012 02:57:51 +0000 (02:57 +0000)
git-svn-id: file:///svnroot/lcore/trunk@113 b1de8a11-f9be-4011-bde0-cc7ace90066a

dnssync.pas

index 60af58082e36a7d075a67fe41d5009683e4f9873..79ace01ca056e4d63312b7a2e807a307f539fb33 100644 (file)
@@ -132,7 +132,8 @@ procedure setupsocket;
 var\r
   inAddrtemp : TInetSockAddrV;\r
   biniptemp:tbinip;\r
-  a:integer;\r
+  a,retrycount:integer;\r
+  bindresult:boolean;\r
 begin\r
   biniptemp := getcurrentsystemnameserverbin(id);\r
   //must get the DNS server here so we know to init v4 or v6\r
@@ -141,11 +142,16 @@ begin
 \r
 \r
   for a := 0 to numsockused-1 do begin\r
-    makeinaddrv(biniptemp,inttostr( 1024 + randominteger(65536 - 1024) ),inaddrtemp);\r
+    retrycount := 5;\r
+    repeat\r
+      makeinaddrv(biniptemp,inttostr( 1024 + randominteger(65536 - 1024) ),inaddrtemp);\r
 \r
-    fd[a] := Socket(biniptemp.family,SOCK_DGRAM,0);\r
+      fd[a] := Socket(biniptemp.family,SOCK_DGRAM,0);\r
+      bindresult := {$ifdef win32}Not{$endif} Bind(fd[a],inAddrtemp,inaddrsize(inaddrtemp));\r
+      dec(retrycount);\r
+    until (retrycount <= 0) or (bindresult);\r
 \r
-    If {$ifndef win32}Not{$endif} Bind(fd[a],inAddrtemp,inaddrsize(inaddrtemp)) Then begin\r
+    If (not bindresult) Then begin\r
       {$ifdef win32}\r
         raise Exception.create('unable to bind '+inttostr(WSAGetLastError));\r
       {$else}\r