-
Notifications
You must be signed in to change notification settings - Fork 59
socket: accept data object in send/receive to reuse buffers #501
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
Draft
lneto
wants to merge
4
commits into
master
Choose a base branch
from
claude_socket
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ff0b56c
socket: accept data object in send/receive to reuse buffers
lneto 1c92b5e
tests/runtime: add socket_data to test send/receive with data objects
lneto 5db772f
socket: sanitize LDoc and fix C99 declarations
lneto cc65b81
fixup! socket: accept data object in send/receive to reuse buffers
lneto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| -- | ||
| -- SPDX-FileCopyrightText: (c) 2026 Ring Zero Desenvolvimento de Software LTDA | ||
| -- SPDX-License-Identifier: MIT OR GPL-2.0-only | ||
| -- | ||
| -- Kernel-side script for the socket_data regression test (see socket_data.sh). | ||
|
|
||
| local socket = require("socket") | ||
| local net = require("net") | ||
| local data = require("data") | ||
|
|
||
| local af = socket.af | ||
| local sock = socket.sock | ||
| local ip = socket.ipproto | ||
| local PORT = 19876 | ||
| local MSG = "hello socket data!" | ||
| local SIZE = #MSG | ||
|
|
||
| local s = socket.new(af.INET, sock.DGRAM, ip.UDP) | ||
| s:bind(net.aton("127.0.0.1"), PORT) | ||
|
|
||
| local sbuf = data.new(SIZE, "single") | ||
| sbuf:setstring(0, MSG) | ||
| local rbuf = data.new(SIZE, "single") | ||
|
|
||
| -- data → data | ||
| s:send(sbuf, net.aton("127.0.0.1"), PORT) | ||
| local n = s:receive(rbuf) | ||
| assert(n == SIZE, "data→data: expected " .. SIZE .. " bytes, got " .. tostring(n)) | ||
| assert(rbuf:getstring(0, n) == MSG, "data→data: content mismatch") | ||
|
|
||
| -- string → data | ||
| s:send(MSG, net.aton("127.0.0.1"), PORT) | ||
| local n2 = s:receive(rbuf) | ||
| assert(n2 == SIZE, "string→data: expected " .. SIZE .. " bytes, got " .. tostring(n2)) | ||
| assert(rbuf:getstring(0, n2) == MSG, "string→data: content mismatch") | ||
|
|
||
| -- data → string | ||
| s:send(sbuf, net.aton("127.0.0.1"), PORT) | ||
| local str = s:receive(SIZE) | ||
| assert(str == MSG, "data→string: content mismatch") | ||
|
|
||
| s:close() | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/bin/bash | ||
| # | ||
| # SPDX-FileCopyrightText: (c) 2026 Ring Zero Desenvolvimento de Software LTDA | ||
| # SPDX-License-Identifier: MIT OR GPL-2.0-only | ||
| # | ||
| # Tests socket send/receive with data objects via a UDP loopback socket. | ||
| # Verifies valid combinations: data→data, string→data, data→string. | ||
| # | ||
| # Usage: sudo bash tests/runtime/socket_data.sh | ||
|
|
||
| SCRIPT="tests/runtime/socket_data" | ||
| MODULE="luasocket" | ||
|
|
||
| source "$(dirname "$(readlink -f "$0")")/../lib.sh" | ||
|
|
||
| cleanup() { lunatik stop "$SCRIPT" 2>/dev/null; } | ||
| trap cleanup EXIT | ||
| cleanup | ||
|
|
||
| ktap_header | ||
| ktap_plan 1 | ||
|
|
||
| cat /sys/module/$MODULE/refcnt > /dev/null 2>&1 || { | ||
| echo "# SKIP: $MODULE not loaded" | ||
| ktap_totals | ||
| exit 0 | ||
| } | ||
|
|
||
| mark_dmesg | ||
|
|
||
| run_script "$SCRIPT" | ||
|
|
||
| check_dmesg || { ktap_totals; exit 1; } | ||
| ktap_pass "socket send/receive with data objects: data→data, string→data, data→string" | ||
|
|
||
| ktap_totals | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| -- | ||
| -- SPDX-FileCopyrightText: (c) 2026 Ring Zero Desenvolvimento de Software LTDA | ||
| -- SPDX-License-Identifier: MIT OR GPL-2.0-only | ||
| -- | ||
| -- Kernel-side script for the socket_data_reject regression test (see socket_data_reject.sh). | ||
|
|
||
| local socket = require("socket") | ||
| local net = require("net") | ||
| local data = require("data") | ||
|
|
||
| local af = socket.af | ||
| local sock = socket.sock | ||
| local ip = socket.ipproto | ||
| local PORT = 19877 | ||
| local SIZE = 16 | ||
|
|
||
| local s = socket.new(af.INET, sock.DGRAM, ip.UDP) | ||
| s:bind(net.aton("127.0.0.1"), PORT) | ||
|
|
||
| -- rejection: wrong-type userdata (socket instead of data) | ||
| local ok, err = pcall(function() s:send(s, net.aton("127.0.0.1"), PORT) end) | ||
| assert(not ok and err:find("bad argument"), "send: wrong type not rejected: " .. tostring(err)) | ||
|
|
||
| local ok2, err2 = pcall(function() s:receive(s) end) | ||
| assert(not ok2 and err2:find("bad argument"), "receive: wrong type not rejected: " .. tostring(err2)) | ||
|
|
||
| -- rejection: non-SINGLE (shared) data | ||
| local shared = data.new(SIZE, "shared") | ||
|
|
||
| local ok3, err3 = pcall(function() s:send(shared, net.aton("127.0.0.1"), PORT) end) | ||
| assert(not ok3 and err3:find("bad argument"), "send: non-SINGLE data not rejected: " .. tostring(err3)) | ||
|
|
||
| local ok4, err4 = pcall(function() s:receive(shared) end) | ||
| assert(not ok4 and err4:find("bad argument"), "receive: non-SINGLE data not rejected: " .. tostring(err4)) | ||
|
|
||
| s:close() | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/bin/bash | ||
| # | ||
| # SPDX-FileCopyrightText: (c) 2026 Ring Zero Desenvolvimento de Software LTDA | ||
| # SPDX-License-Identifier: MIT OR GPL-2.0-only | ||
| # | ||
| # Verifies that socket send/receive reject wrong-type userdata and non-SINGLE | ||
| # data objects with a proper Lua error rather than crashing the kernel. | ||
| # | ||
| # Usage: sudo bash tests/runtime/socket_data_reject.sh | ||
|
|
||
| SCRIPT="tests/runtime/socket_data_reject" | ||
| MODULE="luasocket" | ||
|
|
||
| source "$(dirname "$(readlink -f "$0")")/../lib.sh" | ||
|
|
||
| cleanup() { lunatik stop "$SCRIPT" 2>/dev/null; } | ||
| trap cleanup EXIT | ||
| cleanup | ||
|
|
||
| ktap_header | ||
| ktap_plan 1 | ||
|
|
||
| cat /sys/module/$MODULE/refcnt > /dev/null 2>&1 || { | ||
| echo "# SKIP: $MODULE not loaded" | ||
| ktap_totals | ||
| exit 0 | ||
| } | ||
|
|
||
| mark_dmesg | ||
|
|
||
| run_script "$SCRIPT" | ||
|
|
||
| check_dmesg || { ktap_totals; exit 1; } | ||
| ktap_pass "socket send/receive correctly reject wrong-type and non-SINGLE data" | ||
|
|
||
| ktap_totals | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
extra line ?