Posix fixes by Michael Van Canneyt

git-svn-id: https://svn.code.sf.net/p/synalist/code/trunk@214 7c85be65-684b-0410-a082-b2ed4fbef004
This commit is contained in:
geby 2021-06-12 13:27:35 +00:00
parent 9ee9fa486e
commit bdadbd4c7c
5 changed files with 41 additions and 19 deletions

View File

@ -1,5 +1,5 @@
{==============================================================================| {==============================================================================|
| Project : Ararat Synapse | 009.010.001 | | Project : Ararat Synapse | 009.010.002 |
|==============================================================================| |==============================================================================|
| Content: Library base | | Content: Library base |
|==============================================================================| |==============================================================================|
@ -102,7 +102,9 @@ interface
uses uses
SysUtils, Classes, SysUtils, Classes,
{$IFDEF FPC}
synafpc, synafpc,
{$ENDIF}
synsock, synautil, synacode, synaip synsock, synautil, synacode, synaip
{$IFDEF CIL} {$IFDEF CIL}
,System.Net ,System.Net
@ -3677,7 +3679,7 @@ begin
begin begin
ip6 := StrToIp6(MCastIP); ip6 := StrToIp6(MCastIP);
for n := 0 to 15 do for n := 0 to 15 do
Multicast6.ipv6mr_multiaddr.u6_addr8[n] := Ip6[n]; Multicast6.ipv6mr_multiaddr.s6_addr[n] := Ip6[n];
Multicast6.ipv6mr_interface := 0; Multicast6.ipv6mr_interface := 0;
SockCheck(synsock.SetSockOpt(FSocket, IPPROTO_IPV6, IPV6_JOIN_GROUP, SockCheck(synsock.SetSockOpt(FSocket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
PAnsiChar(@Multicast6), SizeOf(Multicast6))); PAnsiChar(@Multicast6), SizeOf(Multicast6)));
@ -3704,7 +3706,7 @@ begin
begin begin
ip6 := StrToIp6(MCastIP); ip6 := StrToIp6(MCastIP);
for n := 0 to 15 do for n := 0 to 15 do
Multicast6.ipv6mr_multiaddr.u6_addr8[n] := Ip6[n]; Multicast6.ipv6mr_multiaddr.s6_addr[n] := Ip6[n];
Multicast6.ipv6mr_interface := 0; Multicast6.ipv6mr_interface := 0;
SockCheck(synsock.SetSockOpt(FSocket, IPPROTO_IPV6, IPV6_LEAVE_GROUP, SockCheck(synsock.SetSockOpt(FSocket, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
PAnsiChar(@Multicast6), SizeOf(Multicast6))); PAnsiChar(@Multicast6), SizeOf(Multicast6)));

View File

@ -1,5 +1,5 @@
{==============================================================================| {==============================================================================|
| Project : Ararat Synapse | 001.001.004 | | Project : Ararat Synapse | 001.001.005 |
|==============================================================================| |==============================================================================|
| Content: Socket Independent Platform Layer - Delphi Posix definition include | | Content: Socket Independent Platform Layer - Delphi Posix definition include |
|==============================================================================| |==============================================================================|
@ -64,7 +64,6 @@ partially compatible with NextGen Delphi compiler - iOS
} }
interface interface
uses uses
@ -89,10 +88,8 @@ const
type type
TSocket = longint; TSocket = longint;
TAddrFamily = integer; TAddrFamily = integer;
TMemory = pointer; TMemory = pointer;
type type
TFDSet = fd_set; TFDSet = fd_set;
PFDSet = Pfd_set; PFDSet = Pfd_set;
@ -100,11 +97,17 @@ type
Ttimeval = Posix.SysTime.timeval; Ttimeval = Posix.SysTime.timeval;
const const
// {$IFDEF MACOS}
FIONREAD = $4004667F; // oSX FIONREAD = Posix.StrOpts.FIONREAD; FIONREAD = $4004667F; // oSX FIONREAD = Posix.StrOpts.FIONREAD;
FIONBIO = $8004667E; //OSX FIONBIO = Posix.StrOpts.FIONBIO; FIONBIO = $8004667E; //OSX FIONBIO = Posix.StrOpts.FIONBIO;
FIOASYNC = $8004667D; //OSX FIOASYNC = Posix.StrOpts.FIOASYNC; // not defined in XE2 FIOASYNC = $8004667D; //OSX FIOASYNC = Posix.StrOpts.FIOASYNC; // not defined in XE2
{$ELSE}
// LINUX
FIONREAD = $541B;
FIONBIO = $5421;
FIOASYNC = $5452;
{$ENDIF}
{ FIONREAD = $541B; // LINUX? { FIONREAD = $541B; // LINUX?
FIONBIO = $5421; FIONBIO = $5421;
@ -352,7 +355,9 @@ var
SockEnhancedApi: Boolean; SockEnhancedApi: Boolean;
SockWship6Api: Boolean; SockWship6Api: Boolean;
{$DEFINE SOCK_HAS_SINLEN} // OSX {$IFDEF MACOS}
{$DEFINE SOCK_HAS_SINLEN} // OSX
{$ENDIF}
type type
TVarSin = packed record TVarSin = packed record
@ -466,7 +471,7 @@ end;
procedure SET_LOOPBACK_ADDR6 (const a: PInAddr6); procedure SET_LOOPBACK_ADDR6 (const a: PInAddr6);
begin begin
FillChar(a^, sizeof(TInAddr6), 0); FillChar(a^, sizeof(TInAddr6), 0);
a^.__s6_addr8[15] := 1; a^.s6_addr[15] := 1;
end; end;
{$IFDEF NEXTGEN} {$IFDEF NEXTGEN}
@ -733,7 +738,10 @@ var
function GetAddr(const IP, port: string; Hints: AddrInfo; var Sin: TVarSin): integer; function GetAddr(const IP, port: string; Hints: AddrInfo; var Sin: TVarSin): integer;
var var
Addr: PAddrInfo; Addr: PAddrInfo;
aIP,aPort : AnsiString;
begin begin
aIP:=Utf8Encode(IP);
aPort:=Utf8Encode(Port);
Addr := nil; Addr := nil;
try try
FillChar(Sin, Sizeof(Sin), 0); FillChar(Sin, Sizeof(Sin), 0);
@ -741,23 +749,23 @@ var
begin begin
Hints.ai_socktype := 0; Hints.ai_socktype := 0;
Hints.ai_protocol := 0; Hints.ai_protocol := 0;
Result := GetAddrInfo(PAnsiChar(AnsiString(IP)), nil, Hints, Addr); Result := GetAddrInfo(PAnsiChar(aIP), nil, Hints, Addr);
end end
else else
begin begin
if (IP = cAnyHost) or (IP = c6AnyHost) then if (IP = cAnyHost) or (IP = c6AnyHost) then
begin begin
Hints.ai_flags := AI_PASSIVE; Hints.ai_flags := AI_PASSIVE;
Result := GetAddrInfo(nil, PAnsiChar(AnsiString(Port)), Hints, Addr); Result := GetAddrInfo(nil, PAnsiChar(aPort)), Hints, Addr);
end end
else else
if (IP = cLocalhost) or (IP = c6Localhost) then if (IP = cLocalhost) or (IP = c6Localhost) then
begin begin
Result := GetAddrInfo(nil, PAnsiChar(AnsiString(Port)), Hints, Addr); Result := GetAddrInfo(nil, PAnsiChar(aPort)), Hints, Addr);
end end
else else
begin begin
Result := GetAddrInfo(PAnsiChar(AnsiString(IP)), PAnsiChar(AnsiString(Port)), Hints, Addr); Result := GetAddrInfo(PAnsiChar(aIP), PAnsiChar(aPort), Hints, Addr);
end; end;
end; end;
if Result = 0 then if Result = 0 then
@ -939,7 +947,7 @@ begin
while PAdrPtr^[i] <> nil do while PAdrPtr^[i] <> nil do
begin begin
InAddr := PAdrPtr^[i]^; InAddr := PAdrPtr^[i]^;
aby := TArray<byte>(InAddr); aby := TArray<byte>(@InAddr);
s := Format('%d.%d.%d.%d', [aby[0], aby[1], s := Format('%d.%d.%d.%d', [aby[0], aby[1],
aby[2], aby[3]]); aby[2], aby[3]]);
IPList.Add(s); IPList.Add(s);
@ -1076,7 +1084,7 @@ begin
try try
RemoteHost := GetHostByAddr(IPn, SizeOf(IPn), AF_INET); RemoteHost := GetHostByAddr(IPn, SizeOf(IPn), AF_INET);
if RemoteHost <> nil then if RemoteHost <> nil then
Result := string(RemoteHost^.hname); Result := string(RemoteHost^.h_name);
finally finally
SynSockCS.Leave; SynSockCS.Leave;
end; end;

View File

@ -79,7 +79,11 @@ interface
uses uses
{$IFNDEF MSWINDOWS} {$IFNDEF MSWINDOWS}
{$IFNDEF FPC} {$IFNDEF FPC}
Libc, {$IFNDEF POSIX}
Libc,
{$ELSE}
Posix.Langinfo,
{$ENDIF}
{$ENDIF} {$ENDIF}
{$ELSE} {$ELSE}
Windows, Windows,
@ -1501,7 +1505,11 @@ end;
function GetCurCP: TMimeChar; function GetCurCP: TMimeChar;
begin begin
{$IFNDEF FPC} {$IFNDEF FPC}
{$IFNDEF POSIX}
Result := GetCPFromID(nl_langinfo(_NL_CTYPE_CODESET_NAME)); Result := GetCPFromID(nl_langinfo(_NL_CTYPE_CODESET_NAME));
{$ELSE}
Result := GetCPFromID(nl_langinfo(CODESET));
{$ENDIF}
{$ELSE} {$ELSE}
//How to get system codepage without LIBC? //How to get system codepage without LIBC?
Result := UTF_8; Result := UTF_8;

View File

@ -72,7 +72,9 @@ uses
synafpc, synafpc,
{$IFNDEF MSWINDOWS} {$IFNDEF MSWINDOWS}
{$IFNDEF FPC} {$IFNDEF FPC}
Libc, {$IFNDEF POSIX}
Libc,
{$ENDIF}
{$ENDIF} {$ENDIF}
SysUtils; SysUtils;
{$ELSE} {$ELSE}

View File

@ -80,7 +80,9 @@ uses
synautil, blcksock, SysUtils, Classes synautil, blcksock, SysUtils, Classes
{$IFDEF UNIX} {$IFDEF UNIX}
{$IFNDEF FPC} {$IFNDEF FPC}
{$IFNDEF POSIX}
, Libc , Libc
{$ENDIF}
{$ENDIF} {$ENDIF}
{$ELSE} {$ELSE}
, Windows , Windows