socket: accept data object in send/receive to reuse buffers#501
Draft
socket: accept data object in send/receive to reuse buffers#501
Conversation
3de0968 to
e11064f
Compare
sock:send(data [, addr]) -- sends data->ptr/size, no string alloc sock:receive(data [, flags [, from]]) -- receives into data->ptr, returns bytes String path is preserved for backward compatibility. luadata_t is moved to luadata.h and luadata_arg() added for cross-module use. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Verifies all send/receive combinations via UDP loopback: data → data, string → data, data → string. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Trim verbose LDoc in module header, send, receive, bind, listen, connect, getsockname, getpeername, close, accept, and new to concise descriptions. Fix C99 issues: remove uninitialized size_t len from send/receive by scoping it inside the else branch and using vec.iov_len directly in the kernel calls; refactor pushaddr to use early returns and eliminate int n; fix double semicolon in checkaddr AF_PACKET branch. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Physic69
reviewed
Mar 21, 2026
| * @raise Error if the send operation fails. | ||
| * @see net.aton | ||
| */ | ||
| static int luasocket_send(lua_State *L) |
Contributor
There was a problem hiding this comment.
it would be nice to have, smtg like:
sock:send(buf) -- Send entire buffer sock:send(buf, 0, 100) -- Send first 100 bytes
| * | ||
| * -- For a UDP socket (sending to 192.168.1.100, port 1234): | ||
| * local bytes_sent = udp_sock:send("UDP packet", net.aton("192.168.1.100"), 1234) | ||
| * @raise Error if the send operation fails. |
Contributor
There was a problem hiding this comment.
Are we trying to trim the documentation for some reason?
Contributor
Author
There was a problem hiding this comment.
Yup.. trying to clean up it a bit.. making it more concise.. mainly to improve code readability.. too much noise now.. if we do need more extensive documentation, we could have a separate file..
| uint8_t opt; | ||
| } luadata_t; | ||
|
|
||
|
|
Physic69
reviewed
Mar 21, 2026
| vec.iov_base = (void *)luaL_checklstring(L, 2, &len); | ||
| vec.iov_len = len; | ||
| if (lua_isuserdata(L, 2)) { | ||
| luadata_t *data = lunatik_checkclass(L, 2, "data", LUNATIK_OPT_SINGLE)->private; |
Contributor
There was a problem hiding this comment.
Just a thought, maybe we can have a better error msg when we are using shareable objects...
Can be done in another PR :)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.