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

add Eio_unix.Sockopt for setting/getting socket options #575

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

avsm
Copy link
Contributor

@avsm avsm commented Jul 7, 2023

There are some socket options that are Linux-specific which are quite handy to have. This adds a Eio_unix.Sockopt module which works on Eio_unix.Fd.t values.

This is a draft PR to check on the interface: the current PR replaces the need for Unix.setsockopt and has a single simple GADT for the socket options. Alternatively we could just expose the extended ones in the same style as upstream OCaml as a separate set of types, too. Opinions welcome.

@patricoferris patricoferris linked an issue Jul 8, 2023 that may be closed by this pull request
Copy link
Collaborator

@talex5 talex5 left a comment

Choose a reason for hiding this comment

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

Seems like socket options could be useful on non-Unix systems too. We could define the type in Eio.Net as an extensible variant and put the common ones there, adding Unix specific ones in Eio_unix.Net, etc. Would have to decide what to do about unsupported options.

lib_eio/unix/eio_unix.mli Outdated Show resolved Hide resolved
lib_eio/unix/eio_unix.mli Outdated Show resolved Hide resolved
@avsm
Copy link
Contributor Author

avsm commented Jul 12, 2023

Seems like socket options could be useful on non-Unix systems too. We could define the type in Eio.Net as an extensible variant and put the common ones there, adding Unix specific ones in Eio_unix.Net, etc. Would have to decide what to do about unsupported options.

SGTM. Right now, if a given sockopt isn't defined, it becomes (-1) and a call to it raises EINVAL (similar behaviour to the OCaml Unix module).

I'll move the common definitions that work on Windows as well to Eio.Net, and then put the remaining ones in Eio_unix.

@talex5
Copy link
Collaborator

talex5 commented Oct 2, 2024

In #322, @create2000 is asking about helping to finish this. Are we happy with the current design? What needs to happen beyond rebasing it?

It looks to me like some of the options (those not specific to Unix) should move to Eio.Net (e.g. TCP_NODELAY would also make sense in a unikernel). Possibly all the options should move there; it's OK to talk about an option, even if it's not supported.

Possibly eio_unix should define e.g. type _ t += Unix_bool of Unix.socket_bool_option : bool t, so all existing OCaml options can be used.

Might need a way to pass a list of options when connecting or binding (since we do that in one step, and maybe it's too late to set some options by then?). Might want some fancy heterogeneous list to hold them, since they have various types.

@create2000 I don't know if it's a good first issue or not. It uses some fancy types and involves C code. On the other hand, it's mostly done!

@patricoferris
Copy link
Collaborator

Re:design -- my impression is that we should definitely move parts to Eio.Net that are portable, and in this instance perhaps all of the options and add the Unix version to allow for all existing OCaml options to just work. I think we will want to be able to get/set after connecting/binding anyway so this seems like a reasonable chunk of work to have in a single PR (basically what is already here, shuffled around a little)?

Perhaps a follow up PR can work to support options being set at the point of connecting/binding (as you mentioned, this seems very related to #713)?

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.

Support retrieving socket options
4 participants