Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to compile multiplatform #31

Open
Marijsoft opened this issue Oct 5, 2024 · 2 comments
Open

Unable to compile multiplatform #31

Marijsoft opened this issue Oct 5, 2024 · 2 comments

Comments

@Marijsoft
Copy link

On android and linux with fmx have this error on 4 part

function TncLine.GetReceiveTimeout: Integer;
var
Opt: DWord;
OptSize: Integer;
begin
OptSize := SizeOf(Opt);
{$IFDEF MSWINDOWS}
Check(GetSockOpt(FHandle, SOL_SOCKET, SO_RCVTIMEO, PAnsiChar(@opt), OptSize));
{$ELSE}
Check(GetSockOpt(FHandle, SOL_SOCKET, SO_RCVTIMEO, Opt, OptSize));
{$ENDIF}
Result := Opt;
end;

Opt:DWord is only windows platform i try with uint32 for other platform but have error on Check(GetSockOpt(FHandle, SOL_SOCKET, SO_RCVTIMEO, Opt, OptSize));

@spawn451
Copy link

spawn451 commented Nov 12, 2024

I have the same issue. What I did is :

function TncLine.GetReceiveTimeout: Integer;
var
  Opt: Cardinal;
  OptSize: {$IFDEF MSWINDOWS}Integer{$ELSE}socklen_t{$ENDIF};
begin
  OptSize := SizeOf(Opt);
{$IFDEF MSWINDOWS}
  Check(GetSockOpt(FHandle, SOL_SOCKET, SO_RCVTIMEO, PAnsiChar(@Opt), OptSize));
{$ELSE}
  Check(GetSockOpt(FHandle, SOL_SOCKET, SO_RCVTIMEO, Opt, OptSize));
{$ENDIF}
  Result := Opt;
end;
function TncLine.GetSendTimeout: Integer;
var
  Opt: Cardinal;
  OptSize: {$IFDEF MSWINDOWS}Integer{$ELSE}socklen_t{$ENDIF};
begin
  OptSize := SizeOf(Opt);
{$IFDEF MSWINDOWS}
  Check(GetSockOpt(FHandle, SOL_SOCKET, SO_SNDTIMEO, PAnsiChar(@Opt), OptSize));
{$ELSE}
  Check(GetSockOpt(FHandle, SOL_SOCKET, SO_SNDTIMEO, Opt, OptSize));
{$ENDIF}
  Result := Opt;
end;

Last error is there : procedure ProcessEvent; override;

  { TConnectThread }

procedure TConnectThread.ProcessEvent;
begin
  ConnectResult := Connect(Line.FHandle, Line.AddrResult^.ai_addr^, Line.AddrResult^.ai_addrlen);
end; 

Seems that this is only for Windows.

@spawn451
Copy link

spawn451 commented Nov 15, 2024

I haven't tested on Android but here are the modifications that work for Windows and Linux (ncLines.pas)

function TncLine.GetReceiveTimeout: Integer;
var
  Opt: Cardinal;
  OptSize: {$IFDEF MSWINDOWS}Integer{$ELSE}socklen_t{$ENDIF};
begin
  OptSize := SizeOf(Opt);
{$IFDEF MSWINDOWS}
  Check(GetSockOpt(FHandle, SOL_SOCKET, SO_RCVTIMEO, PAnsiChar(@Opt), OptSize));
{$ELSE}
  Check(GetSockOpt(FHandle, SOL_SOCKET, SO_RCVTIMEO, Opt, OptSize));
{$ENDIF}
  Result := Opt;
end;
procedure TncLine.SetReceiveTimeout(const Value: Integer);
var
  Opt: Cardinal;
  OptSize: Integer;
begin
  Opt := Value;
  OptSize := SizeOf(Opt);
{$IFDEF MSWINDOWS}
  Check(SetSockOpt(FHandle, SOL_SOCKET, SO_RCVTIMEO, PAnsiChar(@Opt), OptSize));
{$ELSE}
  Check(SetSockOpt(FHandle, SOL_SOCKET, SO_RCVTIMEO, Opt, OptSize));
{$ENDIF}
end;
function TncLine.GetSendTimeout: Integer;
var
  Opt: Cardinal;
  OptSize: {$IFDEF MSWINDOWS}Integer{$ELSE}socklen_t{$ENDIF};
begin
  OptSize := SizeOf(Opt);
{$IFDEF MSWINDOWS}
  Check(GetSockOpt(FHandle, SOL_SOCKET, SO_SNDTIMEO, PAnsiChar(@Opt), OptSize));
{$ELSE}
  Check(GetSockOpt(FHandle, SOL_SOCKET, SO_SNDTIMEO, Opt, OptSize));
{$ENDIF}
  Result := Opt;
end;
procedure TncLine.SetSendTimeout(const Value: Integer);
var
  Opt: Cardinal;
  OptSize: Integer;
begin
  Opt := Value;
  OptSize := SizeOf(Opt);
{$IFDEF MSWINDOWS}
  Check(SetSockOpt(FHandle, SOL_SOCKET, SO_SNDTIMEO, PAnsiChar(@Opt), OptSize));
{$ELSE}
  Check(SetSockOpt(FHandle, SOL_SOCKET, SO_SNDTIMEO, Opt, OptSize));
{$ENDIF}
end;
{$IFDEF MSWINDOWS}
// Windows-specific types and variables
var
  ExtDllHandle: THandle = 0;

procedure AttachAddrInfo;
  procedure SafeLoadFrom(aDll: string);
  begin
    if not Assigned(DllGetAddrInfo) then
    begin
      ExtDllHandle := SafeLoadLibrary(aDll);
      if ExtDllHandle <> 0 then
      begin
        DllGetAddrInfo := GetProcAddress(ExtDllHandle, 'GetAddrInfoW');
        DllFreeAddrInfo := GetProcAddress(ExtDllHandle, 'FreeAddrInfoW');
        if not Assigned(DllGetAddrInfo) then
        begin
          FreeLibrary(ExtDllHandle);
          ExtDllHandle := 0;
        end;
      end;
    end;
  end;
begin
  SafeLoadFrom('ws2_32.dll');
  SafeLoadFrom('wship6.dll');
end;
{$ENDIF}

{ TConnectThread }
procedure TConnectThread.ProcessEvent;
begin
  {$IFDEF MSWINDOWS}
  ConnectResult := Connect(Line.FHandle, Line.AddrResult^.ai_addr^, Line.AddrResult^.ai_addrlen);
  {$ELSE}
  ConnectResult := Connect(Line.FHandle, Line.AddrResult^.ai_addr^, Line.AddrResult^.ai_addrlen);
  {$ENDIF}
end;

initialization
{$IFDEF MSWINDOWS}
var
  WSAData: TWSAData;
begin
  WSAStartup(MakeWord(2, 2), WSAData);
  AttachAddrInfo;
end;
{$ENDIF}

finalization
{$IFDEF MSWINDOWS}
if ExtDllHandle <> 0 then
  FreeLibrary(ExtDllHandle);
WSACleanup;
{$ENDIF}

end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants