-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feature: support udp large packet segmentation to send multiple times… #2351
Open
coffeei
wants to merge
8
commits into
openresty:master
Choose a base branch
from
coffeei:master
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
535f365
feature: support udp large packet segmentation to send multiple times…
cdb5ae6
Rollback doc commit
f5e3de5
Update ngx_http_lua_socket_udp.c
coffeei 0bd6cd6
Update code format
coffeei 078cf87
Update code format
coffeei a71f4a4
Update code format
coffeei f250915
Update 189-udp-buff.t
coffeei 34a4895
Update 189-udp-buff.t
coffeei 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 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 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,49 @@ | ||
# vim:set ft= ts=4 sw=4 et fdm=marker: | ||
|
||
use Test::Nginx::Socket::Lua 'no_plan'; | ||
|
||
#worker_connections(1014); | ||
master_on(); | ||
workers(2); | ||
#log_level('warn'); | ||
|
||
repeat_each(2); | ||
|
||
#no_diff(); | ||
no_long_string(); | ||
run_tests(); | ||
|
||
__DATA__ | ||
|
||
=== TEST 1: use udp send buffer | ||
--- config | ||
location /lua { | ||
content_by_lua_block { | ||
local udpsock = ngx.socket.udp() | ||
udpsock:settimeout(500) | ||
local host,port = "127.0.0.1",8080 | ||
local ok, err = udpsock:setpeername(host, port) | ||
if not ok then | ||
ngx.say("============failed to connect to udp server: ", host, ",err:", err) | ||
return | ||
end | ||
local header_binary = "11" | ||
local serial_binary = "22" | ||
local log_msg_content = "3333333312345678901234567890123456789012345678901234567890" | ||
local msgStartIndex = 10 | ||
local msgEndIndex = 20 | ||
ok, err = udpsock:sendbuf(header_binary, serial_binary, log_msg_content, msgStartIndex, msgEndIndex) | ||
if not ok then | ||
ngx.say("============failed to send: ", host, ",err:", err) | ||
return | ||
end | ||
ngx.say("OK") | ||
|
||
} | ||
} | ||
--- request | ||
GET /lua | ||
--- response_body_like | ||
OK | ||
--- no_error_log | ||
[error] |
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.
you should use the string.buffer instead of implement this feature.
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.
how to use string.buffer instead of implement this feature on lua land ,can you give some example? the copy occurs on the c land,but i need to split the big string on the lua land ,and also i need to make the header of the udp package on lua land. if i use the origin udpsock:send() method , sub string ( big_msg ) is inevitable ,.usually i can send big string
use udp like below,there is no need to make a new string pass to c land.
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.
https://luajit.org/ext_buffer.html
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.
Thanks a lot,but we can't assume that from the beginning the user can use string.buffer to build the string content on the lua land ,sometimes is really hard for it , and more scenario is that the user can only accept a large string which was already built before.
I think we still need to copy a string on lua land, event if we use the string buffer.that is because openresty only provides a udp send method which can accepts only a string or table object.
Limited by udp message size , it’s necessary to split an existing big string, so you need to avoid a new large number of substring , The new udp send method that i provided is to adapt to this scenario.
Thank you very much!
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.
gotcha