[fpc-pascal] fpSelect fails with UDP sockets?

Klaus Hartnegg hartnegg at gmx.de
Fri Apr 1 18:17:33 CEST 2016


Hello,

Does fpSelect not work with UDP sockets?
It always returns 0, which means it did not see a packet.
Is anything wrong with this code?

Uses
   UnixType, BaseUnix, Sockets;

procedure abort (reason:string);
begin
   writeln (reason);
   halt;
end;

var
   sock: cint;
   adr : {TInet}SockAddr;
   rc  : cint;
   FDS : Tfdset;

begin
   sock := fpSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
   if sock = -1 then
      abort ('Error from fpSocket');

   adr.sin_family      := AF_INET;
   adr.sin_addr.s_addr := INADDR_ANY;
   adr.sin_port        := htons(53);
   rc := fpBind (sock, @adr, sizeof(adr));
   if rc <> 0 then
      abort ('Error from fpBind');

   Writeln ('send udp packet in less than 5 seconds');
   Fpfd_zero(FDS);
   FpFd_set (sock,FDS);
   rc := fpSelect (1, at FDS,nil,nil,5000);
   if rc = -1 then
      abort ('Error from fpSelect');
   if rc > 0 then
     Writeln ('Thank you !')
   else
     Writeln ('Too late !');
end.



More information about the fpc-pascal mailing list