//host : THostentry ;\r
\r
//mainthread : boolean ; //for debuggin only\r
- addr:string;\r
- port:string;\r
- localaddr:string;\r
- localport:string;\r
- proto:string;\r
+ addr:thostname;\r
+ port:ansistring;\r
+ localaddr:thostname;\r
+ localport:ansistring;\r
+ proto:ansistring;\r
udp,dgram:boolean;\r
listenqueue:integer;\r
+\r
+ onconnecttryip:procedure(sender:tobject; const ip:tbinip) of object;\r
+\r
{$ifdef secondlistener}\r
secondlistener:tlsocket;\r
lastsessionfromsecond:boolean;\r
\r
procedure handlefdtrigger(readtrigger,writetrigger:boolean); override;\r
function send(data:pointer;len:integer):integer;override;\r
- procedure sendstr(const str : string);override;\r
+ procedure sendstr(const str : tbufferstring);override;\r
function Receive(Buf:Pointer;BufSize:integer):integer; override;\r
function getpeername(var addr:tsockaddrin;addrlen:integer):integer; virtual;\r
procedure getXaddrbin(var binip:tbinip); virtual;\r
procedure getpeeraddrbin(var binip:tbinip); virtual;\r
- function getXaddr:string; virtual;\r
- function getpeeraddr:string; virtual;\r
- function getXport:string; virtual;\r
- function getpeerport:string; virtual;\r
+ function getXaddr:thostname; virtual;\r
+ function getpeeraddr:thostname; virtual;\r
+ function getXport:ansistring; virtual;\r
+ function getpeerport:ansistring; virtual;\r
constructor Create(AOwner: TComponent); override;\r
\r
//this one has to be kept public for now because lcorewsaasyncselect calls it\r
procedure connectionfailedhandler(error:word);\r
+\r
+ {public in tlasio, and can't be private in both places, so should be public here. \r
+ fixes delphi warning --beware}\r
+ {$ifdef win32}\r
+ procedure myfdclose(fd : integer); override;\r
+ function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; override;\r
+ function myfdread(fd: LongInt;var buf;size: LongInt):LongInt; override;\r
+ {$endif}\r
+\r
private\r
{$ifdef ipv6}\r
isv6socket : boolean; //identifies if the socket is v6, set by bindsocket\r
\r
procedure connecttimeouthandler(sender:tobject);\r
procedure connectsuccesshandler;\r
- {$ifdef win32}\r
- procedure myfdclose(fd : integer); override;\r
- function myfdwrite(fd: LongInt;const buf;size: LongInt):LongInt; override;\r
- function myfdread(fd: LongInt;var buf;size: LongInt):LongInt; override;\r
- {$endif}\r
end;\r
tsocket=longint; // for compatibility with twsocket\r
\r
procedure tlsocket.realconnect;\r
var\r
a,b:integer;\r
+ iptemp:tbinip;\r
begin\r
+ iptemp := biniplist_get(biniplist,currentip);\r
//writeln('trying to connect to ',ipbintostr(biniplist_get(biniplist,currentip)),'#',port);\r
- makeinaddrv(biniplist_get(biniplist,currentip),port,inaddr);\r
+ if assigned(onconnecttryip) then onconnecttryip(self,iptemp);\r
+ makeinaddrv(iptemp,port,inaddr);\r
inc(currentip);\r
if (currentip >= biniplist_getcount(biniplist)) then trymoreips := false;\r
\r
\r
\r
procedure tlsocket.connect;\r
-var\r
- a:integer;\r
- ip:tbinip;\r
begin\r
if state <> wsclosed then close;\r
//prevtime := 0;\r
if not assigned(connecttimeout) then begin\r
connecttimeout := tltimer.create(self);\r
connecttimeout.ontimer := connecttimeouthandler;\r
- connecttimeout.interval := 2500;\r
+ connecttimeout.interval := 5000;\r
connecttimeout.enabled := false;\r
end;\r
realconnect;\r
end;\r
\r
-procedure tlsocket.sendstr(const str : string);\r
+procedure tlsocket.sendstr(const str : tbufferstring);\r
begin\r
if dgram then begin\r
send(@str[1],length(str))\r
\r
procedure tlsocket.bindsocket;\r
var\r
- a:integer;\r
inAddrtemp:TInetSockAddrV;\r
inAddrtempx:{$ifdef win32}winsock.TSockaddr{$else}TInetSockAddrV{$endif} absolute inaddrtemp;\r
inaddrtempsize:integer;\r
\r
procedure tlsocket.listen;\r
var\r
+ {$ifndef win32}\r
yes,no:longint;\r
+ {$endif}\r
socktype:integer;\r
biniptemp:tbinip;\r
- origaddr:string;\r
+ origaddr:thostname;\r
begin\r
if state <> wsclosed then close;\r
udp := uppercase(proto) = 'UDP';\r
fdhandlein := socket(biniptemp.family,socktype,0);\r
{$ifdef ipv6}\r
if (addr = '::') and (origaddr = '') and (fdhandlein < 0) then begin\r
- writeln('failed to create an IPV6 socket with error ',socketerror,'. trying to create an IPV4 one instead');\r
+ {writeln('failed to create an IPV6 socket with error ',socketerror,'. trying to create an IPV4 one instead');}\r
addr := '0.0.0.0';\r
fdhandlein := socket(PF_INET,socktype,0);\r
end;\r
state := wsclosed; // then set this back as it was an undesired side effect of dup\r
\r
try\r
- yes := $01010101; {Copied this from existing code. Value is empiric,\r
- but works. (yes=true<>0) }\r
- no := 0;\r
{$ifndef win32}\r
+ yes := $01010101; {Copied this from existing code. Value is empiric,\r
+ but works. (yes=true<>0) }\r
+ no := 0;\r
+\r
if SetSocketOptions(fdhandlein, SOL_SOCKET, SO_REUSEADDR,yes,sizeof(yes))=-1 then begin\r
raise ESocketException.create('unable to set SO_REUSEADDR socket option');\r
end;\r
if result > absoloutemaxs then begin\r
myfdclose(result);\r
a := result;\r
- result := -1;\r
+{ result := -1;}\r
raise esocketexception.create('file discriptor out of range: '+inttostr(a));\r
end;\r
end;\r
converttov4(binip);\r
end;\r
\r
-function tlsocket.getXaddr:string;\r
+function tlsocket.getXaddr:thostname;\r
var\r
biniptemp:tbinip;\r
begin\r
if result = '' then result := 'error';\r
end;\r
\r
-function tlsocket.getpeeraddr:string;\r
+function tlsocket.getpeeraddr:thostname;\r
var\r
biniptemp:tbinip;\r
begin\r
if result = '' then result := 'error';\r
end;\r
\r
-function tlsocket.getXport:string;\r
+function tlsocket.getXport:ansistring;\r
var\r
addr:tinetsockaddrv;\r
i:integer;\r
result := inttostr(htons(addr.InAddr.port));\r
end;\r
\r
-function tlsocket.getpeerport:string;\r
+function tlsocket.getpeerport:ansistring;\r
var\r
addr:tinetsockaddrv;\r
i:integer;\r