From 535f365e4a2a279cf180366f84ca0da9b0a44784 Mon Sep 17 00:00:00 2001 From: cengwenyuan Date: Wed, 21 Aug 2024 20:00:46 +0800 Subject: [PATCH 1/8] feature: support udp large packet segmentation to send multiple times , each time to send need "zero" copy on the Lua land. --- README.markdown | 450 ++++++++++++++++++++++------------ src/ngx_http_lua_socket_udp.c | 139 ++++++++++- t/189-udp-buff.t | 59 +++++ 3 files changed, 491 insertions(+), 157 deletions(-) create mode 100644 t/189-udp-buff.t diff --git a/README.markdown b/README.markdown index 29a81c1ca4..396992aae5 100644 --- a/README.markdown +++ b/README.markdown @@ -3641,160 +3641,282 @@ The pool is global at Nginx worker level. And it is used to reuse Lua VMs betwee Nginx API for Lua ================= -* [Introduction](#introduction) -* [ngx.arg](#ngxarg) -* [ngx.var.VARIABLE](#ngxvarvariable) -* [Core constants](#core-constants) -* [HTTP method constants](#http-method-constants) -* [HTTP status constants](#http-status-constants) -* [Nginx log level constants](#nginx-log-level-constants) -* [print](#print) -* [ngx.ctx](#ngxctx) -* [ngx.location.capture](#ngxlocationcapture) -* [ngx.location.capture_multi](#ngxlocationcapture_multi) -* [ngx.status](#ngxstatus) -* [ngx.header.HEADER](#ngxheaderheader) -* [ngx.resp.get_headers](#ngxrespget_headers) -* [ngx.req.is_internal](#ngxreqis_internal) -* [ngx.req.start_time](#ngxreqstart_time) -* [ngx.req.http_version](#ngxreqhttp_version) -* [ngx.req.raw_header](#ngxreqraw_header) -* [ngx.req.get_method](#ngxreqget_method) -* [ngx.req.set_method](#ngxreqset_method) -* [ngx.req.set_uri](#ngxreqset_uri) -* [ngx.req.set_uri_args](#ngxreqset_uri_args) -* [ngx.req.get_uri_args](#ngxreqget_uri_args) -* [ngx.req.get_post_args](#ngxreqget_post_args) -* [ngx.req.get_headers](#ngxreqget_headers) -* [ngx.req.set_header](#ngxreqset_header) -* [ngx.req.clear_header](#ngxreqclear_header) -* [ngx.req.read_body](#ngxreqread_body) -* [ngx.req.discard_body](#ngxreqdiscard_body) -* [ngx.req.get_body_data](#ngxreqget_body_data) -* [ngx.req.get_body_file](#ngxreqget_body_file) -* [ngx.req.set_body_data](#ngxreqset_body_data) -* [ngx.req.set_body_file](#ngxreqset_body_file) -* [ngx.req.init_body](#ngxreqinit_body) -* [ngx.req.append_body](#ngxreqappend_body) -* [ngx.req.finish_body](#ngxreqfinish_body) -* [ngx.req.socket](#ngxreqsocket) -* [ngx.exec](#ngxexec) -* [ngx.redirect](#ngxredirect) -* [ngx.send_headers](#ngxsend_headers) -* [ngx.headers_sent](#ngxheaders_sent) -* [ngx.print](#ngxprint) -* [ngx.say](#ngxsay) -* [ngx.log](#ngxlog) -* [ngx.flush](#ngxflush) -* [ngx.exit](#ngxexit) -* [ngx.eof](#ngxeof) -* [ngx.sleep](#ngxsleep) -* [ngx.escape_uri](#ngxescape_uri) -* [ngx.unescape_uri](#ngxunescape_uri) -* [ngx.encode_args](#ngxencode_args) -* [ngx.decode_args](#ngxdecode_args) -* [ngx.encode_base64](#ngxencode_base64) -* [ngx.decode_base64](#ngxdecode_base64) -* [ngx.crc32_short](#ngxcrc32_short) -* [ngx.crc32_long](#ngxcrc32_long) -* [ngx.hmac_sha1](#ngxhmac_sha1) -* [ngx.md5](#ngxmd5) -* [ngx.md5_bin](#ngxmd5_bin) -* [ngx.sha1_bin](#ngxsha1_bin) -* [ngx.quote_sql_str](#ngxquote_sql_str) -* [ngx.today](#ngxtoday) -* [ngx.time](#ngxtime) -* [ngx.now](#ngxnow) -* [ngx.update_time](#ngxupdate_time) -* [ngx.localtime](#ngxlocaltime) -* [ngx.utctime](#ngxutctime) -* [ngx.cookie_time](#ngxcookie_time) -* [ngx.http_time](#ngxhttp_time) -* [ngx.parse_http_time](#ngxparse_http_time) -* [ngx.is_subrequest](#ngxis_subrequest) -* [ngx.re.match](#ngxrematch) -* [ngx.re.find](#ngxrefind) -* [ngx.re.gmatch](#ngxregmatch) -* [ngx.re.sub](#ngxresub) -* [ngx.re.gsub](#ngxregsub) -* [ngx.shared.DICT](#ngxshareddict) -* [ngx.shared.DICT.get](#ngxshareddictget) -* [ngx.shared.DICT.get_stale](#ngxshareddictget_stale) -* [ngx.shared.DICT.set](#ngxshareddictset) -* [ngx.shared.DICT.safe_set](#ngxshareddictsafe_set) -* [ngx.shared.DICT.add](#ngxshareddictadd) -* [ngx.shared.DICT.safe_add](#ngxshareddictsafe_add) -* [ngx.shared.DICT.replace](#ngxshareddictreplace) -* [ngx.shared.DICT.delete](#ngxshareddictdelete) -* [ngx.shared.DICT.incr](#ngxshareddictincr) -* [ngx.shared.DICT.lpush](#ngxshareddictlpush) -* [ngx.shared.DICT.rpush](#ngxshareddictrpush) -* [ngx.shared.DICT.lpop](#ngxshareddictlpop) -* [ngx.shared.DICT.rpop](#ngxshareddictrpop) -* [ngx.shared.DICT.llen](#ngxshareddictllen) -* [ngx.shared.DICT.ttl](#ngxshareddictttl) -* [ngx.shared.DICT.expire](#ngxshareddictexpire) -* [ngx.shared.DICT.flush_all](#ngxshareddictflush_all) -* [ngx.shared.DICT.flush_expired](#ngxshareddictflush_expired) -* [ngx.shared.DICT.get_keys](#ngxshareddictget_keys) -* [ngx.shared.DICT.capacity](#ngxshareddictcapacity) -* [ngx.shared.DICT.free_space](#ngxshareddictfree_space) -* [ngx.socket.udp](#ngxsocketudp) -* [udpsock:bind](#udpsockbind) -* [udpsock:setpeername](#udpsocksetpeername) -* [udpsock:send](#udpsocksend) -* [udpsock:receive](#udpsockreceive) -* [udpsock:close](#udpsockclose) -* [udpsock:settimeout](#udpsocksettimeout) -* [ngx.socket.stream](#ngxsocketstream) -* [ngx.socket.tcp](#ngxsockettcp) -* [tcpsock:bind](#tcpsockbind) -* [tcpsock:connect](#tcpsockconnect) -* [tcpsock:setclientcert](#tcpsocksetclientcert) -* [tcpsock:sslhandshake](#tcpsocksslhandshake) -* [tcpsock:send](#tcpsocksend) -* [tcpsock:receive](#tcpsockreceive) -* [tcpsock:receiveany](#tcpsockreceiveany) -* [tcpsock:receiveuntil](#tcpsockreceiveuntil) -* [tcpsock:close](#tcpsockclose) -* [tcpsock:settimeout](#tcpsocksettimeout) -* [tcpsock:settimeouts](#tcpsocksettimeouts) -* [tcpsock:setoption](#tcpsocksetoption) -* [tcpsock:setkeepalive](#tcpsocksetkeepalive) -* [tcpsock:getreusedtimes](#tcpsockgetreusedtimes) -* [ngx.socket.connect](#ngxsocketconnect) -* [ngx.get_phase](#ngxget_phase) -* [ngx.thread.spawn](#ngxthreadspawn) -* [ngx.thread.wait](#ngxthreadwait) -* [ngx.thread.kill](#ngxthreadkill) -* [ngx.on_abort](#ngxon_abort) -* [ngx.timer.at](#ngxtimerat) -* [ngx.timer.every](#ngxtimerevery) -* [ngx.timer.running_count](#ngxtimerrunning_count) -* [ngx.timer.pending_count](#ngxtimerpending_count) -* [ngx.config.subsystem](#ngxconfigsubsystem) -* [ngx.config.debug](#ngxconfigdebug) -* [ngx.config.prefix](#ngxconfigprefix) -* [ngx.config.nginx_version](#ngxconfignginx_version) -* [ngx.config.nginx_configure](#ngxconfignginx_configure) -* [ngx.config.ngx_lua_version](#ngxconfigngx_lua_version) -* [ngx.worker.exiting](#ngxworkerexiting) -* [ngx.worker.pid](#ngxworkerpid) -* [ngx.worker.pids](#ngxworkerpids) -* [ngx.worker.count](#ngxworkercount) -* [ngx.worker.id](#ngxworkerid) -* [ngx.semaphore](#ngxsemaphore) -* [ngx.balancer](#ngxbalancer) -* [ngx.ssl](#ngxssl) -* [ngx.ocsp](#ngxocsp) -* [ndk.set_var.DIRECTIVE](#ndkset_vardirective) -* [coroutine.create](#coroutinecreate) -* [coroutine.resume](#coroutineresume) -* [coroutine.yield](#coroutineyield) -* [coroutine.wrap](#coroutinewrap) -* [coroutine.running](#coroutinerunning) -* [coroutine.status](#coroutinestatus) -* [ngx.run_worker_thread](#ngxrun_worker_thread) +- [Name](#name) +- [Table of Contents](#table-of-contents) +- [Status](#status) +- [Version](#version) +- [Videos](#videos) +- [Synopsis](#synopsis) +- [Description](#description) +- [Typical Uses](#typical-uses) +- [Nginx Compatibility](#nginx-compatibility) +- [Installation](#installation) + - [Building as a dynamic module](#building-as-a-dynamic-module) + - [C Macro Configurations](#c-macro-configurations) +- [Community](#community) + - [English Mailing List](#english-mailing-list) + - [Chinese Mailing List](#chinese-mailing-list) +- [Code Repository](#code-repository) +- [Bugs and Patches](#bugs-and-patches) +- [LuaJIT bytecode support](#luajit-bytecode-support) +- [System Environment Variable Support](#system-environment-variable-support) +- [HTTP 1.0 support](#http-10-support) +- [Statically Linking Pure Lua Modules](#statically-linking-pure-lua-modules) +- [Data Sharing within an Nginx Worker](#data-sharing-within-an-nginx-worker) +- [Known Issues](#known-issues) + - [TCP socket connect operation issues](#tcp-socket-connect-operation-issues) + - [Lua Coroutine Yielding/Resuming](#lua-coroutine-yieldingresuming) + - [Lua Variable Scope](#lua-variable-scope) + - [Locations Configured by Subrequest Directives of Other Modules](#locations-configured-by-subrequest-directives-of-other-modules) + - [Cosockets Not Available Everywhere](#cosockets-not-available-everywhere) + - [Special Escaping Sequences](#special-escaping-sequences) + - [Mixing with SSI Not Supported](#mixing-with-ssi-not-supported) + - [SPDY Mode Not Fully Supported](#spdy-mode-not-fully-supported) + - [Missing data on short circuited requests](#missing-data-on-short-circuited-requests) +- [TODO](#todo) +- [Changes](#changes) +- [Test Suite](#test-suite) +- [Copyright and License](#copyright-and-license) +- [See Also](#see-also) +- [Directives](#directives) + - [lua\_load\_resty\_core](#lua_load_resty_core) + - [lua\_capture\_error\_log](#lua_capture_error_log) + - [lua\_use\_default\_type](#lua_use_default_type) + - [lua\_malloc\_trim](#lua_malloc_trim) + - [lua\_code\_cache](#lua_code_cache) + - [lua\_thread\_cache\_max\_entries](#lua_thread_cache_max_entries) + - [lua\_regex\_cache\_max\_entries](#lua_regex_cache_max_entries) + - [lua\_regex\_match\_limit](#lua_regex_match_limit) + - [lua\_package\_path](#lua_package_path) + - [lua\_package\_cpath](#lua_package_cpath) + - [init\_by\_lua](#init_by_lua) + - [init\_by\_lua\_block](#init_by_lua_block) + - [init\_by\_lua\_file](#init_by_lua_file) + - [init\_worker\_by\_lua](#init_worker_by_lua) + - [init\_worker\_by\_lua\_block](#init_worker_by_lua_block) + - [init\_worker\_by\_lua\_file](#init_worker_by_lua_file) + - [exit\_worker\_by\_lua\_block](#exit_worker_by_lua_block) + - [exit\_worker\_by\_lua\_file](#exit_worker_by_lua_file) + - [set\_by\_lua](#set_by_lua) + - [set\_by\_lua\_block](#set_by_lua_block) + - [set\_by\_lua\_file](#set_by_lua_file) + - [content\_by\_lua](#content_by_lua) + - [content\_by\_lua\_block](#content_by_lua_block) + - [content\_by\_lua\_file](#content_by_lua_file) + - [server\_rewrite\_by\_lua\_block](#server_rewrite_by_lua_block) + - [server\_rewrite\_by\_lua\_file](#server_rewrite_by_lua_file) + - [rewrite\_by\_lua](#rewrite_by_lua) + - [rewrite\_by\_lua\_block](#rewrite_by_lua_block) + - [rewrite\_by\_lua\_file](#rewrite_by_lua_file) + - [access\_by\_lua](#access_by_lua) + - [access\_by\_lua\_block](#access_by_lua_block) + - [access\_by\_lua\_file](#access_by_lua_file) + - [header\_filter\_by\_lua](#header_filter_by_lua) + - [header\_filter\_by\_lua\_block](#header_filter_by_lua_block) + - [header\_filter\_by\_lua\_file](#header_filter_by_lua_file) + - [body\_filter\_by\_lua](#body_filter_by_lua) + - [body\_filter\_by\_lua\_block](#body_filter_by_lua_block) + - [body\_filter\_by\_lua\_file](#body_filter_by_lua_file) + - [log\_by\_lua](#log_by_lua) + - [log\_by\_lua\_block](#log_by_lua_block) + - [log\_by\_lua\_file](#log_by_lua_file) + - [balancer\_by\_lua\_block](#balancer_by_lua_block) + - [balancer\_by\_lua\_file](#balancer_by_lua_file) + - [balancer\_keepalive](#balancer_keepalive) + - [lua\_need\_request\_body](#lua_need_request_body) + - [ssl\_client\_hello\_by\_lua\_block](#ssl_client_hello_by_lua_block) + - [ssl\_client\_hello\_by\_lua\_file](#ssl_client_hello_by_lua_file) + - [ssl\_certificate\_by\_lua\_block](#ssl_certificate_by_lua_block) + - [ssl\_certificate\_by\_lua\_file](#ssl_certificate_by_lua_file) + - [ssl\_session\_fetch\_by\_lua\_block](#ssl_session_fetch_by_lua_block) + - [ssl\_session\_fetch\_by\_lua\_file](#ssl_session_fetch_by_lua_file) + - [ssl\_session\_store\_by\_lua\_block](#ssl_session_store_by_lua_block) + - [ssl\_session\_store\_by\_lua\_file](#ssl_session_store_by_lua_file) + - [lua\_shared\_dict](#lua_shared_dict) + - [lua\_socket\_connect\_timeout](#lua_socket_connect_timeout) + - [lua\_socket\_send\_timeout](#lua_socket_send_timeout) + - [lua\_socket\_send\_lowat](#lua_socket_send_lowat) + - [lua\_socket\_read\_timeout](#lua_socket_read_timeout) + - [lua\_socket\_buffer\_size](#lua_socket_buffer_size) + - [lua\_socket\_pool\_size](#lua_socket_pool_size) + - [lua\_socket\_keepalive\_timeout](#lua_socket_keepalive_timeout) + - [lua\_socket\_log\_errors](#lua_socket_log_errors) + - [lua\_ssl\_ciphers](#lua_ssl_ciphers) + - [lua\_ssl\_crl](#lua_ssl_crl) + - [lua\_ssl\_protocols](#lua_ssl_protocols) + - [lua\_ssl\_certificate](#lua_ssl_certificate) + - [lua\_ssl\_certificate\_key](#lua_ssl_certificate_key) + - [lua\_ssl\_trusted\_certificate](#lua_ssl_trusted_certificate) + - [lua\_ssl\_verify\_depth](#lua_ssl_verify_depth) + - [lua\_ssl\_conf\_command](#lua_ssl_conf_command) + - [lua\_http10\_buffering](#lua_http10_buffering) + - [rewrite\_by\_lua\_no\_postpone](#rewrite_by_lua_no_postpone) + - [access\_by\_lua\_no\_postpone](#access_by_lua_no_postpone) + - [lua\_transform\_underscores\_in\_response\_headers](#lua_transform_underscores_in_response_headers) + - [lua\_check\_client\_abort](#lua_check_client_abort) + - [lua\_max\_pending\_timers](#lua_max_pending_timers) + - [lua\_max\_running\_timers](#lua_max_running_timers) + - [lua\_sa\_restart](#lua_sa_restart) + - [lua\_worker\_thread\_vm\_pool\_size](#lua_worker_thread_vm_pool_size) +- [Nginx API for Lua](#nginx-api-for-lua) + - [Introduction](#introduction) + - [ngx.arg](#ngxarg) + - [ngx.var.VARIABLE](#ngxvarvariable) + - [Core constants](#core-constants) + - [HTTP method constants](#http-method-constants) + - [HTTP status constants](#http-status-constants) + - [Nginx log level constants](#nginx-log-level-constants) + - [print](#print) + - [ngx.ctx](#ngxctx) + - [ngx.location.capture](#ngxlocationcapture) + - [ngx.location.capture\_multi](#ngxlocationcapture_multi) + - [ngx.status](#ngxstatus) + - [ngx.header.HEADER](#ngxheaderheader) + - [ngx.resp.get\_headers](#ngxrespget_headers) + - [ngx.req.is\_internal](#ngxreqis_internal) + - [ngx.req.start\_time](#ngxreqstart_time) + - [ngx.req.http\_version](#ngxreqhttp_version) + - [ngx.req.raw\_header](#ngxreqraw_header) + - [ngx.req.get\_method](#ngxreqget_method) + - [ngx.req.set\_method](#ngxreqset_method) + - [ngx.req.set\_uri](#ngxreqset_uri) + - [ngx.req.set\_uri\_args](#ngxreqset_uri_args) + - [ngx.req.get\_uri\_args](#ngxreqget_uri_args) + - [ngx.req.get\_post\_args](#ngxreqget_post_args) + - [ngx.req.get\_headers](#ngxreqget_headers) + - [ngx.req.set\_header](#ngxreqset_header) + - [ngx.req.clear\_header](#ngxreqclear_header) + - [ngx.req.read\_body](#ngxreqread_body) + - [ngx.req.discard\_body](#ngxreqdiscard_body) + - [ngx.req.get\_body\_data](#ngxreqget_body_data) + - [ngx.req.get\_body\_file](#ngxreqget_body_file) + - [ngx.req.set\_body\_data](#ngxreqset_body_data) + - [ngx.req.set\_body\_file](#ngxreqset_body_file) + - [ngx.req.init\_body](#ngxreqinit_body) + - [ngx.req.append\_body](#ngxreqappend_body) + - [ngx.req.finish\_body](#ngxreqfinish_body) + - [ngx.req.socket](#ngxreqsocket) + - [ngx.exec](#ngxexec) + - [ngx.redirect](#ngxredirect) + - [ngx.send\_headers](#ngxsend_headers) + - [ngx.headers\_sent](#ngxheaders_sent) + - [ngx.print](#ngxprint) + - [ngx.say](#ngxsay) + - [ngx.log](#ngxlog) + - [ngx.flush](#ngxflush) + - [ngx.exit](#ngxexit) + - [ngx.eof](#ngxeof) + - [ngx.sleep](#ngxsleep) + - [ngx.escape\_uri](#ngxescape_uri) + - [ngx.unescape\_uri](#ngxunescape_uri) + - [ngx.encode\_args](#ngxencode_args) + - [ngx.decode\_args](#ngxdecode_args) + - [ngx.encode\_base64](#ngxencode_base64) + - [ngx.decode\_base64](#ngxdecode_base64) + - [ngx.crc32\_short](#ngxcrc32_short) + - [ngx.crc32\_long](#ngxcrc32_long) + - [ngx.hmac\_sha1](#ngxhmac_sha1) + - [ngx.md5](#ngxmd5) + - [ngx.md5\_bin](#ngxmd5_bin) + - [ngx.sha1\_bin](#ngxsha1_bin) + - [ngx.quote\_sql\_str](#ngxquote_sql_str) + - [ngx.today](#ngxtoday) + - [ngx.time](#ngxtime) + - [ngx.now](#ngxnow) + - [ngx.update\_time](#ngxupdate_time) + - [ngx.localtime](#ngxlocaltime) + - [ngx.utctime](#ngxutctime) + - [ngx.cookie\_time](#ngxcookie_time) + - [ngx.http\_time](#ngxhttp_time) + - [ngx.parse\_http\_time](#ngxparse_http_time) + - [ngx.is\_subrequest](#ngxis_subrequest) + - [ngx.re.match](#ngxrematch) + - [ngx.re.find](#ngxrefind) + - [ngx.re.gmatch](#ngxregmatch) + - [ngx.re.sub](#ngxresub) + - [ngx.re.gsub](#ngxregsub) + - [ngx.shared.DICT](#ngxshareddict) + - [ngx.shared.DICT.get](#ngxshareddictget) + - [ngx.shared.DICT.get\_stale](#ngxshareddictget_stale) + - [ngx.shared.DICT.set](#ngxshareddictset) + - [ngx.shared.DICT.safe\_set](#ngxshareddictsafe_set) + - [ngx.shared.DICT.add](#ngxshareddictadd) + - [ngx.shared.DICT.safe\_add](#ngxshareddictsafe_add) + - [ngx.shared.DICT.replace](#ngxshareddictreplace) + - [ngx.shared.DICT.delete](#ngxshareddictdelete) + - [ngx.shared.DICT.incr](#ngxshareddictincr) + - [ngx.shared.DICT.lpush](#ngxshareddictlpush) + - [ngx.shared.DICT.rpush](#ngxshareddictrpush) + - [ngx.shared.DICT.lpop](#ngxshareddictlpop) + - [ngx.shared.DICT.rpop](#ngxshareddictrpop) + - [ngx.shared.DICT.llen](#ngxshareddictllen) + - [ngx.shared.DICT.ttl](#ngxshareddictttl) + - [ngx.shared.DICT.expire](#ngxshareddictexpire) + - [ngx.shared.DICT.flush\_all](#ngxshareddictflush_all) + - [ngx.shared.DICT.flush\_expired](#ngxshareddictflush_expired) + - [ngx.shared.DICT.get\_keys](#ngxshareddictget_keys) + - [ngx.shared.DICT.capacity](#ngxshareddictcapacity) + - [ngx.shared.DICT.free\_space](#ngxshareddictfree_space) + - [ngx.socket.udp](#ngxsocketudp) + - [udpsock:bind](#udpsockbind) + - [udpsock:setpeername](#udpsocksetpeername) + - [udpsock:send](#udpsocksend) + - [udpsock:sendbuf](#udpsocksendbuf) + - [udpsock:receive](#udpsockreceive) + - [udpsock:close](#udpsockclose) + - [udpsock:settimeout](#udpsocksettimeout) + - [ngx.socket.stream](#ngxsocketstream) + - [ngx.socket.tcp](#ngxsockettcp) + - [tcpsock:bind](#tcpsockbind) + - [tcpsock:connect](#tcpsockconnect) + - [tcpsock:setclientcert](#tcpsocksetclientcert) + - [tcpsock:sslhandshake](#tcpsocksslhandshake) + - [tcpsock:send](#tcpsocksend) + - [tcpsock:receive](#tcpsockreceive) + - [tcpsock:receiveany](#tcpsockreceiveany) + - [tcpsock:receiveuntil](#tcpsockreceiveuntil) + - [tcpsock:close](#tcpsockclose) + - [tcpsock:settimeout](#tcpsocksettimeout) + - [tcpsock:settimeouts](#tcpsocksettimeouts) + - [tcpsock:setoption](#tcpsocksetoption) + - [tcpsock:setkeepalive](#tcpsocksetkeepalive) + - [tcpsock:getreusedtimes](#tcpsockgetreusedtimes) + - [ngx.socket.connect](#ngxsocketconnect) + - [ngx.get\_phase](#ngxget_phase) + - [ngx.thread.spawn](#ngxthreadspawn) + - [ngx.thread.wait](#ngxthreadwait) + - [ngx.thread.kill](#ngxthreadkill) + - [ngx.on\_abort](#ngxon_abort) + - [ngx.timer.at](#ngxtimerat) + - [ngx.timer.every](#ngxtimerevery) + - [ngx.timer.running\_count](#ngxtimerrunning_count) + - [ngx.timer.pending\_count](#ngxtimerpending_count) + - [ngx.config.subsystem](#ngxconfigsubsystem) + - [ngx.config.debug](#ngxconfigdebug) + - [ngx.config.prefix](#ngxconfigprefix) + - [ngx.config.nginx\_version](#ngxconfignginx_version) + - [ngx.config.nginx\_configure](#ngxconfignginx_configure) + - [ngx.config.ngx\_lua\_version](#ngxconfigngx_lua_version) + - [ngx.worker.exiting](#ngxworkerexiting) + - [ngx.worker.pid](#ngxworkerpid) + - [ngx.worker.pids](#ngxworkerpids) + - [ngx.worker.count](#ngxworkercount) + - [ngx.worker.id](#ngxworkerid) + - [ngx.semaphore](#ngxsemaphore) + - [ngx.balancer](#ngxbalancer) + - [ngx.ssl](#ngxssl) + - [ngx.ocsp](#ngxocsp) + - [ndk.set\_var.DIRECTIVE](#ndkset_vardirective) + - [coroutine.create](#coroutinecreate) + - [coroutine.resume](#coroutineresume) + - [coroutine.yield](#coroutineyield) + - [coroutine.wrap](#coroutinewrap) + - [coroutine.running](#coroutinerunning) + - [coroutine.status](#coroutinestatus) + - [ngx.run\_worker\_thread](#ngxrun_worker_thread) +- [Obsolete Sections](#obsolete-sections) + - [Special PCRE Sequences](#special-pcre-sequences) + - [Lua/LuaJIT bytecode support](#lualuajit-bytecode-support) [Back to TOC](#table-of-contents) @@ -7584,6 +7706,7 @@ Creates and returns a UDP or datagram-oriented unix domain socket object (also k * [bind](#udpsockbind) * [setpeername](#udpsocksetpeername) * [send](#udpsocksend) +* [sendbuf](#udpsocksendbuf) * [receive](#udpsockreceive) * [close](#udpsockclose) * [settimeout](#udpsocksettimeout) @@ -7708,6 +7831,21 @@ This feature was first introduced in the `v0.5.7` release. [Back to TOC](#nginx-api-for-lua) +udpsock:sendbuf +--------------- + +**syntax:** *ok, err = udpsock:sendbuf(str1,str2,str3,...,big_str,start,end)* + +**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua** + +Sends data on the current UDP or datagram unix domain socket object. + +In case of success, it returns `1`. Otherwise, it returns `nil` and a string describing the error. + +This method can send udp message without copy or split sub string in Lua land. Usually, in the udp sending scenario, you may have to split the message and send for many times when the string needed to sent is too long, this method will copy all the string elements piece by piece to the underlying Nginx socket send buffers,the copy order is like this: str1,str2,str3,...,big_str[start,end],which usually may helps to improve your system performance. + +[Back to TOC](#nginx-api-for-lua) + udpsock:receive --------------- @@ -8585,8 +8723,8 @@ All the Lua code chunks running by [rewrite_by_lua](#rewrite_by_lua), [access_by By default, the corresponding Nginx handler (e.g., [rewrite_by_lua](#rewrite_by_lua) handler) will not terminate until 1. both the "entry thread" and all the user "light threads" terminates, -1. a "light thread" (either the "entry thread" or a user "light thread") aborts by calling [ngx.exit](#ngxexit), [ngx.exec](#ngxexec), [ngx.redirect](#ngxredirect), or [ngx.req.set_uri(uri, true)](#ngxreqset_uri), or -1. the "entry thread" terminates with a Lua error. +2. a "light thread" (either the "entry thread" or a user "light thread") aborts by calling [ngx.exit](#ngxexit), [ngx.exec](#ngxexec), [ngx.redirect](#ngxredirect), or [ngx.req.set_uri(uri, true)](#ngxreqset_uri), or +3. the "entry thread" terminates with a Lua error. When the user "light thread" terminates with a Lua error, however, it will not abort other running "light threads" like the "entry thread" does. diff --git a/src/ngx_http_lua_socket_udp.c b/src/ngx_http_lua_socket_udp.c index e2ba790fc5..3c3833ddb4 100644 --- a/src/ngx_http_lua_socket_udp.c +++ b/src/ngx_http_lua_socket_udp.c @@ -30,6 +30,7 @@ static int ngx_http_lua_socket_udp(lua_State *L); static int ngx_http_lua_socket_udp_setpeername(lua_State *L); static int ngx_http_lua_socket_udp_send(lua_State *L); +static int ngx_http_lua_socket_udp_buff_send(lua_State *L); static int ngx_http_lua_socket_udp_receive(lua_State *L); static int ngx_http_lua_socket_udp_settimeout(lua_State *L); static void ngx_http_lua_socket_udp_finalize(ngx_http_request_t *r, @@ -86,7 +87,7 @@ ngx_http_lua_inject_socket_udp_api(ngx_log_t *log, lua_State *L) /* udp socket object metatable */ lua_pushlightuserdata(L, ngx_http_lua_lightudata_mask( socket_udp_metatable_key)); - lua_createtable(L, 0 /* narr */, 6 /* nrec */); + lua_createtable(L, 0 /* narr */, 7 /* nrec */); lua_pushcfunction(L, ngx_http_lua_socket_udp_setpeername); lua_setfield(L, -2, "setpeername"); /* ngx socket mt */ @@ -94,6 +95,9 @@ ngx_http_lua_inject_socket_udp_api(ngx_log_t *log, lua_State *L) lua_pushcfunction(L, ngx_http_lua_socket_udp_send); lua_setfield(L, -2, "send"); + lua_pushcfunction(L, ngx_http_lua_socket_udp_buff_send); + lua_setfield(L, -2, "sendbuf"); + lua_pushcfunction(L, ngx_http_lua_socket_udp_receive); lua_setfield(L, -2, "receive"); @@ -961,6 +965,139 @@ ngx_http_lua_socket_udp_send(lua_State *L) } + +#define stack_diff 1 +static int +ngx_http_lua_socket_udp_buff_send(lua_State *L) +{ + ssize_t n; + ngx_http_request_t *r; + ngx_http_lua_socket_udp_upstream_t *u; + ngx_http_lua_loc_conf_t *llcf; + // add new variable for buffer send + ngx_str_t query; + size_t size; + size_t head_len; + size_t buf_len; + u_char *msg_tmp; + const char *header_str; + const char *buff_str; + + + if (lua_gettop(L) < 4 ) { + return luaL_error(L, "expecting at least 4 arguments (including the object), " + "but got %d", lua_gettop(L)); + } + + r = ngx_http_lua_get_req(L); + if (r == NULL) { + return luaL_error(L, "request object not found"); + } + + luaL_checktype(L, 1, LUA_TTABLE); + + lua_rawgeti(L, 1, SOCKET_CTX_INDEX); + u = lua_touserdata(L, -1); + lua_pop(L, 1); + + if (u == NULL || u->udp_connection.connection == NULL) { + llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module); + + if (llcf->log_socket_errors) { + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "attempt to send data on a closed socket: u:%p, c:%p", + u, u ? u->udp_connection.connection : NULL); + } + + lua_pushnil(L); + lua_pushliteral(L, "closed"); + return 2; + } + + if (u->request != r) { + return luaL_error(L, "bad request"); + } + + if (u->ft_type) { + u->ft_type = 0; + } + + if (u->waiting) { + lua_pushnil(L); + lua_pushliteral(L, "socket busy"); + return 2; + } + + // check and calculate string len + int stack_size = lua_gettop(L); + size_t start = luaL_checklong(L, -2); + size_t end = luaL_checklong(L, -1); + buff_str = luaL_checklstring(L, -3, &buf_len); + if (start < 1 || end > buf_len || start > end || start > buf_len) + { + lua_pushnil(L); + lua_pushliteral(L, "start or end index invalid"); + return 2; + } + size = (end - start + 1); + buf_len = size; + if (stack_size > 3 + stack_diff) + { + for (int i = (-1 * stack_size) + stack_diff; i <= -4; i++) + { + luaL_checklstring(L, i, &head_len); + size += head_len; + } + } + // copy msg + query.data = lua_newuserdata(L, size); + query.len = size; + msg_tmp = query.data; + lua_pop(L, 1); + if (stack_size > 3 + stack_diff) + { + for (int i = (-1 * stack_size) + stack_diff; i <= -4; i++) + { + header_str = lua_tolstring(L, i, &head_len); + msg_tmp = ngx_cpymem(msg_tmp, (u_char *)header_str, head_len); + } + } + buff_str = buff_str + start - 1; + ngx_memcpy(msg_tmp, (u_char *)buff_str, buf_len); + + u->ft_type = 0; + + /* mimic ngx_http_upstream_init_request here */ + +#if 1 + u->waiting = 0; +#endif + + dd("sending query %.*s", (int) query.len, query.data); + + n = ngx_send(u->udp_connection.connection, query.data, query.len); + + dd("ngx_send returns %d (query len %d)", (int) n, (int) query.len); + + if (n == NGX_ERROR || n == NGX_AGAIN) { + u->socket_errno = ngx_socket_errno; + + return ngx_http_lua_socket_error_retval_handler(r, u, L); + } + + if (n != (ssize_t) query.len) { + dd("not the while query was sent"); + + u->ft_type |= NGX_HTTP_LUA_SOCKET_FT_PARTIALWRITE; + return ngx_http_lua_socket_error_retval_handler(r, u, L); + } + + dd("n == len"); + + lua_pushinteger(L, 1); + return 1; +} + static int ngx_http_lua_socket_udp_receive(lua_State *L) { diff --git a/t/189-udp-buff.t b/t/189-udp-buff.t new file mode 100644 index 0000000000..d83ead2c86 --- /dev/null +++ b/t/189-udp-buff.t @@ -0,0 +1,59 @@ +# vim:set ft= ts=4 sw=4 et fdm=marker: +our $SkipReason; + +BEGIN { + if ($ENV{TEST_NGINX_CHECK_LEAK}) { + $SkipReason = "unavailable for the hup tests"; + + } else { + $ENV{TEST_NGINX_USE_HUP} = 1; + undef $ENV{TEST_NGINX_USE_STAP}; + } +} + +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() + 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] From cdb5ae64bc004a33156d5eb30ac400c7eb3d30e3 Mon Sep 17 00:00:00 2001 From: cengwenyuan Date: Thu, 22 Aug 2024 09:15:10 +0800 Subject: [PATCH 2/8] Rollback doc commit --- README.markdown | 450 +++++++++++++++++------------------------------- 1 file changed, 156 insertions(+), 294 deletions(-) diff --git a/README.markdown b/README.markdown index 396992aae5..29a81c1ca4 100644 --- a/README.markdown +++ b/README.markdown @@ -3641,282 +3641,160 @@ The pool is global at Nginx worker level. And it is used to reuse Lua VMs betwee Nginx API for Lua ================= -- [Name](#name) -- [Table of Contents](#table-of-contents) -- [Status](#status) -- [Version](#version) -- [Videos](#videos) -- [Synopsis](#synopsis) -- [Description](#description) -- [Typical Uses](#typical-uses) -- [Nginx Compatibility](#nginx-compatibility) -- [Installation](#installation) - - [Building as a dynamic module](#building-as-a-dynamic-module) - - [C Macro Configurations](#c-macro-configurations) -- [Community](#community) - - [English Mailing List](#english-mailing-list) - - [Chinese Mailing List](#chinese-mailing-list) -- [Code Repository](#code-repository) -- [Bugs and Patches](#bugs-and-patches) -- [LuaJIT bytecode support](#luajit-bytecode-support) -- [System Environment Variable Support](#system-environment-variable-support) -- [HTTP 1.0 support](#http-10-support) -- [Statically Linking Pure Lua Modules](#statically-linking-pure-lua-modules) -- [Data Sharing within an Nginx Worker](#data-sharing-within-an-nginx-worker) -- [Known Issues](#known-issues) - - [TCP socket connect operation issues](#tcp-socket-connect-operation-issues) - - [Lua Coroutine Yielding/Resuming](#lua-coroutine-yieldingresuming) - - [Lua Variable Scope](#lua-variable-scope) - - [Locations Configured by Subrequest Directives of Other Modules](#locations-configured-by-subrequest-directives-of-other-modules) - - [Cosockets Not Available Everywhere](#cosockets-not-available-everywhere) - - [Special Escaping Sequences](#special-escaping-sequences) - - [Mixing with SSI Not Supported](#mixing-with-ssi-not-supported) - - [SPDY Mode Not Fully Supported](#spdy-mode-not-fully-supported) - - [Missing data on short circuited requests](#missing-data-on-short-circuited-requests) -- [TODO](#todo) -- [Changes](#changes) -- [Test Suite](#test-suite) -- [Copyright and License](#copyright-and-license) -- [See Also](#see-also) -- [Directives](#directives) - - [lua\_load\_resty\_core](#lua_load_resty_core) - - [lua\_capture\_error\_log](#lua_capture_error_log) - - [lua\_use\_default\_type](#lua_use_default_type) - - [lua\_malloc\_trim](#lua_malloc_trim) - - [lua\_code\_cache](#lua_code_cache) - - [lua\_thread\_cache\_max\_entries](#lua_thread_cache_max_entries) - - [lua\_regex\_cache\_max\_entries](#lua_regex_cache_max_entries) - - [lua\_regex\_match\_limit](#lua_regex_match_limit) - - [lua\_package\_path](#lua_package_path) - - [lua\_package\_cpath](#lua_package_cpath) - - [init\_by\_lua](#init_by_lua) - - [init\_by\_lua\_block](#init_by_lua_block) - - [init\_by\_lua\_file](#init_by_lua_file) - - [init\_worker\_by\_lua](#init_worker_by_lua) - - [init\_worker\_by\_lua\_block](#init_worker_by_lua_block) - - [init\_worker\_by\_lua\_file](#init_worker_by_lua_file) - - [exit\_worker\_by\_lua\_block](#exit_worker_by_lua_block) - - [exit\_worker\_by\_lua\_file](#exit_worker_by_lua_file) - - [set\_by\_lua](#set_by_lua) - - [set\_by\_lua\_block](#set_by_lua_block) - - [set\_by\_lua\_file](#set_by_lua_file) - - [content\_by\_lua](#content_by_lua) - - [content\_by\_lua\_block](#content_by_lua_block) - - [content\_by\_lua\_file](#content_by_lua_file) - - [server\_rewrite\_by\_lua\_block](#server_rewrite_by_lua_block) - - [server\_rewrite\_by\_lua\_file](#server_rewrite_by_lua_file) - - [rewrite\_by\_lua](#rewrite_by_lua) - - [rewrite\_by\_lua\_block](#rewrite_by_lua_block) - - [rewrite\_by\_lua\_file](#rewrite_by_lua_file) - - [access\_by\_lua](#access_by_lua) - - [access\_by\_lua\_block](#access_by_lua_block) - - [access\_by\_lua\_file](#access_by_lua_file) - - [header\_filter\_by\_lua](#header_filter_by_lua) - - [header\_filter\_by\_lua\_block](#header_filter_by_lua_block) - - [header\_filter\_by\_lua\_file](#header_filter_by_lua_file) - - [body\_filter\_by\_lua](#body_filter_by_lua) - - [body\_filter\_by\_lua\_block](#body_filter_by_lua_block) - - [body\_filter\_by\_lua\_file](#body_filter_by_lua_file) - - [log\_by\_lua](#log_by_lua) - - [log\_by\_lua\_block](#log_by_lua_block) - - [log\_by\_lua\_file](#log_by_lua_file) - - [balancer\_by\_lua\_block](#balancer_by_lua_block) - - [balancer\_by\_lua\_file](#balancer_by_lua_file) - - [balancer\_keepalive](#balancer_keepalive) - - [lua\_need\_request\_body](#lua_need_request_body) - - [ssl\_client\_hello\_by\_lua\_block](#ssl_client_hello_by_lua_block) - - [ssl\_client\_hello\_by\_lua\_file](#ssl_client_hello_by_lua_file) - - [ssl\_certificate\_by\_lua\_block](#ssl_certificate_by_lua_block) - - [ssl\_certificate\_by\_lua\_file](#ssl_certificate_by_lua_file) - - [ssl\_session\_fetch\_by\_lua\_block](#ssl_session_fetch_by_lua_block) - - [ssl\_session\_fetch\_by\_lua\_file](#ssl_session_fetch_by_lua_file) - - [ssl\_session\_store\_by\_lua\_block](#ssl_session_store_by_lua_block) - - [ssl\_session\_store\_by\_lua\_file](#ssl_session_store_by_lua_file) - - [lua\_shared\_dict](#lua_shared_dict) - - [lua\_socket\_connect\_timeout](#lua_socket_connect_timeout) - - [lua\_socket\_send\_timeout](#lua_socket_send_timeout) - - [lua\_socket\_send\_lowat](#lua_socket_send_lowat) - - [lua\_socket\_read\_timeout](#lua_socket_read_timeout) - - [lua\_socket\_buffer\_size](#lua_socket_buffer_size) - - [lua\_socket\_pool\_size](#lua_socket_pool_size) - - [lua\_socket\_keepalive\_timeout](#lua_socket_keepalive_timeout) - - [lua\_socket\_log\_errors](#lua_socket_log_errors) - - [lua\_ssl\_ciphers](#lua_ssl_ciphers) - - [lua\_ssl\_crl](#lua_ssl_crl) - - [lua\_ssl\_protocols](#lua_ssl_protocols) - - [lua\_ssl\_certificate](#lua_ssl_certificate) - - [lua\_ssl\_certificate\_key](#lua_ssl_certificate_key) - - [lua\_ssl\_trusted\_certificate](#lua_ssl_trusted_certificate) - - [lua\_ssl\_verify\_depth](#lua_ssl_verify_depth) - - [lua\_ssl\_conf\_command](#lua_ssl_conf_command) - - [lua\_http10\_buffering](#lua_http10_buffering) - - [rewrite\_by\_lua\_no\_postpone](#rewrite_by_lua_no_postpone) - - [access\_by\_lua\_no\_postpone](#access_by_lua_no_postpone) - - [lua\_transform\_underscores\_in\_response\_headers](#lua_transform_underscores_in_response_headers) - - [lua\_check\_client\_abort](#lua_check_client_abort) - - [lua\_max\_pending\_timers](#lua_max_pending_timers) - - [lua\_max\_running\_timers](#lua_max_running_timers) - - [lua\_sa\_restart](#lua_sa_restart) - - [lua\_worker\_thread\_vm\_pool\_size](#lua_worker_thread_vm_pool_size) -- [Nginx API for Lua](#nginx-api-for-lua) - - [Introduction](#introduction) - - [ngx.arg](#ngxarg) - - [ngx.var.VARIABLE](#ngxvarvariable) - - [Core constants](#core-constants) - - [HTTP method constants](#http-method-constants) - - [HTTP status constants](#http-status-constants) - - [Nginx log level constants](#nginx-log-level-constants) - - [print](#print) - - [ngx.ctx](#ngxctx) - - [ngx.location.capture](#ngxlocationcapture) - - [ngx.location.capture\_multi](#ngxlocationcapture_multi) - - [ngx.status](#ngxstatus) - - [ngx.header.HEADER](#ngxheaderheader) - - [ngx.resp.get\_headers](#ngxrespget_headers) - - [ngx.req.is\_internal](#ngxreqis_internal) - - [ngx.req.start\_time](#ngxreqstart_time) - - [ngx.req.http\_version](#ngxreqhttp_version) - - [ngx.req.raw\_header](#ngxreqraw_header) - - [ngx.req.get\_method](#ngxreqget_method) - - [ngx.req.set\_method](#ngxreqset_method) - - [ngx.req.set\_uri](#ngxreqset_uri) - - [ngx.req.set\_uri\_args](#ngxreqset_uri_args) - - [ngx.req.get\_uri\_args](#ngxreqget_uri_args) - - [ngx.req.get\_post\_args](#ngxreqget_post_args) - - [ngx.req.get\_headers](#ngxreqget_headers) - - [ngx.req.set\_header](#ngxreqset_header) - - [ngx.req.clear\_header](#ngxreqclear_header) - - [ngx.req.read\_body](#ngxreqread_body) - - [ngx.req.discard\_body](#ngxreqdiscard_body) - - [ngx.req.get\_body\_data](#ngxreqget_body_data) - - [ngx.req.get\_body\_file](#ngxreqget_body_file) - - [ngx.req.set\_body\_data](#ngxreqset_body_data) - - [ngx.req.set\_body\_file](#ngxreqset_body_file) - - [ngx.req.init\_body](#ngxreqinit_body) - - [ngx.req.append\_body](#ngxreqappend_body) - - [ngx.req.finish\_body](#ngxreqfinish_body) - - [ngx.req.socket](#ngxreqsocket) - - [ngx.exec](#ngxexec) - - [ngx.redirect](#ngxredirect) - - [ngx.send\_headers](#ngxsend_headers) - - [ngx.headers\_sent](#ngxheaders_sent) - - [ngx.print](#ngxprint) - - [ngx.say](#ngxsay) - - [ngx.log](#ngxlog) - - [ngx.flush](#ngxflush) - - [ngx.exit](#ngxexit) - - [ngx.eof](#ngxeof) - - [ngx.sleep](#ngxsleep) - - [ngx.escape\_uri](#ngxescape_uri) - - [ngx.unescape\_uri](#ngxunescape_uri) - - [ngx.encode\_args](#ngxencode_args) - - [ngx.decode\_args](#ngxdecode_args) - - [ngx.encode\_base64](#ngxencode_base64) - - [ngx.decode\_base64](#ngxdecode_base64) - - [ngx.crc32\_short](#ngxcrc32_short) - - [ngx.crc32\_long](#ngxcrc32_long) - - [ngx.hmac\_sha1](#ngxhmac_sha1) - - [ngx.md5](#ngxmd5) - - [ngx.md5\_bin](#ngxmd5_bin) - - [ngx.sha1\_bin](#ngxsha1_bin) - - [ngx.quote\_sql\_str](#ngxquote_sql_str) - - [ngx.today](#ngxtoday) - - [ngx.time](#ngxtime) - - [ngx.now](#ngxnow) - - [ngx.update\_time](#ngxupdate_time) - - [ngx.localtime](#ngxlocaltime) - - [ngx.utctime](#ngxutctime) - - [ngx.cookie\_time](#ngxcookie_time) - - [ngx.http\_time](#ngxhttp_time) - - [ngx.parse\_http\_time](#ngxparse_http_time) - - [ngx.is\_subrequest](#ngxis_subrequest) - - [ngx.re.match](#ngxrematch) - - [ngx.re.find](#ngxrefind) - - [ngx.re.gmatch](#ngxregmatch) - - [ngx.re.sub](#ngxresub) - - [ngx.re.gsub](#ngxregsub) - - [ngx.shared.DICT](#ngxshareddict) - - [ngx.shared.DICT.get](#ngxshareddictget) - - [ngx.shared.DICT.get\_stale](#ngxshareddictget_stale) - - [ngx.shared.DICT.set](#ngxshareddictset) - - [ngx.shared.DICT.safe\_set](#ngxshareddictsafe_set) - - [ngx.shared.DICT.add](#ngxshareddictadd) - - [ngx.shared.DICT.safe\_add](#ngxshareddictsafe_add) - - [ngx.shared.DICT.replace](#ngxshareddictreplace) - - [ngx.shared.DICT.delete](#ngxshareddictdelete) - - [ngx.shared.DICT.incr](#ngxshareddictincr) - - [ngx.shared.DICT.lpush](#ngxshareddictlpush) - - [ngx.shared.DICT.rpush](#ngxshareddictrpush) - - [ngx.shared.DICT.lpop](#ngxshareddictlpop) - - [ngx.shared.DICT.rpop](#ngxshareddictrpop) - - [ngx.shared.DICT.llen](#ngxshareddictllen) - - [ngx.shared.DICT.ttl](#ngxshareddictttl) - - [ngx.shared.DICT.expire](#ngxshareddictexpire) - - [ngx.shared.DICT.flush\_all](#ngxshareddictflush_all) - - [ngx.shared.DICT.flush\_expired](#ngxshareddictflush_expired) - - [ngx.shared.DICT.get\_keys](#ngxshareddictget_keys) - - [ngx.shared.DICT.capacity](#ngxshareddictcapacity) - - [ngx.shared.DICT.free\_space](#ngxshareddictfree_space) - - [ngx.socket.udp](#ngxsocketudp) - - [udpsock:bind](#udpsockbind) - - [udpsock:setpeername](#udpsocksetpeername) - - [udpsock:send](#udpsocksend) - - [udpsock:sendbuf](#udpsocksendbuf) - - [udpsock:receive](#udpsockreceive) - - [udpsock:close](#udpsockclose) - - [udpsock:settimeout](#udpsocksettimeout) - - [ngx.socket.stream](#ngxsocketstream) - - [ngx.socket.tcp](#ngxsockettcp) - - [tcpsock:bind](#tcpsockbind) - - [tcpsock:connect](#tcpsockconnect) - - [tcpsock:setclientcert](#tcpsocksetclientcert) - - [tcpsock:sslhandshake](#tcpsocksslhandshake) - - [tcpsock:send](#tcpsocksend) - - [tcpsock:receive](#tcpsockreceive) - - [tcpsock:receiveany](#tcpsockreceiveany) - - [tcpsock:receiveuntil](#tcpsockreceiveuntil) - - [tcpsock:close](#tcpsockclose) - - [tcpsock:settimeout](#tcpsocksettimeout) - - [tcpsock:settimeouts](#tcpsocksettimeouts) - - [tcpsock:setoption](#tcpsocksetoption) - - [tcpsock:setkeepalive](#tcpsocksetkeepalive) - - [tcpsock:getreusedtimes](#tcpsockgetreusedtimes) - - [ngx.socket.connect](#ngxsocketconnect) - - [ngx.get\_phase](#ngxget_phase) - - [ngx.thread.spawn](#ngxthreadspawn) - - [ngx.thread.wait](#ngxthreadwait) - - [ngx.thread.kill](#ngxthreadkill) - - [ngx.on\_abort](#ngxon_abort) - - [ngx.timer.at](#ngxtimerat) - - [ngx.timer.every](#ngxtimerevery) - - [ngx.timer.running\_count](#ngxtimerrunning_count) - - [ngx.timer.pending\_count](#ngxtimerpending_count) - - [ngx.config.subsystem](#ngxconfigsubsystem) - - [ngx.config.debug](#ngxconfigdebug) - - [ngx.config.prefix](#ngxconfigprefix) - - [ngx.config.nginx\_version](#ngxconfignginx_version) - - [ngx.config.nginx\_configure](#ngxconfignginx_configure) - - [ngx.config.ngx\_lua\_version](#ngxconfigngx_lua_version) - - [ngx.worker.exiting](#ngxworkerexiting) - - [ngx.worker.pid](#ngxworkerpid) - - [ngx.worker.pids](#ngxworkerpids) - - [ngx.worker.count](#ngxworkercount) - - [ngx.worker.id](#ngxworkerid) - - [ngx.semaphore](#ngxsemaphore) - - [ngx.balancer](#ngxbalancer) - - [ngx.ssl](#ngxssl) - - [ngx.ocsp](#ngxocsp) - - [ndk.set\_var.DIRECTIVE](#ndkset_vardirective) - - [coroutine.create](#coroutinecreate) - - [coroutine.resume](#coroutineresume) - - [coroutine.yield](#coroutineyield) - - [coroutine.wrap](#coroutinewrap) - - [coroutine.running](#coroutinerunning) - - [coroutine.status](#coroutinestatus) - - [ngx.run\_worker\_thread](#ngxrun_worker_thread) -- [Obsolete Sections](#obsolete-sections) - - [Special PCRE Sequences](#special-pcre-sequences) - - [Lua/LuaJIT bytecode support](#lualuajit-bytecode-support) +* [Introduction](#introduction) +* [ngx.arg](#ngxarg) +* [ngx.var.VARIABLE](#ngxvarvariable) +* [Core constants](#core-constants) +* [HTTP method constants](#http-method-constants) +* [HTTP status constants](#http-status-constants) +* [Nginx log level constants](#nginx-log-level-constants) +* [print](#print) +* [ngx.ctx](#ngxctx) +* [ngx.location.capture](#ngxlocationcapture) +* [ngx.location.capture_multi](#ngxlocationcapture_multi) +* [ngx.status](#ngxstatus) +* [ngx.header.HEADER](#ngxheaderheader) +* [ngx.resp.get_headers](#ngxrespget_headers) +* [ngx.req.is_internal](#ngxreqis_internal) +* [ngx.req.start_time](#ngxreqstart_time) +* [ngx.req.http_version](#ngxreqhttp_version) +* [ngx.req.raw_header](#ngxreqraw_header) +* [ngx.req.get_method](#ngxreqget_method) +* [ngx.req.set_method](#ngxreqset_method) +* [ngx.req.set_uri](#ngxreqset_uri) +* [ngx.req.set_uri_args](#ngxreqset_uri_args) +* [ngx.req.get_uri_args](#ngxreqget_uri_args) +* [ngx.req.get_post_args](#ngxreqget_post_args) +* [ngx.req.get_headers](#ngxreqget_headers) +* [ngx.req.set_header](#ngxreqset_header) +* [ngx.req.clear_header](#ngxreqclear_header) +* [ngx.req.read_body](#ngxreqread_body) +* [ngx.req.discard_body](#ngxreqdiscard_body) +* [ngx.req.get_body_data](#ngxreqget_body_data) +* [ngx.req.get_body_file](#ngxreqget_body_file) +* [ngx.req.set_body_data](#ngxreqset_body_data) +* [ngx.req.set_body_file](#ngxreqset_body_file) +* [ngx.req.init_body](#ngxreqinit_body) +* [ngx.req.append_body](#ngxreqappend_body) +* [ngx.req.finish_body](#ngxreqfinish_body) +* [ngx.req.socket](#ngxreqsocket) +* [ngx.exec](#ngxexec) +* [ngx.redirect](#ngxredirect) +* [ngx.send_headers](#ngxsend_headers) +* [ngx.headers_sent](#ngxheaders_sent) +* [ngx.print](#ngxprint) +* [ngx.say](#ngxsay) +* [ngx.log](#ngxlog) +* [ngx.flush](#ngxflush) +* [ngx.exit](#ngxexit) +* [ngx.eof](#ngxeof) +* [ngx.sleep](#ngxsleep) +* [ngx.escape_uri](#ngxescape_uri) +* [ngx.unescape_uri](#ngxunescape_uri) +* [ngx.encode_args](#ngxencode_args) +* [ngx.decode_args](#ngxdecode_args) +* [ngx.encode_base64](#ngxencode_base64) +* [ngx.decode_base64](#ngxdecode_base64) +* [ngx.crc32_short](#ngxcrc32_short) +* [ngx.crc32_long](#ngxcrc32_long) +* [ngx.hmac_sha1](#ngxhmac_sha1) +* [ngx.md5](#ngxmd5) +* [ngx.md5_bin](#ngxmd5_bin) +* [ngx.sha1_bin](#ngxsha1_bin) +* [ngx.quote_sql_str](#ngxquote_sql_str) +* [ngx.today](#ngxtoday) +* [ngx.time](#ngxtime) +* [ngx.now](#ngxnow) +* [ngx.update_time](#ngxupdate_time) +* [ngx.localtime](#ngxlocaltime) +* [ngx.utctime](#ngxutctime) +* [ngx.cookie_time](#ngxcookie_time) +* [ngx.http_time](#ngxhttp_time) +* [ngx.parse_http_time](#ngxparse_http_time) +* [ngx.is_subrequest](#ngxis_subrequest) +* [ngx.re.match](#ngxrematch) +* [ngx.re.find](#ngxrefind) +* [ngx.re.gmatch](#ngxregmatch) +* [ngx.re.sub](#ngxresub) +* [ngx.re.gsub](#ngxregsub) +* [ngx.shared.DICT](#ngxshareddict) +* [ngx.shared.DICT.get](#ngxshareddictget) +* [ngx.shared.DICT.get_stale](#ngxshareddictget_stale) +* [ngx.shared.DICT.set](#ngxshareddictset) +* [ngx.shared.DICT.safe_set](#ngxshareddictsafe_set) +* [ngx.shared.DICT.add](#ngxshareddictadd) +* [ngx.shared.DICT.safe_add](#ngxshareddictsafe_add) +* [ngx.shared.DICT.replace](#ngxshareddictreplace) +* [ngx.shared.DICT.delete](#ngxshareddictdelete) +* [ngx.shared.DICT.incr](#ngxshareddictincr) +* [ngx.shared.DICT.lpush](#ngxshareddictlpush) +* [ngx.shared.DICT.rpush](#ngxshareddictrpush) +* [ngx.shared.DICT.lpop](#ngxshareddictlpop) +* [ngx.shared.DICT.rpop](#ngxshareddictrpop) +* [ngx.shared.DICT.llen](#ngxshareddictllen) +* [ngx.shared.DICT.ttl](#ngxshareddictttl) +* [ngx.shared.DICT.expire](#ngxshareddictexpire) +* [ngx.shared.DICT.flush_all](#ngxshareddictflush_all) +* [ngx.shared.DICT.flush_expired](#ngxshareddictflush_expired) +* [ngx.shared.DICT.get_keys](#ngxshareddictget_keys) +* [ngx.shared.DICT.capacity](#ngxshareddictcapacity) +* [ngx.shared.DICT.free_space](#ngxshareddictfree_space) +* [ngx.socket.udp](#ngxsocketudp) +* [udpsock:bind](#udpsockbind) +* [udpsock:setpeername](#udpsocksetpeername) +* [udpsock:send](#udpsocksend) +* [udpsock:receive](#udpsockreceive) +* [udpsock:close](#udpsockclose) +* [udpsock:settimeout](#udpsocksettimeout) +* [ngx.socket.stream](#ngxsocketstream) +* [ngx.socket.tcp](#ngxsockettcp) +* [tcpsock:bind](#tcpsockbind) +* [tcpsock:connect](#tcpsockconnect) +* [tcpsock:setclientcert](#tcpsocksetclientcert) +* [tcpsock:sslhandshake](#tcpsocksslhandshake) +* [tcpsock:send](#tcpsocksend) +* [tcpsock:receive](#tcpsockreceive) +* [tcpsock:receiveany](#tcpsockreceiveany) +* [tcpsock:receiveuntil](#tcpsockreceiveuntil) +* [tcpsock:close](#tcpsockclose) +* [tcpsock:settimeout](#tcpsocksettimeout) +* [tcpsock:settimeouts](#tcpsocksettimeouts) +* [tcpsock:setoption](#tcpsocksetoption) +* [tcpsock:setkeepalive](#tcpsocksetkeepalive) +* [tcpsock:getreusedtimes](#tcpsockgetreusedtimes) +* [ngx.socket.connect](#ngxsocketconnect) +* [ngx.get_phase](#ngxget_phase) +* [ngx.thread.spawn](#ngxthreadspawn) +* [ngx.thread.wait](#ngxthreadwait) +* [ngx.thread.kill](#ngxthreadkill) +* [ngx.on_abort](#ngxon_abort) +* [ngx.timer.at](#ngxtimerat) +* [ngx.timer.every](#ngxtimerevery) +* [ngx.timer.running_count](#ngxtimerrunning_count) +* [ngx.timer.pending_count](#ngxtimerpending_count) +* [ngx.config.subsystem](#ngxconfigsubsystem) +* [ngx.config.debug](#ngxconfigdebug) +* [ngx.config.prefix](#ngxconfigprefix) +* [ngx.config.nginx_version](#ngxconfignginx_version) +* [ngx.config.nginx_configure](#ngxconfignginx_configure) +* [ngx.config.ngx_lua_version](#ngxconfigngx_lua_version) +* [ngx.worker.exiting](#ngxworkerexiting) +* [ngx.worker.pid](#ngxworkerpid) +* [ngx.worker.pids](#ngxworkerpids) +* [ngx.worker.count](#ngxworkercount) +* [ngx.worker.id](#ngxworkerid) +* [ngx.semaphore](#ngxsemaphore) +* [ngx.balancer](#ngxbalancer) +* [ngx.ssl](#ngxssl) +* [ngx.ocsp](#ngxocsp) +* [ndk.set_var.DIRECTIVE](#ndkset_vardirective) +* [coroutine.create](#coroutinecreate) +* [coroutine.resume](#coroutineresume) +* [coroutine.yield](#coroutineyield) +* [coroutine.wrap](#coroutinewrap) +* [coroutine.running](#coroutinerunning) +* [coroutine.status](#coroutinestatus) +* [ngx.run_worker_thread](#ngxrun_worker_thread) [Back to TOC](#table-of-contents) @@ -7706,7 +7584,6 @@ Creates and returns a UDP or datagram-oriented unix domain socket object (also k * [bind](#udpsockbind) * [setpeername](#udpsocksetpeername) * [send](#udpsocksend) -* [sendbuf](#udpsocksendbuf) * [receive](#udpsockreceive) * [close](#udpsockclose) * [settimeout](#udpsocksettimeout) @@ -7831,21 +7708,6 @@ This feature was first introduced in the `v0.5.7` release. [Back to TOC](#nginx-api-for-lua) -udpsock:sendbuf ---------------- - -**syntax:** *ok, err = udpsock:sendbuf(str1,str2,str3,...,big_str,start,end)* - -**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua** - -Sends data on the current UDP or datagram unix domain socket object. - -In case of success, it returns `1`. Otherwise, it returns `nil` and a string describing the error. - -This method can send udp message without copy or split sub string in Lua land. Usually, in the udp sending scenario, you may have to split the message and send for many times when the string needed to sent is too long, this method will copy all the string elements piece by piece to the underlying Nginx socket send buffers,the copy order is like this: str1,str2,str3,...,big_str[start,end],which usually may helps to improve your system performance. - -[Back to TOC](#nginx-api-for-lua) - udpsock:receive --------------- @@ -8723,8 +8585,8 @@ All the Lua code chunks running by [rewrite_by_lua](#rewrite_by_lua), [access_by By default, the corresponding Nginx handler (e.g., [rewrite_by_lua](#rewrite_by_lua) handler) will not terminate until 1. both the "entry thread" and all the user "light threads" terminates, -2. a "light thread" (either the "entry thread" or a user "light thread") aborts by calling [ngx.exit](#ngxexit), [ngx.exec](#ngxexec), [ngx.redirect](#ngxredirect), or [ngx.req.set_uri(uri, true)](#ngxreqset_uri), or -3. the "entry thread" terminates with a Lua error. +1. a "light thread" (either the "entry thread" or a user "light thread") aborts by calling [ngx.exit](#ngxexit), [ngx.exec](#ngxexec), [ngx.redirect](#ngxredirect), or [ngx.req.set_uri(uri, true)](#ngxreqset_uri), or +1. the "entry thread" terminates with a Lua error. When the user "light thread" terminates with a Lua error, however, it will not abort other running "light threads" like the "entry thread" does. From f5e3de5eb7dbce11e63c64e1bfea7cd014936b02 Mon Sep 17 00:00:00 2001 From: coffeei <35646648+coffeei@users.noreply.github.com> Date: Thu, 22 Aug 2024 09:23:07 +0800 Subject: [PATCH 3/8] Update ngx_http_lua_socket_udp.c update error message --- src/ngx_http_lua_socket_udp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ngx_http_lua_socket_udp.c b/src/ngx_http_lua_socket_udp.c index 3c3833ddb4..84bbade206 100644 --- a/src/ngx_http_lua_socket_udp.c +++ b/src/ngx_http_lua_socket_udp.c @@ -985,8 +985,8 @@ ngx_http_lua_socket_udp_buff_send(lua_State *L) if (lua_gettop(L) < 4 ) { - return luaL_error(L, "expecting at least 4 arguments (including the object), " - "but got %d", lua_gettop(L)); + return luaL_error(L, "expecting at least 4 arguments, " + "but got %d (including the object)", lua_gettop(L)); } r = ngx_http_lua_get_req(L); From 0bd6cd69cac3afa2bd16ce0cd818a30940e95524 Mon Sep 17 00:00:00 2001 From: coffeei <35646648+coffeei@users.noreply.github.com> Date: Thu, 22 Aug 2024 09:37:58 +0800 Subject: [PATCH 4/8] Update code format --- src/ngx_http_lua_socket_udp.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ngx_http_lua_socket_udp.c b/src/ngx_http_lua_socket_udp.c index 84bbade206..a6513f6aa6 100644 --- a/src/ngx_http_lua_socket_udp.c +++ b/src/ngx_http_lua_socket_udp.c @@ -965,8 +965,9 @@ ngx_http_lua_socket_udp_send(lua_State *L) } - #define stack_diff 1 + + static int ngx_http_lua_socket_udp_buff_send(lua_State *L) { @@ -1033,14 +1034,17 @@ ngx_http_lua_socket_udp_buff_send(lua_State *L) size_t start = luaL_checklong(L, -2); size_t end = luaL_checklong(L, -1); buff_str = luaL_checklstring(L, -3, &buf_len); + if (start < 1 || end > buf_len || start > end || start > buf_len) { lua_pushnil(L); lua_pushliteral(L, "start or end index invalid"); return 2; } + size = (end - start + 1); buf_len = size; + if (stack_size > 3 + stack_diff) { for (int i = (-1 * stack_size) + stack_diff; i <= -4; i++) @@ -1049,21 +1053,24 @@ ngx_http_lua_socket_udp_buff_send(lua_State *L) size += head_len; } } + // copy msg query.data = lua_newuserdata(L, size); query.len = size; msg_tmp = query.data; lua_pop(L, 1); + if (stack_size > 3 + stack_diff) { for (int i = (-1 * stack_size) + stack_diff; i <= -4; i++) { header_str = lua_tolstring(L, i, &head_len); - msg_tmp = ngx_cpymem(msg_tmp, (u_char *)header_str, head_len); + msg_tmp = ngx_cpymem(msg_tmp, (u_char *) header_str, head_len); } } + buff_str = buff_str + start - 1; - ngx_memcpy(msg_tmp, (u_char *)buff_str, buf_len); + ngx_memcpy(msg_tmp, (u_char *) buff_str, buf_len); u->ft_type = 0; @@ -1098,6 +1105,7 @@ ngx_http_lua_socket_udp_buff_send(lua_State *L) return 1; } + static int ngx_http_lua_socket_udp_receive(lua_State *L) { From 078cf874ba78a781b3beba5baa78421688d3351c Mon Sep 17 00:00:00 2001 From: coffeei <35646648+coffeei@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:04:30 +0800 Subject: [PATCH 5/8] Update code format remove line tailing spaces --- src/ngx_http_lua_socket_udp.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/ngx_http_lua_socket_udp.c b/src/ngx_http_lua_socket_udp.c index a6513f6aa6..e58c1952cb 100644 --- a/src/ngx_http_lua_socket_udp.c +++ b/src/ngx_http_lua_socket_udp.c @@ -1035,8 +1035,7 @@ ngx_http_lua_socket_udp_buff_send(lua_State *L) size_t end = luaL_checklong(L, -1); buff_str = luaL_checklstring(L, -3, &buf_len); - if (start < 1 || end > buf_len || start > end || start > buf_len) - { + if (start < 1 || end > buf_len || start > end || start > buf_len) { lua_pushnil(L); lua_pushliteral(L, "start or end index invalid"); return 2; @@ -1045,10 +1044,8 @@ ngx_http_lua_socket_udp_buff_send(lua_State *L) size = (end - start + 1); buf_len = size; - if (stack_size > 3 + stack_diff) - { - for (int i = (-1 * stack_size) + stack_diff; i <= -4; i++) - { + if (stack_size > 3 + stack_diff) { + for (int i = (-1 * stack_size) + stack_diff; i <= -4; i++) { luaL_checklstring(L, i, &head_len); size += head_len; } @@ -1060,10 +1057,8 @@ ngx_http_lua_socket_udp_buff_send(lua_State *L) msg_tmp = query.data; lua_pop(L, 1); - if (stack_size > 3 + stack_diff) - { - for (int i = (-1 * stack_size) + stack_diff; i <= -4; i++) - { + if (stack_size > 3 + stack_diff) { + for (int i = (-1 * stack_size) + stack_diff; i <= -4; i++) { header_str = lua_tolstring(L, i, &head_len); msg_tmp = ngx_cpymem(msg_tmp, (u_char *) header_str, head_len); } From a71f4a4b08d0bb661a2f0a523722e8dba01826c4 Mon Sep 17 00:00:00 2001 From: coffeei <35646648+coffeei@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:29:33 +0800 Subject: [PATCH 6/8] Update code format remove line tailing spaces --- src/ngx_http_lua_socket_udp.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ngx_http_lua_socket_udp.c b/src/ngx_http_lua_socket_udp.c index e58c1952cb..808ad6ce60 100644 --- a/src/ngx_http_lua_socket_udp.c +++ b/src/ngx_http_lua_socket_udp.c @@ -1034,39 +1034,39 @@ ngx_http_lua_socket_udp_buff_send(lua_State *L) size_t start = luaL_checklong(L, -2); size_t end = luaL_checklong(L, -1); buff_str = luaL_checklstring(L, -3, &buf_len); - + if (start < 1 || end > buf_len || start > end || start > buf_len) { lua_pushnil(L); lua_pushliteral(L, "start or end index invalid"); return 2; } - + size = (end - start + 1); buf_len = size; - + if (stack_size > 3 + stack_diff) { for (int i = (-1 * stack_size) + stack_diff; i <= -4; i++) { luaL_checklstring(L, i, &head_len); size += head_len; } } - + // copy msg query.data = lua_newuserdata(L, size); query.len = size; msg_tmp = query.data; lua_pop(L, 1); - + if (stack_size > 3 + stack_diff) { for (int i = (-1 * stack_size) + stack_diff; i <= -4; i++) { header_str = lua_tolstring(L, i, &head_len); msg_tmp = ngx_cpymem(msg_tmp, (u_char *) header_str, head_len); } } - + buff_str = buff_str + start - 1; ngx_memcpy(msg_tmp, (u_char *) buff_str, buf_len); - + u->ft_type = 0; /* mimic ngx_http_upstream_init_request here */ From f2509157702bb7e0bdce0c8e4e028d9bf25cc42c Mon Sep 17 00:00:00 2001 From: coffeei <35646648+coffeei@users.noreply.github.com> Date: Mon, 26 Aug 2024 09:36:57 +0800 Subject: [PATCH 7/8] Update 189-udp-buff.t --- t/189-udp-buff.t | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/t/189-udp-buff.t b/t/189-udp-buff.t index d83ead2c86..035b09418b 100644 --- a/t/189-udp-buff.t +++ b/t/189-udp-buff.t @@ -1,15 +1,4 @@ # vim:set ft= ts=4 sw=4 et fdm=marker: -our $SkipReason; - -BEGIN { - if ($ENV{TEST_NGINX_CHECK_LEAK}) { - $SkipReason = "unavailable for the hup tests"; - - } else { - $ENV{TEST_NGINX_USE_HUP} = 1; - undef $ENV{TEST_NGINX_USE_STAP}; - } -} use Test::Nginx::Socket::Lua 'no_plan'; From 34a4895e13fd610dfd2dd46296ccb721669b7927 Mon Sep 17 00:00:00 2001 From: coffeei <35646648+coffeei@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:30:58 +0800 Subject: [PATCH 8/8] Update 189-udp-buff.t udpsock settimeout --- t/189-udp-buff.t | 1 + 1 file changed, 1 insertion(+) diff --git a/t/189-udp-buff.t b/t/189-udp-buff.t index 035b09418b..22d63a0d94 100644 --- a/t/189-udp-buff.t +++ b/t/189-udp-buff.t @@ -20,6 +20,7 @@ __DATA__ 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