ocaml-multicore / eio

Effects-based direct-style IO for multicore OCaml
Other
559 stars 72 forks source link

(draft) Eio.Net.connect: optionally bind before connect #713

Open art-w opened 8 months ago

art-w commented 8 months ago

I'm looking to port some existing code which does a bind before connect and couldn't find a way to do it with Eio. I wasn't familiar with this trick, but it's apparently useful when you have multiple public IPs and need to control which one will be seen by the server.

Let me know if there's a better way to do this!.. I'm marking this PR as a draft because I'm starting to think this might actually require a new bind_connect function, to also expose the REUSEADDR/PORT options as they only make sense when ?bind is set.

SGrondin commented 8 months ago

I'd interested to hear what made you select this approach over exposing a bind function to the user?

talex5 commented 8 months ago

This seems reasonable to me.

Possibly we should have a dedicated options argument (extensible variant) as there will likely be loads more special features that could be added (see e.g. #575).

e.g. something like

Net.connect net dst
   ~options:[Source_addr src]

Need to decide what to do if a backend doesn't support an option. e.g. mirage-tcpip doesn't look like it supports this (https://github.com/mirage/mirage-tcpip/blob/75382e296ff6779338c3b7b069c885d5d8e10eeb/src/core/tcp.mli#L76).