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 win32}\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
//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
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.enabled := false;\r
\r
procedure tlsocket.listen;\r
var\r
- yes:longint;\r
+ yes,no:longint;\r
socktype:integer;\r
biniptemp:tbinip;\r
origaddr:string;\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
if SetSocketOptions(fdhandlein, SOL_SOCKET, SO_REUSEADDR,yes,sizeof(yes))=-1 then begin\r
raise ESocketException.create('unable to set socket options');\r
end;\r
+ if SetSocketOptions(fdhandlein, IPPROTO_IPV6,IPV6_V6ONLY,no,sizeof(no))=-1 then begin\r
+ raise ESocketException.create('unable to set socket options');\r
+ end;\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\r
+ If {$ifdef win32}winsock.listen{$else}system_listen{$endif}(fdhandlein,listenqueue)<>{$ifdef win32}0{$else}true{$endif} Then raise\r
esocketexception.create('unable to listen');\r
state := wsListening;\r
end else begin\r
{$ifdef win32}\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
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
exit;\r
end;\r
{$endif}\r
- result := {$ifdef win32}winsock{$else}sockets{$endif}.sendto(self.fdhandleout,data^,len,0,destx,destlen);\r
+ result := {$ifdef win32}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
tempsrc:TInetSockAddrV;\r
end;\r
{$endif}\r
tempsrclen := sizeof(tempsrc);\r
- result := {$ifdef win32}winsock{$else}sockets{$endif}.recvfrom(self.fdhandlein,data^,len,0,srcx,tempsrclen);\r
+ result := recvfrom(self.fdhandlein,data^,len,0,srcx,tempsrclen);\r
\r
{$ifdef ipv6}\r
biniptemp := inaddrvtobinip(tempsrc);\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
begin\r
- result := {$ifdef win32}winsock{$else}sockets{$endif}.getpeername(self.fdhandlein,addrx,addrlen);\r
+ result := {$ifdef win32}winsock.getpeername{$else}system_getpeername{$endif}(self.fdhandlein,addrx,addrlen);\r
end;\r
\r
procedure tlsocket.getxaddrbin(var binip:tbinip);\r
{$ifdef win32}\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 := inaddrvtobinip(addr);\r
converttov4(binip);\r
{$ifdef win32}\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 := inaddrvtobinip(addr);\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
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