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

Setting socket buffer sizes #230

Open
fpagliughi opened this issue Oct 13, 2023 · 2 comments
Open

Setting socket buffer sizes #230

fpagliughi opened this issue Oct 13, 2023 · 2 comments
Assignees

Comments

@fpagliughi
Copy link

I've been looking through some C examples for some SocketCAN Netlink communications, and they all seem to set the socket buffer sizes. Like:

int sndbuf = 32768;
int rcvbuf = 1048576;

setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void *)&sndbuf, sizeof(sndbuf));
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void *)&rcvbuf, sizeof(rcvbuf));

Is there a way to do this easily with this library - other than getting the socket file handle and doing it manually with libc functions? If it doesn't already exist, I can give it a try and send over a PR.

@jbaublitz
Copy link
Owner

Hi @fpagliughi, sorry for the delay. I don't support this right now, but this is actually very interesting to me mainly because if we can set the buffer size to a lower value than MAX_NL_LEN, we can simplify some of the parallel buffer code a bit by only allocating buffers that are rcvbuf size. This would also eliminate an environment variable that I thought was a little bit clunky.

Does this mean that the data from .recv() is guaranteed to be less than or equal to rcvbuf?

@jbaublitz jbaublitz added this to the 0.7.0-rc4 milestone Nov 11, 2023
@fpagliughi
Copy link
Author

Honestly, I have no idea. I'm still brand new to Netlink as a whole. I was just going through a number of different C libraries and examples for the SocketCAN use of Netlink to figure out the calls, and all of them set the socket buffer length. Like here:
https://github.com/lalten/libsocketcan/blob/b464485031b6f2a4e53d3ef1b3d405f9ba159c07/src/libsocketcan.c#L305-L307

My random guess was that it was a performance thing to reduce the trips across the user/kernel barrier if you were transferring large amounts of data.

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

No branches or pull requests

2 participants