-
Notifications
You must be signed in to change notification settings - Fork 204
Add socket udp peek #383
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
Open
aaurizon
wants to merge
4
commits into
openresty:master
Choose a base branch
from
aaurizon:feature/add-socket-udp-peek-cli
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.
Open
Add socket udp peek #383
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7249d48
Add UDP preread socket peek() support and tests
aaurizon f355a0f
Fix UDP socket cleanup handler in peek function
aaurizon 38bdefc
Fix null pointer dereference in UDP socket peek
aaurizon f1f2b44
Add debug logs for UDP socket peek in stream lua
aaurizon 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
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,107 @@ | ||
# vim:set ft= ts=4 sw=4 et fdm=marker: | ||
|
||
use Test::Nginx::Socket::Lua::Stream; | ||
|
||
repeat_each(2); | ||
|
||
plan tests => repeat_each() * (blocks() * 3); | ||
|
||
no_long_string(); | ||
run_tests(); | ||
|
||
__DATA__ | ||
|
||
=== TEST 1: UDP reqsock:peek returns prefix without consuming | ||
--- stream_server_config | ||
preread_by_lua_block { | ||
local sock, err = ngx.req.socket() | ||
if not sock then | ||
ngx.say("no sock: ", err) | ||
return | ||
end | ||
|
||
local p, perr = sock.peek and sock:peek(8) | ||
ngx.say("peek:", p, ", err:", perr) | ||
|
||
local data, rerr = sock:receive() | ||
ngx.say("recv:", data, ", err:", rerr) | ||
} | ||
content_by_lua return; | ||
--- stream_request chop | ||
hello world | ||
--- stream_response | ||
peek:hello wo, err:nil | ||
recv:hello world, err:nil | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 2: two consecutive peeks return same bytes | ||
--- stream_server_config | ||
preread_by_lua_block { | ||
local sock = ngx.req.socket() | ||
local p1 = sock:peek(8) | ||
local p2 = sock:peek(8) | ||
ngx.say(p1 .. "|" .. p2) | ||
} | ||
content_by_lua return; | ||
--- stream_request chop | ||
abcdefghijk | ||
--- stream_response | ||
abcdefgh|abcdefgh | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 3: peek after receive() raises error | ||
--- stream_server_config | ||
preread_by_lua_block { | ||
local sock = ngx.req.socket() | ||
local d = sock:receive(3) | ||
local ok, err = pcall(function() return sock:peek(1) end) | ||
ngx.say("ok=", ok, ", err=", err) | ||
} | ||
content_by_lua return; | ||
--- stream_request chop | ||
xyz | ||
--- stream_response_like | ||
^ok=false, err=attempt to peek on a consumed socket | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 4: timeout behavior (peek waits then times out) | ||
--- SKIP: requires partial sends in harness | ||
--- stream_server_config | ||
preread_by_lua_block { | ||
local sock = ngx.req.socket() | ||
local ok, err = pcall(function() return sock:peek(8) end) | ||
ngx.say("ok:", ok, ", err:", err) | ||
} | ||
content_by_lua return; | ||
--- stream_request chop | ||
hi | ||
--- stream_response_like | ||
^ok:false, err:.*timeout | ||
|
||
|
||
|
||
=== TEST 5: buffer full behavior (peek errors when exceeded) | ||
--- SKIP: requires controlled preread_buffer_size in harness | ||
--- stream_config | ||
preread_buffer_size 8; | ||
--- stream_server_config | ||
preread_by_lua_block { | ||
local sock = ngx.req.socket() | ||
local ok, err = pcall(function() return sock:peek(16) end) | ||
ngx.say("ok:", ok, ", err:", err) | ||
} | ||
content_by_lua return; | ||
--- stream_request chop | ||
abcdefghijklmnop | ||
--- stream_response_like | ||
^ok:false, err:.*buffer.* | ||
|
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.
If there are multiple udp packets in the same stream, will peak available in every packet?