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 select #160

Closed
wants to merge 8 commits into from
Closed

Conversation

alexispires
Copy link

@alexispires alexispires commented Jan 5, 2020

Allow select to this kind of design:

for i := 1; i > 0; i, _ = conn.Select(&unix.Timeval{}) {
	rmsg, err := conn.Receive()

	if err != nil {
		return fmt.Errorf("Receive: %w", err)
	}

	for _, msg := range rmsg {
		// do something
	}
}

I need this to trying reproduce behaviors of nftables which check with select before doing a recvmsg, example of strace:

select(4, [3], NULL, NULL, {tv_sec=0, tv_usec=0}) = 1 (in [3], left {tv_sec=0, tv_usec=0})
recvmsg(......)
select(4, [3], NULL, NULL, {tv_sec=0, tv_usec=0}) = 1 (in [3], left {tv_sec=0, tv_usec=0})
recvmsg(......)
select(4, [3], NULL, NULL, {tv_sec=0, tv_usec=0}) = 0 (Timeout)

@mdlayher
Copy link
Owner

mdlayher commented Jan 6, 2020

I think it makes more sense to use an API like SyscallConn for this, although I'm also not sure why you wouldn't just let receive wait on the socket since the runtime handles it in an efficient way.

https://godoc.org/github.com/mdlayher/netlink#Conn.SyscallConn

@alexispires
Copy link
Author

I think it makes more sense to use an API like SyscallConn for this, although I'm also not sure why you wouldn't just let receive wait on the socket since the runtime handles it in an efficient way.

https://godoc.org/github.com/mdlayher/netlink#Conn.SyscallConn

Ok it works by using SyscallConn.

I need this to prevent to be blocked by recvmsg because the func which make the syscall need to return some results. As nftables:
http://git.netfilter.org/nftables/tree/src/mnl.c#n349

I think it's better to have it directly in this lib but you can close this PR if you want ;)

@alexispires
Copy link
Author

Related to google/nftables#88

@mdlayher
Copy link
Owner

mdlayher commented Jan 7, 2020

It could be worth pursuing something like this as an internal change to unblock issues like #136, but I don't want to expose this API directly. Will close this, but thanks for your time.

@mdlayher mdlayher closed this Jan 7, 2020
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.

3 participants