Skip to content

Use enums for tri-state return values #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
Merged

Conversation

andy5995
Copy link
Contributor

Resolves #112

There's probably some other areas that could be changed as well, but I thought I'd submit what I have so far for review and feedback.

src/SDL_net.c Outdated
@@ -1350,15 +1356,15 @@ static int SendOneDatagram(NET_DatagramSocket *sock, NET_Address *addr, Uint16 p
}

SDL_assert(rc == buflen);
return 1;
return NET_SUCCESS;
}

// see if any pending data can finally be sent, etc
static int PumpDatagramSocket(NET_DatagramSocket *sock)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the return type be enum TriState?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change PumpDatagramSocket to return bool (this was written before SDL3 changed from 0-or-negative-one to true-or-false for these sort of things).

I can do that separately (in which case, just back out changes to this function), or you can change it in this PR. Either's fine with me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mind doing that, but I'll do it in a separate PR. Since it's going to return a bool, would you like the function name changed a little as well?

@icculus
Copy link
Collaborator

icculus commented May 12, 2025

typedef enum NET_TriState
{
    Blah;
} NET_TriState;

(needs to be this way for the wiki bridge and consistency).

Let's call it something like NET_Outcome or NET_Result instead of NET_TriState. I'm open to suggestions ("result" sort of implies everything should return this type, which isn't good).

Outside of the typedef, never use the enum keyword; it's just NET_Whatever after that.

@andy5995
Copy link
Contributor Author

Let's call it something like NET_Outcome or NET_Result instead of NET_TriState. I'm open to suggestions ("result" sort of implies everything should return this type, which isn't good).

Done. I changed it to NET_Status. I don't have any other suggestions at this time.

{
struct addrinfo *addrwithport = MakeAddrInfoWithPort(addr, SOCK_DGRAM, port);
if (!addrwithport) {
return -1;
return NET_FAILURE;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this last time, but below this, you are returning 0 instead of NET_WOULDBLOCK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkunkacnc You're referring to return WouldBlock(err) ? 0? That's used in two other locations, in functions that wouldn't apply to this PR. To maintain some consistency, I'm not sure that should be changed there (although it wouldn't hurt and it would have the same effect).

Actually, I will make that change in this function.

It might be that there needs to be a discussion on whether all the zeroes in the code that indicate NET_WOULDBLOCK should be changed at some point.

@icculus Where do you stand on this?

@andy5995
Copy link
Contributor Author

@icculus I've searched the code some, but it's not clear to me yet if any other functions need to be changed. It might be more efficient for someone else to finish this than for you to try to point out any remaining changes needed. Any idea on how much stuff I missed?

@icculus
Copy link
Collaborator

icculus commented May 14, 2025

Let's merge this. If there are other things to tweak, we can always make more commits. :)

@icculus icculus merged commit 2ac59a2 into libsdl-org:main May 14, 2025
5 checks passed
@andy5995 andy5995 deleted the iss-112 branch May 14, 2025 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tri-state return values should be enums, not ints
3 participants