X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/e27ef2c6aab3a2a8051314bd37bb3b2386775f36..9e8179457b49de0ee52ab40192a88971fc3c01e6:/lsocket.pas?ds=inline

diff --git a/lsocket.pas b/lsocket.pas
index a7c6164..642ec9a 100755
--- a/lsocket.pas
+++ b/lsocket.pas
@@ -101,6 +101,9 @@ type
       proto:ansistring;
       udp,dgram:boolean;
       listenqueue:integer;
+
+      onconnecttryip:procedure(sender:tobject; const ip:tbinip) of object;
+
       {$ifdef secondlistener}
       secondlistener:tlsocket;
       lastsessionfromsecond:boolean;
@@ -131,6 +134,15 @@ type
 
       //this one has to be kept public for now because lcorewsaasyncselect calls it
       procedure connectionfailedhandler(error:word);
+
+      {public in tlasio, and can't be private in both places, so should be public here. 
+      fixes delphi warning --beware}
+      {$ifdef win32}
+        procedure myfdclose(fd : integer); override;
+        function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; override;
+        function myfdread(fd: LongInt;var buf;size: LongInt):LongInt; override;
+      {$endif}
+
     private
       {$ifdef ipv6}
         isv6socket : boolean; //identifies if the socket is v6, set by bindsocket
@@ -139,11 +151,6 @@ type
 
       procedure connecttimeouthandler(sender:tobject);
       procedure connectsuccesshandler;
-      {$ifdef win32}
-        procedure myfdclose(fd : integer); override;
-        function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; override;
-        function myfdread(fd: LongInt;var buf;size: LongInt):LongInt; override;
-      {$endif}
     end;
     tsocket=longint; // for compatibility with twsocket
 
@@ -193,9 +200,12 @@ end;
 procedure tlsocket.realconnect;
 var
   a,b:integer;
+  iptemp:tbinip;
 begin
+  iptemp := biniplist_get(biniplist,currentip);
   //writeln('trying to connect to ',ipbintostr(biniplist_get(biniplist,currentip)),'#',port);
-  makeinaddrv(biniplist_get(biniplist,currentip),port,inaddr);
+  if assigned(onconnecttryip) then onconnecttryip(self,iptemp);
+  makeinaddrv(iptemp,port,inaddr);
   inc(currentip);
   if (currentip >= biniplist_getcount(biniplist)) then trymoreips := false;
 
@@ -278,9 +288,6 @@ end;
 
 
 procedure tlsocket.connect;
-var
-  a:integer;
-  ip:tbinip;
 begin
   if state <> wsclosed then close;
   //prevtime := 0;
@@ -293,7 +300,7 @@ begin
   if not assigned(connecttimeout) then begin
     connecttimeout := tltimer.create(self);
     connecttimeout.ontimer := connecttimeouthandler;
-    connecttimeout.interval := 2500;
+    connecttimeout.interval := 5000;
     connecttimeout.enabled := false;
   end;
   realconnect;
@@ -339,7 +346,6 @@ end;
 
 procedure tlsocket.bindsocket;
 var
-  a:integer;
   inAddrtemp:TInetSockAddrV;
   inAddrtempx:{$ifdef win32}winsock.TSockaddr{$else}TInetSockAddrV{$endif} absolute inaddrtemp;
   inaddrtempsize:integer;
@@ -374,7 +380,9 @@ end;
 
 procedure tlsocket.listen;
 var
+  {$ifndef win32}
   yes,no:longint;
+  {$endif}
   socktype:integer;
   biniptemp:tbinip;
   origaddr:thostname;
@@ -421,10 +429,11 @@ begin
   state := wsclosed; // then set this back as it was an undesired side effect of dup
 
   try
-    yes := $01010101;  {Copied this from existing code. Value is empiric,
-                    but works. (yes=true<>0) }
-    no := 0;
     {$ifndef win32}
+      yes := $01010101;  {Copied this from existing code. Value is empiric,
+                    but works. (yes=true<>0) }
+      no := 0;
+
       if SetSocketOptions(fdhandlein, SOL_SOCKET, SO_REUSEADDR,yes,sizeof(yes))=-1 then begin
         raise ESocketException.create('unable to set SO_REUSEADDR socket option');
       end;
@@ -546,7 +555,7 @@ begin
   if result > absoloutemaxs then begin
     myfdclose(result);
     a := result;
-    result := -1;
+{    result := -1;}
     raise esocketexception.create('file discriptor out of range: '+inttostr(a));
   end;
 end;