[fpc-pascal] Translating from error numbers to symbolic name

2012-08-03 Thread Mark Morgan Lloyd
When using a function like fpAccept on a non-blocking socket, in some 
cases -1 is returned with a documented (Linux kernel) error code of 
EAGAIN. Should I be looking for this in errno or SocketError?


When I've retrieved a numeric code from errno or SocketError, is there a 
way of converting it to a concise literal such as 'EAGAIN'? I want the 
log to report that accept() has failed with EAGAIN, rather than having 
explanatory text that doesn't match the kernel documentation.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Translating from error numbers to symbolic name

2012-08-03 Thread Marco van de Voort
In our previous episode, Mark Morgan Lloyd said:
> When using a function like fpAccept on a non-blocking socket, in some 
> cases -1 is returned with a documented (Linux kernel) error code of 
> EAGAIN. Should I be looking for this in errno or SocketError?

Socketerror is more portable, but on *nix errno will work too.
 
> When I've retrieved a numeric code from errno or SocketError, is there a 
> way of converting it to a concise literal such as 'EAGAIN'?

See errors unit.

> I want the 
> log to report that accept() has failed with EAGAIN, rather than having 
> explanatory text that doesn't match the kernel documentation.

EAGAIN generally means that you should try again. So repeat until
   
  repeat
res:=dofunc;
err:=geterrno;
  until (res<>-1) or ((err<>ESysEINTR) and (err<>ESysEAgain));
  
it is a workaround against potential deadlock between userland and kernel
iirc. Retrying means it can simple work.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Translating from error numbers to symbolic name

2012-08-03 Thread Mark Morgan Lloyd

Marco van de Voort wrote:

In our previous episode, Mark Morgan Lloyd said:
When using a function like fpAccept on a non-blocking socket, in some 
cases -1 is returned with a documented (Linux kernel) error code of 
EAGAIN. Should I be looking for this in errno or SocketError?


Socketerror is more portable, but on *nix errno will work too.


Thanks, found that in the source.

When I've retrieved a numeric code from errno or SocketError, is there a 
way of converting it to a concise literal such as 'EAGAIN'?


See errors unit.


But if I'm reading that properly, it translates (some OS-specific 
number) to 'Try again', not to 'EAGAIN' which is what the kernel docs 
refer to and which can reasonably be logged without requiring i18n.


I want the 
log to report that accept() has failed with EAGAIN, rather than having 
explanatory text that doesn't match the kernel documentation.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Translating from error numbers to symbolic name

2012-08-03 Thread waldo kitty

On 8/3/2012 18:24, Marco van de Voort wrote:


EAGAIN generally means that you should try again. So repeat until

   repeat
 res:=dofunc;
 err:=geterrno;
   until (res<>-1) or ((err<>ESysEINTR) and (err<>ESysEAgain));

it is a workaround against potential deadlock between userland and kernel
iirc. Retrying means it can simple work.


should there be some sort of retry count or timing period in which to decide to 
give up so that one doesn't retry forever? if yes, how might that be 
accomplished? ;)


admittedly, i may have missed something in the ESysEINTR and ESysAgain portion 
since i'm a new babe with regards to signaling like that... but i just had to 
ask, ya know? ;)

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal