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

[RFC] Implement setsockopt and getsockopt support #2104

Open
Kaiepi opened this Issue Jul 21, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@Kaiepi
Contributor

Kaiepi commented Jul 21, 2018

The Problem

Setting socket options isn't currently possible unless the user's using IO::Socket::INET and a recent version of MoarVM, and requires using NativeCall. This makes for a lot of boilerplate in projects that need to be able to access socket options.

I think nqp::getsockopt and nqp::setsockopt could be added as ops to help solve this:

nqp::getsockopt(int \fd, int \level, int \option --> int) {*} # returns option gotten, if any
nqp::setsockopt(int \fd, int \level, int \option, int \val --> int) {*} # returns option set

To get the options, an op likenqp::getsockopts may be needed if they differ between systems and can't just be made constants:

nqp::getsockopts(--> hash) {*}

With these, option methods could be added to IO::Socket::INET and IO::Socket::Async (once it supports getting its file descriptors).

constant SOL_SOCKET = 0xFFFF;

enum Option (
   SO_DEBUG => 0x0001, 
   # ...
);

# ...

proto method option(Option, Int $?) {*}
multi method option(Option \opt --> Int) {
    my int \ret := nqp::getsockopt(nqp::unbox_i(self.native-descriptor), nqp::unbox_i(SOL_SOCKET), opt);
    nqp::box_i(ret, Int)
}
multi method option(Option \opt, Int \val --> Int) {
    my int \ret := nqp::setsockopt(nqp::unbox_i(self.native-descriptor), nqp::unbox_i(SOL_SOCKET), opt, val);
    nqp::box_i(ret, Int)
}

The problem with this is how should errors be handled? i don't think it'd be a good idea to ignore them like the way I've written this does. Better yet, is it a good idea to have in the language at all for v6.d?

@Kaiepi

This comment has been minimized.

Show comment
Hide comment
@Kaiepi

Kaiepi Aug 7, 2018

Contributor

Since 6.d is getting released so soon, I think it'd be better if this were held off until 6.e.
Does anyone have any comments?

Contributor

Kaiepi commented Aug 7, 2018

Since 6.d is getting released so soon, I think it'd be better if this were held off until 6.e.
Does anyone have any comments?

@zoffixznet

This comment has been minimized.

Show comment
Hide comment
@zoffixznet

zoffixznet Aug 7, 2018

Contributor

I think it'd be better if this were held off until 6.e.

Without commenting on the RFC itself, FYI: unless it violates 6.c spec or has major impact on users, there's no reason to hold off until any language version.

Contributor

zoffixznet commented Aug 7, 2018

I think it'd be better if this were held off until 6.e.

Without commenting on the RFC itself, FYI: unless it violates 6.c spec or has major impact on users, there's no reason to hold off until any language version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment