-
Notifications
You must be signed in to change notification settings - Fork 106
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 support for setting rcvbuf buffer size on a socket #907
Conversation
d196d2a
to
ea77a28
Compare
ea77a28
to
1b951a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also do a rebease before going for merge.
1b951a5
to
7b44a4b
Compare
src/libAtomVM/otp_socket.c
Outdated
ssize_t buffer_size = len == 0 ? (ssize_t) res : MIN((size_t) res, len); | ||
// user-supplied len has higher precedence than the default buffer size, but we also | ||
// want the configured default buffer size to be a lower bound on anything we peek | ||
ssize_t buffer_size = len == 0 ? MIN((size_t) res, rsrc_obj->buf_size) : MIN((size_t) res, len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we doing MIN(len == 0 ? rsrc_obj->buf_size : len, res)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is also a good chance to fix a warning we have:
AtomVM/src/libAtomVM/otp_socket.c:1665:42: warning: operand of ‘?:’ changes signedness from ‘long int’ to ‘long unsigned int’ due to unsignedness of other operand [-Wsign-compare]
1665 | ssize_t buffer_size = len == 0 ? (ssize_t) res : MIN((size_t) res, len);
| ^~~~~~~~~~~~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we doing
MIN(len == 0 ? rsrc_obj->buf_size : len, res)
?
I believe these are equivalent, right? (assuming MIN is commutative) Changed to your version, with changes to address any compiler warnings.
Scanning dependencies of target libAtomVMLinux-x86_64
[ 28%] Building C object src/platforms/generic_unix/lib/CMakeFiles/libAtomVMLinux-x86_64.dir/mapped_file.c.o
[ 28%] Building C object src/platforms/generic_unix/lib/CMakeFiles/libAtomVMLinux-x86_64.dir/platform_defaultatoms.c.o
[ 28%] Building C object src/platforms/generic_unix/lib/CMakeFiles/libAtomVMLinux-x86_64.dir/smp.c.o
[ 28%] Building C object src/platforms/generic_unix/lib/CMakeFiles/libAtomVMLinux-x86_64.dir/platform_nifs.c.o
[ 28%] Building C object src/platforms/generic_unix/lib/CMakeFiles/libAtomVMLinux-x86_64.dir/socket_driver.c.o
[ 28%] Building C object src/platforms/generic_unix/lib/CMakeFiles/libAtomVMLinux-x86_64.dir/otp_socket_platform.c.o
[ 29%] Building C object src/platforms/generic_unix/lib/CMakeFiles/libAtomVMLinux-x86_64.dir/sys.c.o
[ 29%] Building C object src/platforms/generic_unix/lib/CMakeFiles/libAtomVMLinux-x86_64.dir/__/__/__/libAtomVM/inet.c.o
[ 29%] Building C object src/platforms/generic_unix/lib/CMakeFiles/libAtomVMLinux-x86_64.dir/__/__/__/libAtomVM/otp_net.c.o
[ 29%] Building C object src/platforms/generic_unix/lib/CMakeFiles/libAtomVMLinux-x86_64.dir/__/__/__/libAtomVM/otp_socket.c.o
[ 29%] Linking C static library liblibAtomVMLinux-x86_64.a
[ 29%] Built target libAtomVMLinux-x86_64
7b44a4b
to
56f6d31
Compare
369f53c
to
0bfe2af
Compare
src/libAtomVM/otp_socket.c
Outdated
ssize_t buffer_size = len == 0 ? (ssize_t) res : MIN((size_t) res, len); | ||
// user-supplied len has higher precedence than the default buffer size, but we also | ||
// want the configured default buffer size to be a lower bound on anything we peek | ||
ssize_t buffer_size = len == 0 ? MIN((size_t) res, rsrc_obj->buf_size) : MIN((size_t) res, len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we doing MIN(len == 0 ? rsrc_obj->buf_size : len, res)
?
doc/src/programmers-guide.md
Outdated
@@ -1804,12 +1804,14 @@ Currently, the following options are supported: | |||
|------------|--------------|-------------| | |||
| `{socket, reuseaddr}` | `boolean()` | Sets `SO_REUSEADDR` on the socket. | | |||
| `{socket, linger}` | `#{onoff => boolean(), linger => non_neg_integer()}` | Sets `SO_LINGER` on the socekt. | | |||
| `{otp, rcvbuf}` | `non_neg_integer()` | Sets the default buffer size (in bytes) on receive calls. This value is only used if the `Length` parameter of the `socket:recv` family of functions has the value `0`; otherwise, the specified non-zero length in the `socket:recv` takes precendence. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have 0 for this value?
OTP specifies default | integer()>0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what the meaning of default
is? Would that be for the case in which you set the buffer size to be some value, and then want to set it back to default at a later time?
I'd say in that case we either:
- defer implementing that use case (not sure how useful it is) with a TODO
- Add support for setting it back to default, if desired (would be easy to do)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added note to table and TODO in the code. Not sure why CI did not kick off.
0bfe2af
to
c2356cc
Compare
c2356cc
to
29b291a
Compare
Signed-off-by: Fred Dushin <fred@dushin.net>
29b291a
to
5fc7732
Compare
This PR allows users to set the buffer size on receive operations via the
socket:setopt/3
function, using the{otp, rcvbuf}
configuration option.This PR addresses Issue #896
These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later