Allow datagram_socket to be created without address#360
Allow datagram_socket to be created without address#360bikallem merged 8 commits intoocaml-multicore:mainfrom bikallem:fix-udp
Conversation
|
/cc @haesbaert |
|
Code LGTM, that's in the direction I was thinking as well, it feels a bit weird that |
|
@haesbaert could you please approve if you are happy with the PR. I want to use this for my ocaml-dns PR (mirage/ocaml-dns#312) |
lib_eio_linux/eio_linux.ml
Outdated
| udp_socket sock | ||
| | (`UdpV4 | `UdpV6) as s -> | ||
| let socket_fd = Unix.socket ~cloexec:true (socket_domain_of s) Unix.SOCK_DGRAM 0 in | ||
| let sock = FD.of_unix ~sw ~seekable:false ~close_unix:true socket_fd in |
There was a problem hiding this comment.
Does is matter that the socket options are different in this case?
(Aside: why is SO_REUSEPORT on by default? That seems like a dangerous option, allowing two programs to listen on the same port by mistake! )
There was a problem hiding this comment.
Good point, I wonder if it actually has any effect if you don't bind(2) ?
There was a problem hiding this comment.
Not sure about SO_REUSEPORT myself. I think we should remove these options altogether and leave it to the user of the lib to set them if they need it after #322 is implemented. Should both of reuseport and resuseaddress settings be removed? in both TCP and UDP?
There was a problem hiding this comment.
Let's leave this to PR which will address #322
There was a problem hiding this comment.
I think it's fine and even desirable to have reuse_{addr,port} as an optional argument, but it should be default off, I'd add the optional arguments to datagram_socket to mimick the behaviour of listening_socket (default off).
This would be a breaking change as old users of datagram_socket Sockaddr would now get default off, but I think that's better than the old behavior.
There was a problem hiding this comment.
I have opened #362 to discuss and track this issue.
There was a problem hiding this comment.
Does is matter that the socket options are different in this case?
Yes, Udp4 creates socket domain of Unix.PF_INET and Udp6 creates socket domain of Unix.PF_INET6.
EDIT: Do you mean the pattern matching? I suppose not but it is better to be explicit, no?
There was a problem hiding this comment.
I meant I wasn't sure if the reuse options were useful even without a fixed source address. I guess it is probably best to ignore them, as you did.
|
@talex5 I have addressed the review comments. |
|
@haesbaert I have now added |
Removed the last IPv6 test since it was identical to an earlier test.
Fix problem that UDP sockets were not created close-on-exec.
talex5
left a comment
There was a problem hiding this comment.
I pushed some more changes (to be squashed if accepted):
- I removed some duplication in the test code (and removed a duplicate test).
- I changed the socket creation code to share the bits that were the same. That revealed that the old path wasn't setting close-on-exec.
- I removed the new functions from eio_unix. This is intended for users integrating with Unix, rather than as a place for sharing common code between backends, and these functions were quite confusing (they do nothing if passed
false), and also not shared.
If that looks OK, I'm happy for it to be merged.
|
LGTM. 👍 |
CHANGES: API changes: - Unify IO errors as `Eio.Io` (@talex5 ocaml-multicore/eio#378). This makes it easy to catch and log all IO errors if desired. The exception payload gives the type and can be used for matching specific errors. It also allows attaching extra information to exceptions, and various functions were updated to do this. - Add `Time.Mono` for monotonic clocks (@bikallem @talex5 ocaml-multicore/eio#338). Using the system clock for timeouts, etc can fail if the system time is changed during the wait. - Allow datagram sockets to be created without a source address (@bikallem @haesbaert ocaml-multicore/eio#360). The kernel will allocate an address in this case. You can also now control the `reuse_addr` and `reuse_port` options. - Add `File.stat` and improve `Path.load` (@haesbaert @talex5 ocaml-multicore/eio#339). `Path.load` now uses the file size as the initial buffer size. - Add `Eio_unix.pipe` (@patricoferris ocaml-multicore/eio#350). This replaces `Eio_linux.pipe`. - Avoid short reads from `getrandom(2)` (@haesbaert ocaml-multicore/eio#344). Guards against buggy user code that might not handle this correctly. - Rename `Flow.read` to `Flow.single_read` (@talex5 ocaml-multicore/eio#353). This is a low-level function and it is easy to use it incorrectly by ignoring the possibility of short reads. Bug fixes: - Eio_luv: Fix non-tail-recursive continue (@talex5 ocaml-multicore/eio#378). Affects the `Socket_of_fd` and `Socketpair` effects. - Eio_linux: UDP sockets were not created close-on-exec (@talex5 ocaml-multicore/eio#360). - Eio_linux: work around io_uring non-blocking bug (@haesbaert ocaml-multicore/eio#327 ocaml-multicore/eio#355). The proper fix should be in Linux 6.1. - `Eio_mock.Backend`: preserve backtraces from `main` (@talex5 ocaml-multicore/eio#349). - Don't lose backtrace in `Switch.run_internal` (@talex5 ocaml-multicore/eio#369). Documentation: - Use a proper HTTP response in the README example (@talex5 ocaml-multicore/eio#377). - Document that read_dir excludes "." and ".." (@talex5 ocaml-multicore/eio#379). - Warn about both operations succeeding in `Fiber.first` (@talex5 ocaml-multicore/eio#358, reported by @iitalics). - Update README for OCaml 5.0.0~beta2 (@talex5 ocaml-multicore/eio#375). Backend-specific changes: - Eio_luv: add low-level process support (@patricoferris ocaml-multicore/eio#359). A future release will add Eio_linux support and a cross-platform API for this. - Expose `Eio_luv.Low_level.Stream.write` (@patricoferris ocaml-multicore/eio#359). - Expose `Eio_luv.Low_level.get_loop` (@talex5 ocaml-multicore/eio#371). This is needed if you want to create resources directly and then use them with Eio_luv. - `Eio_linux.Low_level.openfile` is gone (@talex5 ocaml-multicore/eio#378). It was just left-over test code.
This PR allows to create UDP
datagram_socketwithout passing in the socket address. Being able to createdatagram_socketwithout socket address is useful in udp client applications where it is convenient to send data to UDP severs without having to figure out the udp client address first.Fixes #345 #341