[libfabric-users] API suggestion: some return values without minus sign

Hugh Fisher laranzu at ozemail.com.au
Mon Jun 23 18:09:37 PDT 2025


The existing convention for socket programming (accept, send, etc) is that error codes are NOT negated. The function returns -1, errno is set to the positive value. So as a socket programmer I’m used to writing

	if (err < 0 && errno == EAGAIN)

without the minus sign. Since I imagine many libfabric programmers are also socket programmers, it is the current system that forces people to remember two different conventions.

My proposal does not introduce another set of negative values, since every #define refers to an existing value. (And if we really want to eliminate redundancy, why have #define FI_EAGAIN EAGAIN to begin with?) The _RET_ is there to make it clear that these are not the original error values. IMHO it will make it easier for new programmers to write correct code, while not requiring any change to existing user or implementation code.

—
cheers,
Hugh Fisher


> On 23 Jun 2025, at 5:16 pm, Xiong, Jianxin <jianxin.xiong at intel.com> wrote:
> 
> Hi Hugh,
> 
> Thanks for the suggestion, but I would disagree with the proposal.
> 
> The convention is to define the error numbers as positive and the returned error as negative, just like how "errno.h" is defined and used. This is a consistent behavior and doesn't need much hard work to use correctly in applications.
> 
> Introducing anther set of negative values is redundant and can cause more confusion. Now people will have to remember two different conventions and try not to mix them up. I don't think this is worthwhile.
> 
> I understand some users may prefer not needing to write the minus sign, this can be easily achieved easily by local definitions.
> 
> Thanks,
> 
> Jianxin Xiong
> 
>> -----Original Message-----
>> From: Libfabric-users <libfabric-users-bounces at lists.openfabrics.org> On Behalf Of Hugh Fisher via Libfabric-users
>> Sent: Sunday, June 22, 2025 6:09 PM
>> To: libfabric-users at lists.openfabrics.org
>> Subject: [libfabric-users] API suggestion: some return values without minus sign
>> 
>> Suggestion for the libfabric public API, add three defines in fabric.h
>> 
>> #define FI_RET_EAVAIL   (-FI_EAVAIL)
>> #define FI_RET_AGAIN    (-FI_EAGAIN)
>> #define FI_RET_TIMEDOUT (-FI_ETIMEDOUT)
>> 
>> This is so we don’t have to write the minus sign when comparing the return value from fi_send, etc to particular values.
>> 
>> It’s an easy mistake: in developing my current program I wrote  “if (err == FI_EAGAIN) … “ and was very impressed by the speed and reliability
>> of my network link, I never ran out of resources. Even though I’d posted tens of thousands of fi_recv ops with no active sender … uh, that can’t
>> be right.
>> 
>> I suggest only these three values, not all possible error codes, because these three are the “not really errors” that are most likely to be
>> individually tested for.
>> 
>> I considered FI_ERR_AVAIL etc instead of FI_RET, but I think the RET prefix makes it clear that these are derived values.
>> 
>> Happy to try and submit a pull request on GitHub, but thought this was a better place to discuss initially.
>> 
>>>> cheers,
>> Hugh Fisher
>> 
>> 
>> _______________________________________________
>> Libfabric-users mailing list
>> Libfabric-users at lists.openfabrics.org
>> https://lists.openfabrics.org/mailman/listinfo/libfabric-users




More information about the Libfabric-users mailing list