-
Notifications
You must be signed in to change notification settings - Fork 198
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
ngx.socket.tcp receive bsd style #33
base: master
Are you sure you want to change the base?
Conversation
@brg-liuwei Seems like your branch fails the Travis CI testing: https://travis-ci.org/openresty/stream-lua-nginx-module/builds/156263654 And also see below in this ticket's web UI. Your branch does not even compile. Will you fix that first? |
@brg-liuwei It is useful and it works well, thank you. |
@mike07026 Ok, I'm very glad to make another PR to lua-nginx-module. I will accomplish it soon, please wait a moment. |
stream { | ||
server { | ||
listen 5678; | ||
content_by_lua_block { |
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.
I think we should make the test as simple as possible to avoid bugs in the test itself. I don't see why the feature requires this complicated is_power_of_two
thing in the first place. Will you just output all the packets received? It does not need to be this convoluted IMHO. Thanks!
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.
I just want to mock a text protocol decoding function using is_power_of_two
. I think it is better to just output all the packets received. I will modify the test case as your advice.
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.
I think do something like echo is better. is_power_of_two is just too heavy!
@doujiang24 @cuiweixie @yangshuxin Will you have a look at this for me? Many thanks! |
I have used the api |
when will those PRs to be merged to master? @agentzh @brg-liuwei |
when will those PRs to be merged to master? @agentzh :) |
@brg-liuwei I suggest adding this feature to ngx_http_lua_module first since we usually sync changes in only one direction (i.e., from |
listen 5678; | ||
content_by_lua_block { | ||
local sock = ngx.req.socket(true) | ||
local data, _ = sock:receive('*b') |
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.
I suggest we handle and log the errors out and loud, so when tests fail, we can easily see any error messages in the test reports. We should do proper error handling in our own tests.
See other existing tests for examples.
end | ||
|
||
data, _ = sock:receive('*b') | ||
if data ~= 'hello world' then |
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.
Instead of doing comparison in the Lua code, we prefer doing the comparison in the tests scaffold when comparing the response body to the expected one. You can see other existing test cases for examples.
Please also fix other tests as well.
@@ -1736,6 +1737,10 @@ ngx_stream_lua_socket_tcp_receive(lua_State *L) | |||
u->input_filter = ngx_stream_lua_socket_read_all; | |||
break; | |||
|
|||
case 'b': |
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.
I think c
is better here? It means "chunks", just like existing a
means "all" and l
means "line". "b" is not very descriptive in terms of its semantics.
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.
Hi, agentzh, I tried to modify code as follows:
case 'c': u->input_filter = ngx_http_lua_socket_read_chunks;
but there is a function named ngx_http_lua_socket_read_chunk
existing in ngx_http_lua_socket_tcp.c
. I'm afraid those names would confuse people who read source code. I hope you give me some good suggestions.
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.
@brg-liuwei Or maybe add a new bsdrecv()
method instead? It will also be a little bit faster I think.
sock:settimeout(100) | ||
assert(sock:connect("127.0.0.1", 5678)) | ||
|
||
sock:send("1") |
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.
Please always do error handling so when things go south, we can easily see error messages in the test report.
Oops! it seems that the #refactor# break all pull codes. @brg-liuwei |
Why didn't I find *b parameter in v0.0.6rc3 version? @brg-liuwei |
I think we are going for the |
I will port the |
Implement bsd style receive('*b') for ngx.socket.tcp, and add a simple test case in file t/137-tcp-socket-receive-bsd-style.t
春哥好,今天看到openresty邮件列表里面有关于BSD风格的receive的讨论,我印象中关于这个主题在邮件列表里面已经多次出现了。因此一时兴起写了实现了这个接口,并附上一个简单的测试文件(对Test::Nginx的语法还不完全了解,所以只写一个最简单的test case)。目前还没有去在openresty的文档中添加使用方法,如果这个PR被接受,我再去补充文档,到时候再提交一个PR。英文学得不好,表达不够native,因此前面仅用一段简单的英语做描述,不知道是否符合规范?希望能得到春哥的指点,谢谢。