Skip to content
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

UDP Socket support #87

Merged
merged 7 commits into from
Jan 15, 2025
Merged

UDP Socket support #87

merged 7 commits into from
Jan 15, 2025

Conversation

thatstoasty
Copy link
Collaborator

@thatstoasty thatstoasty commented Jan 13, 2025

Extended the Socket struct to support UDP. Some higher level structs like UDPConnection were added to support the dial/listen paradigm as well. An example echo server was added to the tests.

Comment on lines 271 to 283
fn read_from(mut self, mut dest: Bytes) raises -> (UInt, String, UInt16):
"""Reads data from the underlying file descriptor.

Args:
dest: The buffer to read data into.

Returns:
The number of bytes read, or an error if one occurred.

Raises:
Error: If an error occurred while reading data.
"""
return self.socket.receive_from_into(dest)
Copy link
Collaborator

@saviorand saviorand Jan 14, 2025

Choose a reason for hiding this comment

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

on the socket this method is called receive_from_into but here it's one of the overloads on read_from. For consistency we could call this one read_from_into? or am I missing something

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's just verbiage we want to use. Do you think connections should read/write (read_from/write_to) or send/receive (receive_from/send_to)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think read/write is fine on connections, I was more talking about this pattern where we supply the dest to read into, looks like this same pattern has the from_into suffix on the socket but just from on the connection, although they have a similar signature.
I think on the socket this similar to how it's done in the Python socket, right? where recvfrom_into writes into a given buffer, and recvfrom allocates a new one. Maybe on the connection we can have a similar pattern?

Copy link
Collaborator

Choose a reason for hiding this comment

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

or is it better to have an overload here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ohh, I see what you mean. Yeah, the socket follows Python. I think perhaps overloading the socket like the connection would be better. Python doesn't have function overloading which is probably why there's more than one function name. Didn't think of that!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, overloading sounds good!

@thatstoasty thatstoasty changed the title WIP: Udp UDP Socket support Jan 15, 2025
@saviorand saviorand merged commit 064d7f6 into Lightbug-HQ:main Jan 15, 2025
3 checks passed
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.

2 participants