- result := longip(s);\r
- if result = 0 then begin\r
- if gethostbyname(s,host) then begin;\r
- result := htonl(Longint(Host.Addr));\r
- end;\r
- //writeln(inttohex(longint(host.addr),8))\r
+ raise ESocketException.create('unrecognised protocol');\r
+ end;\r
+\r
+ a := Socket(inaddr.inaddr.family,a,b);\r
+ //writeln(ord(inaddr.inaddr.family));\r
+ if a = -1 then begin\r
+ //unable to create socket, fire an error event (better to use an error event\r
+ //to avoid poor interaction with multilistener stuff.\r
+ //a socket value of -2 is a special value to say there is no socket but\r
+ //we want internalclose to act as if there was\r
+ fdhandlein := -2;\r
+ fdhandleout := -2;\r
+ tltask.create(taskcallconnectionfailedhandler,self,{$ifdef win32}wsagetlasterror{$else}socketerror{$endif},0);\r
+ exit;\r
+ end;\r
+ try\r
+ dup(a);\r
+ bindsocket;\r
+ if dgram then begin\r
+ {$ifndef win32}\r
+ SetSocketOptions(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));\r
+ {$else}\r
+ SetSockOpt(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));\r
+ {$endif}\r
+ state := wsconnected;\r
+ if assigned(onsessionconnected) then onsessionconnected(self,0);\r
+\r
+ eventcore.rmasterset(fdhandlein,false);\r
+ eventcore.wmasterclr(fdhandleout);\r
+ end else begin\r
+ state :=wsconnecting;\r
+ {$ifdef win32}\r
+ //writeln(inaddr.inaddr.port);\r
+ winsock.Connect(fdhandlein,winsock.psockaddr(@inADDR)^,getaddrsize);\r
+ {$else}\r
+ system_Connect(fdhandlein,inADDR,getaddrsize);\r
+ {$endif}\r
+ eventcore.rmasterset(fdhandlein,false);\r
+ eventcore.wmasterset(fdhandleout);\r
+ if trymoreips then connecttimeout.enabled := true;\r