Skip to content

Conversation

aaurizon
Copy link

Changes

  • support reqsock:peek for UDP preread sockets
  • document UDP preread peek API
  • add tests for UDP reqsock peek, errors and edge cases

Introduces the peek(N) method for UDP request sockets in the preread phase, allowing inspection of N bytes from the preread buffer without consuming them. Updates the UDP socket implementation, metatable, and state tracking to support this feature. Adds documentation and comprehensive tests for UDP socket peek behavior, including error and edge cases.
Replaces the coroutine cleanup handler from ngx_stream_lua_coctx_cleanup to ngx_stream_lua_udp_socket_cleanup in ngx_stream_lua_req_socket_udp_peek. This ensures proper cleanup specific to UDP socket operations when yielding due to insufficient preread buffer data.
Added a check for NULL buffer before calculating the size in ngx_stream_lua_req_socket_udp_peek_resume to prevent potential null pointer dereference.
Introduces additional debug logging when the UDP socket peek() method is called and updates an existing log message for clarity. This helps with tracing and debugging UDP socket operations in the stream lua module.
@@ -1122,6 +1128,8 @@ ngx_stream_lua_socket_udp_receive(lua_State *L)
r->connection->buffer->pos, u->received);
r->connection->buffer->pos += u->received;

u->read_consumed = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

If there are multiple udp packets in the same stream, will peak available in every packet?

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

Successfully merging this pull request may close these issues.

2 participants