Skip to content

socket: accept data object in send/receive to reuse buffers#501

Draft
lneto wants to merge 4 commits intomasterfrom
claude_socket
Draft

socket: accept data object in send/receive to reuse buffers#501
lneto wants to merge 4 commits intomasterfrom
claude_socket

Conversation

@lneto
Copy link
Copy Markdown
Contributor

@lneto lneto commented Mar 15, 2026

No description provided.

@lneto lneto marked this pull request as draft March 15, 2026 02:43
@lneto lneto force-pushed the claude_socket branch 3 times, most recently from 3de0968 to e11064f Compare March 15, 2026 12:49
lneto and others added 3 commits March 15, 2026 13:06
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>
Copy link
Copy Markdown
Contributor

@Physic69 Physic69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, LGTM. Thanks ;)

Comment thread lib/luasocket.c
* @raise Error if the send operation fails.
* @see net.aton
*/
static int luasocket_send(lua_State *L)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice to have, smtg like:
sock:send(buf) -- Send entire buffer sock:send(buf, 0, 100) -- Send first 100 bytes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense ;-)

Comment thread lib/luasocket.c
*
* -- 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we trying to trim the documentation for some reason?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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..

Comment thread lib/luadata.h
uint8_t opt;
} luadata_t;


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line ?

Comment thread lib/luasocket.c
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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought, maybe we can have a better error msg when we are using shareable objects...
Can be done in another PR :)

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants