-
Notifications
You must be signed in to change notification settings - Fork 38
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
Conversation
lightbug_http/net.mojo
Outdated
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, overloading sounds good!
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.