[fpc-pascal] BlockWrite() version 2.6.4

Marco van de Voort marcov at stack.nl
Mon Aug 14 16:44:00 CEST 2017


In our previous episode, Brian said:
> I notice the Do_Write() uses  repeat .. until where fpWrite() does a direct
> call.
> 
> What was the reasoning for the repeat..until in Do_Write() ?

Syscalls that block for hardware can return EINTR (ESysIntr) on some
*nixes when a signal arrives while waiting for data.

Some *nixes restart the syscall after the signal was delivered, but afaik
Linux does not.  So the loop is just to restart the syscall if needed.

source:
Function Do_Write(Handle:thandle;Addr:Pointer;Len:Longint):longint;

var j : cint;
Begin
  repeat
    Do_Write:=Fpwrite(Handle,addr,len);
    j:=geterrno;
  until (do_write<>-1) or ((j<>ESysEINTR) and (j<>ESysEAgain));
  If Do_Write<0 Then
   Begin
    Errno2InOutRes;
    Do_Write:=0;
   End
  else
   InOutRes:=0;
End;

see also:
https://www.gnu.org/software/libc/manual/html_node/Interrupted-Primitives.html



More information about the fpc-pascal mailing list