From 2d2676149292e4e388bb102a41a3d64349ac88ed Mon Sep 17 00:00:00 2001 From: plugwash Date: Thu, 12 Nov 2009 20:47:41 +0000 Subject: [PATCH] add support for fpc 2.2.4rc1 git-svn-id: file:///svnroot/lcore/trunk@60 b1de8a11-f9be-4011-bde0-cc7ace90066a --- btime.pas | 2 +- lcore.pas | 2 +- lcorernd.pas | 2 +- lcoreselect.pas | 2 +- lloopback.pas | 2 +- lmessages.pas | 2 +- lsignal.pas | 2 +- lsocket.pas | 52 ++++++++++++++++++++++++++++++++++++++--------- ltimevalstuff.pas | 2 +- unitfork.pas | 2 +- unixstuff.inc | 37 +++++++++++++++++++++++++++++++++ 11 files changed, 88 insertions(+), 19 deletions(-) diff --git a/btime.pas b/btime.pas index 4636a9b..9bb9550 100755 --- a/btime.pas +++ b/btime.pas @@ -96,7 +96,7 @@ uses {$ifdef VER1_0} linux, {$else} - baseunix,unix,unixutil, {needed for 2.0.2} + baseunix,unix,unixutil,sockets, {unixutil and sockets needed by unixstuff.inc on some compiler versions} {$endif} {$else} windows,unitsettc,mmsystem, diff --git a/lcore.pas b/lcore.pas index 9061e45..bb9eb8d 100755 --- a/lcore.pas +++ b/lcore.pas @@ -26,7 +26,7 @@ interface {$ifdef VER1_0} linux, {$else} - baseunix,unix,unixutil, + baseunix,unix,unixutil,sockets, {$endif} fd_utils, {$endif} diff --git a/lcorernd.pas b/lcorernd.pas index 64759e8..673860f 100644 --- a/lcorernd.pas +++ b/lcorernd.pas @@ -137,7 +137,7 @@ uses {$ifdef ver1_0} linux, {$else} - baseunix,unix,unixutil, + baseunix,unix,unixutil,sockets, {$endif} {$endif} fastmd5,sysutils; diff --git a/lcoreselect.pas b/lcoreselect.pas index fea2058..df2501a 100755 --- a/lcoreselect.pas +++ b/lcoreselect.pas @@ -21,7 +21,7 @@ uses {$ifdef VER1_0} linux, {$else} - baseunix,unix,unixutil, + baseunix,unix,unixutil,sockets, {$endif} fd_utils; var diff --git a/lloopback.pas b/lloopback.pas index 167aa65..83870d6 100755 --- a/lloopback.pas +++ b/lloopback.pas @@ -15,7 +15,7 @@ uses {$ifdef ver1_0} linux; {$else} - baseunix,unix,unixutil; + baseunix,unix,unixutil,sockets; {$endif} {$i unixstuff.inc} diff --git a/lmessages.pas b/lmessages.pas index d7e4008..a7bd01e 100755 --- a/lmessages.pas +++ b/lmessages.pas @@ -99,7 +99,7 @@ procedure init; implementation uses - baseunix,unix,lcore,unixutil,ltimevalstuff;//,safewriteln; + baseunix,unix,lcore,unixutil,ltimevalstuff,sockets;//,safewriteln; {$i unixstuff.inc} type diff --git a/lsignal.pas b/lsignal.pas index 833c56e..ef98905 100755 --- a/lsignal.pas +++ b/lsignal.pas @@ -14,7 +14,7 @@ interface {$ifdef VER1_0} linux, {$else} - baseunix,unix,unixutil, + baseunix,unix,unixutil,sockets, {$endif} classes,lcore,lloopback; diff --git a/lsocket.pas b/lsocket.pas index ddee93e..f7d40e3 100755 --- a/lsocket.pas +++ b/lsocket.pas @@ -160,6 +160,32 @@ begin result := inaddrsize(inaddr); end; +//I used to use the system versions of these from within lsocket (which has +//functions whose name clashes with them) by using sockets.* and but I can't do +//that anymore since in some cases connect is now provided by unixstuff.inc +//hence these wrapper functions --plugwash +{$ifndef win32} + function system_Connect(Sock: LongInt;const Addr;Addrlen: LongInt):Boolean; + begin + result := connect(sock,addr,addrlen); + end; + function system_SendTo(Sock: LongInt; const Buf;BufLen: LongInt;Flags: LongInt;var Addr;AddrLen: LongInt):LongInt; + begin + result := sendto(sock,buf,buflen,flags,addr,addrlen); + end; + function system_getpeername(Sock: LongInt;var Addr;var Addrlen: LongInt):LongInt; + begin + result := getpeername(sock,addr,addrlen); + end; + function system_listen(Sock: LongInt; MaxConnect: LongInt):Boolean; + begin + result := listen(sock,maxconnect); + end; + function system_Accept(Sock: LongInt;var Addr;var Addrlen: LongInt):LongInt; + begin + result := accept(sock,addr,addrlen); + end; +{$endif} procedure tlsocket.realconnect; var @@ -220,7 +246,7 @@ begin //writeln(inaddr.inaddr.port); winsock.Connect(fdhandlein,winsock.psockaddr(@inADDR)^,getaddrsize); {$else} - sockets.Connect(fdhandlein,inADDR,getaddrsize); + system_Connect(fdhandlein,inADDR,getaddrsize); {$endif} eventcore.rmasterset(fdhandlein,false); eventcore.wmasterset(fdhandleout); @@ -245,6 +271,9 @@ begin realconnect; end; + + + procedure tlsocket.connect; var a:integer; @@ -391,7 +420,7 @@ begin if not udp then begin {!!! allow custom queue length? default 5} if listenqueue = 0 then listenqueue := 5; - If {$ifdef win32}winsock{$else}sockets{$endif}.Listen(fdhandlein,listenqueue)<>{$ifdef win32}0{$else}true{$endif} Then raise + If {$ifdef win32}winsock.listen{$else}system_listen{$endif}(fdhandlein,listenqueue)<>{$ifdef win32}0{$else}true{$endif} Then raise esocketexception.create('unable to listen'); state := wsListening; end else begin @@ -479,7 +508,7 @@ begin {$ifdef win32} result := winsock.accept(fdhandlein,@fromaddr,@fromaddrsize); {$else} - result := sockets.accept(fdhandlein,fromaddr,fromaddrsize); + result := system_accept(fdhandlein,fromaddr,fromaddrsize); {$endif} //now we have accepted one request start monitoring for more again eventcore.rmasterset(fdhandlein,true); @@ -495,6 +524,7 @@ begin end; end; + function tlsocket.sendto(dest:TInetSockAddrV;destlen:integer;data:pointer;len:integer):integer; var destx : {$ifdef win32}winsock.TSockAddr{$else}TInetSockAddrV{$endif} absolute dest; @@ -505,9 +535,10 @@ begin exit; end; {$endif} - result := {$ifdef win32}winsock{$else}sockets{$endif}.sendto(self.fdhandleout,data^,len,0,destx,destlen); + result := {$ifdef win32}winsock.sendto{$else}system_sendto{$endif}(self.fdhandleout,data^,len,0,destx,destlen); end; + function tlsocket.receivefrom(data:pointer;len:integer;var src:TInetSockAddrV;var srclen:integer):integer; var tempsrc:TInetSockAddrV; @@ -523,7 +554,7 @@ begin end; {$endif} tempsrclen := sizeof(tempsrc); - result := {$ifdef win32}winsock{$else}sockets{$endif}.recvfrom(self.fdhandlein,data^,len,0,srcx,tempsrclen); + result := recvfrom(self.fdhandlein,data^,len,0,srcx,tempsrclen); {$ifdef ipv6} biniptemp := inaddrvtobinip(tempsrc); @@ -636,11 +667,12 @@ begin end; + function tlsocket.getpeername(var addr:tsockaddrin;addrlen:integer):integer; var addrx : {$ifdef win32}winsock.tsockaddr{$else}tsockaddrin{$endif} absolute addr; begin - result := {$ifdef win32}winsock{$else}sockets{$endif}.getpeername(self.fdhandlein,addrx,addrlen); + result := {$ifdef win32}winsock.getpeername{$else}system_getpeername{$endif}(self.fdhandlein,addrx,addrlen); end; procedure tlsocket.getxaddrbin(var binip:tbinip); @@ -654,7 +686,7 @@ begin {$ifdef win32} winsock.getsockname(self.fdhandlein,psockaddr(@addr)^,i); {$else} - sockets.getsocketname(self.fdhandlein,addr,i); + getsocketname(self.fdhandlein,addr,i); {$endif} binip := inaddrvtobinip(addr); converttov4(binip); @@ -670,7 +702,7 @@ begin {$ifdef win32} winsock.getpeername(self.fdhandlein,psockaddr(@addr)^,i); {$else} - sockets.getpeername(self.fdhandlein,addr,i); + system_getpeername(self.fdhandlein,addr,i); {$endif} binip := inaddrvtobinip(addr); @@ -705,7 +737,7 @@ begin winsock.getsockname(self.fdhandlein,psockaddrin(@addr)^,i); {$else} - sockets.getsocketname(self.fdhandlein,addr,i); + getsocketname(self.fdhandlein,addr,i); {$endif} result := inttostr(htons(addr.InAddr.port)); @@ -721,7 +753,7 @@ begin winsock.getpeername(self.fdhandlein,psockaddrin(@addr)^,i); {$else} - sockets.getpeername(self.fdhandlein,addr,i); + system_getpeername(self.fdhandlein,addr,i); {$endif} result := inttostr(htons(addr.InAddr.port)); diff --git a/ltimevalstuff.pas b/ltimevalstuff.pas index df0342c..b955ef5 100755 --- a/ltimevalstuff.pas +++ b/ltimevalstuff.pas @@ -16,7 +16,7 @@ interface {$ifdef ver1_0} uses linux; {$else} - uses baseunix,unix,unixutil; + uses baseunix,unix,unixutil,sockets; {$endif} {$endif} diff --git a/unitfork.pas b/unitfork.pas index cd008da..019695b 100755 --- a/unitfork.pas +++ b/unitfork.pas @@ -17,7 +17,7 @@ uses {$ifdef VER1_0} linux, {$else} - baseunix,unix,unixutil, + baseunix,unix,unixutil,sockets, {$endif} sysutils; diff --git a/unixstuff.inc b/unixstuff.inc index 89c96f2..120f8f1 100755 --- a/unixstuff.inc +++ b/unixstuff.inc @@ -50,6 +50,43 @@ if (p=nil) or (p^=nil) then exit; fpexecv(p^,p); end; + function SendTo(Sock: LongInt; const Buf;BufLen: LongInt;Flags: LongInt;var Addr;AddrLen: LongInt):LongInt; + begin + result := fpsendto(sock,@buf,buflen,flags,@addr,addrlen); + end; + function RecvFrom(Sock: LongInt;var Buf;Buflen: LongInt;Flags: LongInt;var Addr;var addrlen: Longint):LongInt; + begin + result := fprecvfrom(sock,@buf,buflen,flags,@addr,@addrlen); + end; + {$define socket := fpsocket} + function Bind(Sock: LongInt;const Addr;AddrLen: LongInt):Boolean; + begin + result := fpbind(sock,@addr,addrlen) = 0; + end; + function SetSocketOptions(Sock: LongInt;Level: LongInt;OptName: LongInt;const OptVal;optlen: LongInt):LongInt; + begin + result := fpsetsockopt(sock,level,optname,@optval,optlen); + end; + function Connect(Sock: LongInt;const Addr;Addrlen: LongInt):Boolean; + begin + result := fpconnect(sock,@addr,addrlen) >= 0; + end; + function listen(Sock: LongInt;MaxConnect: LongInt):Boolean; + begin + result := fplisten(sock,maxconnect) = 0; + end; + function GetPeerName(Sock: LongInt; var Addr;var Addrlen: LongInt):LongInt; + begin + result := fpgetpeername(sock,@addr,@addrlen); + end; + function GetSocketName(Sock: LongInt; var Addr;var Addrlen: LongInt):LongInt; + begin + result := fpgetpeername(sock,@addr,@addrlen); + end; + function Accept(Sock: LongInt; var Addr; var Addrlen: LongInt):LongInt; + begin + result := fpaccept(sock,@addr,@addrlen); + end; {$endif} {$endif} {$ifdef ver2_0} -- 2.30.2