Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-10

FIONREAD FPC FpIOCtl for Cross platform Sockets

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrew Brunner

Sockets programming often requires a poll for how much data is available on a particular socket descriptor.

I'm porting an inhouse library for a sockets implementation and I realize that while I have a FpIOCtl call in the baseUnix unit I have no such animal in the Sockets implement which would be cross platform. Winsock does support this call and was wondering if someone wants to just use the windows sockets implement in the Sockets unit instead of using conditional definitions.

Windows Constants

  FD_READ         = $01;
  FD_WRITE        = $02;
  FD_OOB          = $04;
  FD_ACCEPT       = $08;
  FD_CONNECT      = $10;
  FD_CLOSE        = $20;
  FD_QOS          = $40;
  FD_GROUP_QOS    = $80;
  FD_MAX_EVENTS	= 8;
  FD_ALL_EVENTS	= $100; { AHS - trudno powiedzieæ, ile powinno byæ }
  IOCPARM_MASK = $7f;
  IOC_VOID     = $20000000;
  IOC_OUT      = $40000000;
  IOC_IN       = $80000000;
  IOC_INOUT    = (IOC_IN or IOC_OUT);
     FIONREAD     = IOC_OUT or { get # bytes to read }
       ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or
       (Longint(Byte('f')) shl 8) or 127;
     FIONBIO      = IOC_IN or { set/clear non-blocking i/o }
       ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or
       (Longint(Byte('f')) shl 8) or 126;
     FIOASYNC     = IOC_IN or { set/clear async i/o }
       ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or
       (Longint(Byte('f')) shl 8) or 125;

Winsock DLL calling for "ioctlsocket"

  TWSF_ioctlsocket           = function (s: TSocket; cmd: DWORD; var
arg: u_long): Integer; stdcall;

Anyone want to update the sockets unit to include a cross platform ioctl function for sockets specifically?

Thanks a lot.

Marco van de Voort
to Andrew Brunner

In our previous episode, Andrew Brunner said:

Show quoted text 9 lines
Sockets programming often requires a poll for how much data is available on a particular socket descriptor. I'm porting an inhouse library for a sockets implementation and I realize that while I have a FpIOCtl call in the baseUnix unit I have no such animal in the Sockets implement which would be cross platform. Winsock does support this call and was wondering if someone wants to just use the windows sockets implement in the Sockets unit instead of using conditional definitions.

See http://bugs.freepascal.org/view.php?id=14701 , it is about the same problem with select.

Bottom line: new unit, not in sockets. These are border cases, and while both Unix and Windows have it in *some* form, the usage might not be the same. The sockets unit is now fairly orthogonal, so lets keep it that way, and not increase porting burden.