FIONREAD FPC FpIOCtl for Cross platform Sockets

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

FIONREAD FPC FpIOCtl for Cross platform Sockets

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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FIONREAD FPC FpIOCtl for Cross platform Sockets

Marco van de Voort
In our previous episode, Andrew Brunner said:
> 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.
 
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FIONREAD FPC FpIOCtl for Cross platform Sockets

Micha Nelissen
In reply to this post by Andrew Brunner
Andrew Brunner wrote:
> Sockets programming often requires a poll for how much data is
> available on a particular socket descriptor.

AFAIK, it doesn't? If data is available, but less than you request, a
'read' on the socket does not block, but returns the number of bytes
read, which is less than you requested.

Micha
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal