interface\r
uses\r
sysutils,\r
- {$ifdef win32}\r
+ {$ifdef mswindows}\r
windows,winsock,\r
{$else}\r
\r
sockets,\r
{$endif}\r
classes,{pgdebugout,}pgtypes,lcore,fd_utils,binipstuff,dnssync;\r
+\r
+{$ifdef ipv6}\r
+const\r
+ v4listendefault:boolean=false;\r
+{$endif}\r
+\r
+\r
type\r
sunB = packed record\r
s_b1, s_b2, s_b3, s_b4: byte;\r
//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
- udp:boolean;\r
+ addr:thostname;\r
+ port:ansistring;\r
+ localaddr:thostname;\r
+ localport:ansistring;\r
+ proto:ansistring;\r
+ udp,dgram:boolean;\r
listenqueue:integer;\r
- procedure connectionfailedhandler(error:word);\r
- procedure connecttimeouthandler(sender:tobject);\r
- procedure connectsuccesshandler;\r
+\r
+ onconnecttryip:procedure(sender:tobject; const ip:tbinip) of object;\r
+\r
+ {$ifdef secondlistener}\r
+ secondlistener:tlsocket;\r
+ lastsessionfromsecond:boolean;\r
+ procedure secondaccepthandler(sender:tobject;error:word);\r
+ procedure internalclose(error:word);override;\r
+ {$endif}\r
function getaddrsize:integer;\r
procedure connect; virtual;\r
procedure realconnect;\r
function accept : longint;\r
function sendto(dest:TInetSockAddrV;destlen:integer;data:pointer;len:integer):integer; virtual;\r
function receivefrom(data:pointer;len:integer;var src:TInetSockAddrV;var srclen:integer):integer; virtual;\r
- //procedure internalclose(error:word);override;\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
- {$ifdef win32}\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 mswindows}\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
+ {$endif}\r
+ procedure taskcallconnectionfailedhandler(wparam,lparam : longint);\r
+\r
+ procedure connecttimeouthandler(sender:tobject);\r
+ procedure connectsuccesshandler;\r
end;\r
tsocket=longint; // for compatibility with twsocket\r
\r
twsocket=tlsocket; {easy}\r
\r
\r
-{!!!function longipdns(s:string):longint;}\r
-\r
-{$ifdef ipv6}\r
-const\r
- v4listendefault:boolean=false;\r
-{$endif}\r
-\r
-\r
const\r
TCP_NODELAY=1;\r
IPPROTO_TCP=6;\r
result := inaddrsize(inaddr);\r
end;\r
\r
+//I used to use the system versions of these from within lsocket (which has\r
+//functions whose name clashes with them) by using sockets.* and but I can't do\r
+//that anymore since in some cases connect is now provided by unixstuff.inc\r
+//hence these wrapper functions --plugwash\r
+{$ifndef mswindows}\r
+ function system_Connect(Sock: LongInt;const Addr;Addrlen: LongInt):Boolean;\r
+ begin\r
+ result := connect(sock,addr,addrlen);\r
+ end;\r
+ function system_SendTo(Sock: LongInt; const Buf;BufLen: LongInt;Flags: LongInt;var Addr;AddrLen: LongInt):LongInt;\r
+ begin\r
+ result := sendto(sock,buf,buflen,flags,addr,addrlen);\r
+ end;\r
+ function system_getpeername(Sock: LongInt;var Addr;var Addrlen: LongInt):LongInt;\r
+ begin\r
+ result := getpeername(sock,addr,addrlen);\r
+ end;\r
+ function system_listen(Sock: LongInt; MaxConnect: LongInt):Boolean;\r
+ begin\r
+ result := listen(sock,maxconnect);\r
+ end;\r
+ function system_Accept(Sock: LongInt;var Addr;var Addrlen: LongInt):LongInt;\r
+ begin\r
+ result := accept(sock,addr,addrlen);\r
+ end;\r
+{$endif}\r
\r
procedure tlsocket.realconnect;\r
var\r
- a:integer;\r
-\r
+ a,b:integer;\r
+ iptemp:tbinip;\r
begin\r
-// writeln('trying to connect to ',ipbintostr(biniplist_get(biniplist,currentip)),'#',port);\r
- makeinaddrv(biniplist_get(biniplist,currentip),port,inaddr);\r
+ iptemp := biniplist_get(biniplist,currentip);\r
+ //writeln('trying to connect to ',ipbintostr(biniplist_get(biniplist,currentip)),'#',port);\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
- udp := uppercase(proto) = 'UDP';\r
- if udp then a := SOCK_DGRAM else a := SOCK_STREAM;\r
- a := Socket(inaddr.inaddr.family,a,0);\r
+\r
+ udp := false;\r
+ if (uppercase(proto) = 'UDP') then begin\r
+ b := IPPROTO_UDP;\r
+ a := SOCK_DGRAM;\r
+ udp := true;\r
+ dgram := true;\r
+ end else if (uppercase(proto) = 'TCP') or (uppercase(proto) = '') then begin\r
+ b := IPPROTO_TCP;\r
+ a := SOCK_STREAM;\r
+ dgram := false;\r
+ end else if (uppercase(proto) = 'ICMP') or (strtointdef(proto,256) < 256) then begin\r
+ b := strtointdef(proto,IPPROTO_ICMP);\r
+ a := SOCK_RAW;\r
+ dgram := true;\r
+ end else begin\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
- lasterror := {$ifdef win32}getlasterror{$else}socketerror{$endif};\r
- raise esocketexception.create('unable to create socket');\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 mswindows}wsagetlasterror{$else}socketerror{$endif},0);\r
+ exit;\r
end;\r
try\r
dup(a);\r
bindsocket;\r
- if udp then begin\r
- {$ifndef win32}\r
+ if dgram then begin\r
+ {$ifndef mswindows}\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
eventcore.wmasterclr(fdhandleout);\r
end else begin\r
state :=wsconnecting;\r
- {$ifdef win32}\r
+ {$ifdef mswindows}\r
//writeln(inaddr.inaddr.port);\r
winsock.Connect(fdhandlein,winsock.psockaddr(@inADDR)^,getaddrsize);\r
{$else}\r
- sockets.Connect(fdhandlein,inADDR,getaddrsize);\r
+ system_Connect(fdhandlein,inADDR,getaddrsize);\r
{$endif}\r
eventcore.rmasterset(fdhandlein,false);\r
eventcore.wmasterset(fdhandleout);\r
realconnect;\r
end;\r
\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
currentip := 0;\r
if not assigned(connecttimeout) then begin\r
connecttimeout := tltimer.create(self);\r
- connecttimeout.Tag := integer(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 udp then begin\r
+ if dgram then begin\r
send(@str[1],length(str))\r
end else begin\r
inherited sendstr(str);\r
\r
function tlsocket.send(data:pointer;len:integer):integer;\r
begin\r
- if udp then begin\r
+ if dgram then begin\r
// writeln('sending to '+ipbintostr(inaddrvtobinip(inaddr)),' ',htons(inaddr.inaddr.port),' ',len,' bytes');\r
result := sendto(inaddr,getaddrsize,data,len);\r
\r
\r
function tlsocket.receive(Buf:Pointer;BufSize:integer):integer;\r
begin\r
- if udp then begin\r
- result := myfdread(self.fdhandlein,buf^,bufsize);\r
+ if dgram then begin\r
+ {$ifdef secondlistener}\r
+ if lastsessionfromsecond then begin\r
+ result := secondlistener.receive(buf,bufsize);\r
+ lastsessionfromsecond := false;\r
+ end else\r
+ {$endif}\r
+ result := myfdread(self.fdhandlein,buf^,bufsize);\r
end else begin\r
result := inherited receive(buf,bufsize);\r
end;\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
+ inAddrtempx:{$ifdef mswindows}winsock.TSockaddr{$else}TInetSockAddrV{$endif} absolute inaddrtemp;\r
inaddrtempsize:integer;\r
begin\r
try\r
localaddr := '0.0.0.0';\r
end;\r
//gethostbyname(localaddr,host);\r
-\r
inaddrtempsize := makeinaddrv(forwardlookup(localaddr,0),localport,inaddrtemp);\r
-\r
- If Bind(fdhandlein,inaddrtempx,inaddrtempsize)<> {$ifdef win32}0{$else}true{$endif} Then begin\r
+ {$ifdef ipv6}\r
+ isv6socket := (inaddrtemp.inaddr.family = AF_INET6);\r
+ {$endif}\r
+ If Bind(fdhandlein,inaddrtempx,inaddrtempsize)<> {$ifdef mswindows}0{$else}true{$endif} Then begin\r
state := wsclosed;\r
- lasterror := {$ifdef win32}getlasterror{$else}socketerror{$endif};\r
- raise ESocketException.create('unable to bind, error '+inttostr(lasterror));\r
+ lasterror := {$ifdef mswindows}getlasterror{$else}socketerror{$endif};\r
+ raise ESocketException.create('unable to bind on address '+localaddr+'#'+localport+', error '+inttostr(lasterror));\r
end;\r
state := wsbound;\r
end;\r
\r
procedure tlsocket.listen;\r
var\r
- yes:longint;\r
+ {$ifndef mswindows}\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
- if udp then socktype := SOCK_DGRAM else socktype := SOCK_STREAM;\r
+ if udp then begin\r
+ socktype := SOCK_DGRAM;\r
+ dgram := true;\r
+ end else socktype := SOCK_STREAM;\r
origaddr := addr;\r
\r
if addr = '' then begin\r
{$ifdef ipv6}\r
+ //writeln('ipv6 is defined');\r
if not v4listendefault then begin\r
+ //writeln('setting addr to ::');\r
addr := '::';\r
end else\r
{$endif}\r
end;\r
if isbiniplist(addr) then biniptemp := biniplist_get(addr,0) else biniptemp := forwardlookup(addr,10);\r
addr := ipbintostr(biniptemp);\r
+ //writeln('after ipbintostr call addr =',addr);\r
+ //writeln('biniptemp.family =',biniptemp.family);\r
+ //writeln('AF_INET6=',AF_INET6);\r
+ //writeln('PF_INET6=',PF_INET6);\r
+ //writeln('AF_INET=',AF_INET);\r
+ //writeln('PF_INET=',PF_INET);\r
+ \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
addr := '0.0.0.0';\r
- fdhandlein := socket(AF_INET,socktype,0);\r
+ biniptemp := ipstrtobinf(addr);\r
+ fdhandlein := socket(PF_INET,socktype,0);\r
end;\r
{$endif}\r
- if fdhandlein = -1 then raise ESocketException.create('unable to create socket');\r
+\r
+ if fdhandlein = -1 then raise ESocketException.create('unable to create socket'{$ifdef mswindows}+' error='+inttostr(wsagetlasterror){$endif});\r
dupnowatch(fdhandlein); // sets up maxs and copies handle to fdhandleout among other things\r
//eventcore.setfdreverse(fdhandlein,self); //already taken care of by dup\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
+ {$ifndef mswindows}\r
+ yes := $01010101; {Copied this from existing code. Value is empiric,\r
but works. (yes=true<>0) }\r
- {$ifndef win32}\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 socket options');\r
+ raise ESocketException.create('unable to set SO_REUSEADDR socket option');\r
end;\r
+ //writeln('addr=',addr);\r
+ //writeln('setting IPV6_V6ONLY option to 0');\r
+ //allow v4 connections on v6 sockets\r
+ if biniptemp.family = af_inet6 then begin\r
+ if SetSocketOptions(fdhandlein, IPPROTO_IPV6,IPV6_V6ONLY,no,sizeof(no))=-1 then begin\r
+ writeln(IPPROTO_IPV6);\r
+ writeln(IPV6_V6ONLY);\r
+ raise ESocketException.create('unable to set IPV6_V6ONLY socket option error='+inttostr(socketerror));\r
+ \r
+ end;\r
+ end;\r
+ {$else}\r
+ SetSockOpt(fdhandlein, SOL_SOCKET, SO_REUSEADDR, 'TRUE', Length('TRUE'));\r
+\r
{$endif}\r
localaddr := addr;\r
localport := port;\r
if not udp then begin\r
{!!! allow custom queue length? default 5}\r
if listenqueue = 0 then listenqueue := 5;\r
- If {$ifdef win32}winsock{$else}sockets{$endif}.Listen(fdhandlein,listenqueue)<>{$ifdef win32}0{$else}true{$endif} Then raise esocketexception.create('unable to listen');\r
+ If {$ifdef mswindows}winsock.listen{$else}system_listen{$endif}(fdhandlein,listenqueue)<>{$ifdef mswindows}0{$else}true{$endif} Then raise\r
+esocketexception.create('unable to listen');\r
state := wsListening;\r
end else begin\r
- {$ifndef win32}\r
+ {$ifndef mswindows}\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
end;\r
+\r
+ {$ifdef secondlistener}\r
+ //listening on ::. try to listen on 0.0.0.0 as well for platforms which don't already do that\r
+ if addr = '::' then begin\r
+ secondlistener := tlsocket.create(nil);\r
+ secondlistener.proto := proto;\r
+ secondlistener.addr := '0.0.0.0';\r
+ secondlistener.port := port;\r
+ if udp then begin\r
+ secondlistener.ondataavailable := secondaccepthandler;\r
+ end else begin\r
+ secondlistener.onsessionAvailable := secondaccepthandler;\r
+ end;\r
+ try\r
+ secondlistener.listen;\r
+ except\r
+ secondlistener.destroy;\r
+ secondlistener := nil;\r
+ end;\r
+ end;\r
+ {$endif}\r
finally\r
if state = wsclosed then begin\r
if fdhandlein >= 0 then begin\r
//writeln('listened on addr '+addr+':'+port+' '+proto+' using socket number ',fdhandlein);\r
end;\r
\r
+{$ifdef secondlistener}\r
+procedure tlsocket.internalclose(error:word);\r
+begin\r
+ if assigned(secondlistener) then begin\r
+ secondlistener.destroy;\r
+ secondlistener := nil;\r
+ end;\r
+ inherited internalclose(error);\r
+end;\r
+\r
+procedure tlsocket.secondaccepthandler;\r
+begin\r
+ lastsessionfromsecond := true;\r
+ if udp then begin\r
+ ondataavailable(self,error);\r
+ end else begin\r
+ if assigned(onsessionavailable) then onsessionavailable(self,error);\r
+ end;\r
+end;\r
+{$endif}\r
+\r
function tlsocket.accept : longint;\r
var\r
FromAddrSize : LongInt; // i don't realy know what to do with these at this\r
FromAddr : TInetSockAddrV; // at this point time will tell :)\r
a:integer;\r
begin\r
+ {$ifdef secondlistener}\r
+ if (lastsessionfromsecond) then begin\r
+ lastsessionfromsecond := false;\r
+ result := secondlistener.accept;\r
+ exit;\r
+ end;\r
+ {$endif}\r
\r
FromAddrSize := Sizeof(FromAddr);\r
- {$ifdef win32}\r
+ {$ifdef mswindows}\r
result := winsock.accept(fdhandlein,@fromaddr,@fromaddrsize);\r
{$else}\r
- result := sockets.accept(fdhandlein,fromaddr,fromaddrsize);\r
+ result := system_accept(fdhandlein,fromaddr,fromaddrsize);\r
{$endif}\r
//now we have accepted one request start monitoring for more again\r
eventcore.rmasterset(fdhandlein,true);\r
\r
if result = -1 then begin\r
- raise esocketexception.create('error '+inttostr({$ifdef win32}getlasterror{$else}socketerror{$endif})+' while accepting');\r
+ raise esocketexception.create('error '+inttostr({$ifdef mswindows}getlasterror{$else}socketerror{$endif})+' while accepting');\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
\r
+\r
function tlsocket.sendto(dest:TInetSockAddrV;destlen:integer;data:pointer;len:integer):integer;\r
var\r
- destx : {$ifdef win32}winsock.TSockAddr{$else}TInetSockAddrV{$endif} absolute dest;\r
+ {$ifdef ipv6}\r
+ realdest : tinetsockaddrv;\r
+ biniptemp : tbinip;\r
+ {$endif}\r
+ destx : {$ifdef mswindows}winsock.pSockAddr{$else}pInetSockAddrV{$endif};\r
+\r
begin\r
- result := {$ifdef win32}winsock{$else}sockets{$endif}.sendto(self.fdhandleout,data^,len,0,destx,destlen);\r
+ {$ifdef secondlistener}\r
+ if assigned(secondlistener) then if (dest.inaddr.family = AF_INET) then begin\r
+ result := secondlistener.sendto(dest,destlen,data,len);\r
+ exit;\r
+ end;\r
+ {$endif}\r
+ {$ifdef ipv6}\r
+ if isv6socket then begin\r
+ biniptemp := inaddrvtobinip(dest);\r
+ converttov6(biniptemp);\r
+ destlen := makeinaddrv(biniptemp,inttostr(ntohs(dest.InAddr.port)),realdest);\r
+ destx := {$ifdef mswindows}winsock.pSockAddr{$else}pInetSockAddrV{$endif}(@realdest)\r
+ end else begin\r
+ destx := {$ifdef mswindows}winsock.pSockAddr{$else}pInetSockAddrV{$endif}(@dest)\r
+ end;\r
+ {$else}\r
+ destx := {$ifdef mswindows}winsock.pSockAddr{$else}pInetSockAddrV{$endif}(@dest);\r
+ {$endif}\r
+\r
+ result := {$ifdef mswindows}winsock.sendto{$else}system_sendto{$endif}(self.fdhandleout,data^,len,0,destx^,destlen);\r
end;\r
\r
+\r
function tlsocket.receivefrom(data:pointer;len:integer;var src:TInetSockAddrV;var srclen:integer):integer;\r
var\r
- srcx : {$ifdef win32}winsock.TSockAddr{$else}TInetSockAddrV{$endif} absolute src;\r
+ tempsrc:TInetSockAddrV;\r
+ tempsrclen:integer;\r
+ srcx : {$ifdef mswindows}winsock.TSockAddr{$else}TInetSockAddrV{$endif} absolute tempsrc;\r
+ biniptemp:tbinip;\r
begin\r
- result := {$ifdef win32}winsock{$else}sockets{$endif}.recvfrom(self.fdhandlein,data^,len,0,srcx,srclen);\r
+ {$ifdef secondlistener}\r
+ if assigned(secondlistener) then if lastsessionfromsecond then begin\r
+ lastsessionfromsecond := false;\r
+ result := secondlistener.receivefrom(data,len,src,srclen);\r
+ exit;\r
+ end;\r
+ {$endif}\r
+ tempsrclen := sizeof(tempsrc);\r
+ result := recvfrom(self.fdhandlein,data^,len,0,srcx,tempsrclen);\r
+\r
+ {$ifdef ipv6}\r
+ biniptemp := inaddrvtobinip(tempsrc);\r
+ if needconverttov4(biniptemp) then begin\r
+ converttov4(biniptemp);\r
+ tempsrclen := makeinaddrv(biniptemp,inttostr(ntohs(tempsrc.InAddr.port)),tempsrc);\r
+ end;\r
+ {$endif}\r
+\r
+ move(tempsrc,src,srclen);\r
+ srclen := tempsrclen;\r
+end;\r
+\r
+procedure tlsocket.taskcallconnectionfailedhandler(wparam,lparam : longint);\r
+begin\r
+ connectionfailedhandler(wparam);\r
end;\r
\r
procedure tlsocket.connectionfailedhandler(error:word);\r
eventcore.rmasterclr(fdhandlein);\r
if assigned(onsessionAvailable) then onsessionAvailable(self,0);\r
end;\r
- if udp and readtrigger then begin\r
+ if dgram and readtrigger then begin\r
if assigned(ondataAvailable) then ondataAvailable(self,0);\r
{!!!test}\r
exit;\r
//connectread := true;\r
recvq.add(@tempbuf,numread);\r
end else begin\r
- connectionfailedhandler({$ifdef win32}wsagetlasterror{$else}linuxerror{$endif});\r
+ connectionfailedhandler({$ifdef mswindows}wsagetlasterror{$else}linuxerror{$endif});\r
exit;\r
end;\r
// if things went well here we are now in the state wsconnected with data sitting in our receive buffer\r
end;\r
\r
\r
+\r
function tlsocket.getpeername(var addr:tsockaddrin;addrlen:integer):integer;\r
var\r
- addrx : {$ifdef win32}winsock.tsockaddr{$else}tsockaddrin{$endif} absolute addr;\r
+ addrx : {$ifdef mswindows}winsock.tsockaddr{$else}tsockaddrin{$endif} absolute addr;\r
begin\r
- result := {$ifdef win32}winsock{$else}sockets{$endif}.getpeername(self.fdhandlein,addrx,addrlen);\r
+ result := {$ifdef mswindows}winsock.getpeername{$else}system_getpeername{$endif}(self.fdhandlein,addrx,addrlen);\r
end;\r
\r
procedure tlsocket.getxaddrbin(var binip:tbinip);\r
i := sizeof(addr);\r
fillchar(addr,sizeof(addr),0);\r
\r
- {$ifdef win32}\r
+ {$ifdef mswindows}\r
winsock.getsockname(self.fdhandlein,psockaddr(@addr)^,i);\r
{$else}\r
- sockets.getsocketname(self.fdhandlein,addr,i);\r
+ getsocketname(self.fdhandlein,addr,i);\r
{$endif}\r
- binip.family := addr.inaddr.family;\r
- {$ifdef ipv6}\r
- if addr.inaddr6.sin6_family = AF_INET6 then begin\r
- binip.ip6 := addr.inaddr6.sin6_addr;\r
- end else\r
- {$endif}\r
- begin\r
- binip.ip := addr.inaddr.addr;\r
- end;\r
+ binip := inaddrvtobinip(addr);\r
converttov4(binip);\r
end;\r
\r
begin\r
i := sizeof(addr);\r
fillchar(addr,sizeof(addr),0);\r
- {$ifdef win32}\r
+ {$ifdef mswindows}\r
winsock.getpeername(self.fdhandlein,psockaddr(@addr)^,i);\r
{$else}\r
- sockets.getpeername(self.fdhandlein,addr,i);\r
+ system_getpeername(self.fdhandlein,addr,i);\r
{$endif}\r
\r
- binip.family := addr.inaddr.family;\r
- {$ifdef ipv6}\r
- if addr.inaddr6.sin6_family = AF_INET6 then begin\r
- binip.ip6 := addr.inaddr6.sin6_addr;\r
- end else\r
- {$endif}\r
- begin\r
- binip.ip := addr.inaddr.addr;\r
- end;\r
+ binip := inaddrvtobinip(addr);\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
begin\r
i := sizeof(addr);\r
- {$ifdef win32}\r
+ {$ifdef mswindows}\r
winsock.getsockname(self.fdhandlein,psockaddrin(@addr)^,i);\r
\r
{$else}\r
- sockets.getsocketname(self.fdhandlein,addr,i);\r
+ getsocketname(self.fdhandlein,addr,i);\r
\r
{$endif}\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
begin\r
i := sizeof(addr);\r
- {$ifdef win32}\r
+ {$ifdef mswindows}\r
winsock.getpeername(self.fdhandlein,psockaddrin(@addr)^,i);\r
\r
{$else}\r
- sockets.getpeername(self.fdhandlein,addr,i);\r
+ system_getpeername(self.fdhandlein,addr,i);\r
\r
{$endif}\r
result := inttostr(htons(addr.InAddr.port));\r
end;\r
\r
-{$ifdef win32}\r
+{$ifdef mswindows}\r
procedure tlsocket.myfdclose(fd : integer);\r
begin\r
closesocket(fd);\r