/[lcore]/trunk/lsocket.pas
ViewVC logotype

Diff of /trunk/lsocket.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 25 by zipplet, Fri Jan 23 00:36:13 2009 UTC revision 32 by plugwash, Sat Jan 31 00:58:54 2009 UTC
# Line 107  Line 107 
107        procedure secondaccepthandler(sender:tobject;error:word);        procedure secondaccepthandler(sender:tobject;error:word);
108        procedure internalclose(error:word);override;        procedure internalclose(error:word);override;
109        {$endif}        {$endif}
       procedure connectionfailedhandler(error:word);  
       procedure connecttimeouthandler(sender:tobject);  
       procedure connectsuccesshandler;  
110        function getaddrsize:integer;        function getaddrsize:integer;
111        procedure connect; virtual;        procedure connect; virtual;
112        procedure realconnect;        procedure realconnect;
# Line 131  Line 128 
128        function getXport:string; virtual;        function getXport:string; virtual;
129        function getpeerport:string; virtual;        function getpeerport:string; virtual;
130        constructor Create(AOwner: TComponent); override;        constructor Create(AOwner: TComponent); override;
131    
132          //this one has to be kept public for now because lcorewsaasyncselect calls it
133          procedure connectionfailedhandler(error:word);
134        private
135          procedure taskcallconnectionfailedhandler(wparam,lparam : longint);
136    
137          procedure connecttimeouthandler(sender:tobject);
138          procedure connectsuccesshandler;
139        {$ifdef win32}        {$ifdef win32}
140          procedure myfdclose(fd : integer); override;          procedure myfdclose(fd : integer); override;
141          function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; override;          function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; override;
# Line 171  Line 176 
176      a := SOCK_DGRAM;      a := SOCK_DGRAM;
177      udp := true;      udp := true;
178      dgram := true;      dgram := true;
179    end else if (uppercase(proto) = 'TCP') then begin    end else if (uppercase(proto) = 'TCP') or (uppercase(proto) = '') then begin
180      b := IPPROTO_TCP;      b := IPPROTO_TCP;
181      a := SOCK_STREAM;      a := SOCK_STREAM;
182      dgram := false;      dgram := false;
183    end else begin    end else if (uppercase(proto) = 'ICMP') or (strtointdef(proto,256) < 256) then begin
184        //note: ICMP support doesn't seem to work yet
185      b := strtointdef(proto,IPPROTO_ICMP);      b := strtointdef(proto,IPPROTO_ICMP);
186      a := SOCK_RAW;      a := SOCK_RAW;
187      dgram := true;      dgram := true;
188      end else begin
189        raise ESocketException.create('unrecognised protocol');
190    end;    end;
191    
192    a := Socket(inaddr.inaddr.family,a,b);    a := Socket(inaddr.inaddr.family,a,b);
193    //writeln(ord(inaddr.inaddr.family));    //writeln(ord(inaddr.inaddr.family));
194    if a = -1 then begin    if a = -1 then begin
195      lasterror := {$ifdef win32}getlasterror{$else}socketerror{$endif};      //unable to create socket, fire an error event (better to use an error event
196      raise esocketexception.create('unable to create socket');      //to avoid poor interaction with multilistener stuff.
197        //a socket value of -2 is a special value to say there is no socket but
198        //we want internalclose to act as if there was
199        fdhandlein := -2;
200        fdhandleout := -2;
201        tltask.create(taskcallconnectionfailedhandler,self,{$ifdef win32}wsagetlasterror{$else}socketerror{$endif},0);
202        exit;
203    end;    end;
204    try    try
205      dup(a);      dup(a);
# Line 359  Line 373 
373    end;    end;
374    {$endif}    {$endif}
375    
376    if fdhandlein = -1 then raise ESocketException.create('unable to create socket');    if fdhandlein = -1 then raise ESocketException.create('unable to create socket'{$ifdef win32}+' error='+inttostr(wsagetlasterror){$endif});
377    dupnowatch(fdhandlein); // sets up maxs and copies handle to fdhandleout among other things    dupnowatch(fdhandlein); // sets up maxs and copies handle to fdhandleout among other things
378    //eventcore.setfdreverse(fdhandlein,self); //already taken care of by dup    //eventcore.setfdreverse(fdhandlein,self); //already taken care of by dup
379    state := wsclosed; // then set this back as it was an undesired side effect of dup    state := wsclosed; // then set this back as it was an undesired side effect of dup
# Line 525  Line 539 
539    srclen := tempsrclen;    srclen := tempsrclen;
540  end;  end;
541    
542    procedure tlsocket.taskcallconnectionfailedhandler(wparam,lparam : longint);
543    begin
544      connectionfailedhandler(wparam);
545    end;
546    
547  procedure tlsocket.connectionfailedhandler(error:word);  procedure tlsocket.connectionfailedhandler(error:word);
548  begin  begin
549     if trymoreips then begin     if trymoreips then begin

Legend:
Removed from v.25  
changed lines
  Added in v.32

No admin address has been configured">No admin address has been configured
ViewVC Help
Powered by ViewVC 1.1.22