1 Star 0 Fork 0

kuoyihp/nginx-lua-module-zh-wiki

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
doc
access_by_lua.md
access_by_lua_file.md
body_filter_by_lua.md
body_filter_by_lua_file.md
bugs-and-patches.md
c-macro-configurations.md
changes.md
code-repository.md
content_by_lua.md
content_by_lua_file.md
copyright-and-license.md
core-constants.md
coroutinecreate.md
coroutineresume.md
coroutinerunning.md
coroutinestatus.md
coroutinewrap.md
coroutineyield.md
cosockets-not-available-everywhere.md
data-sharing-within-an-nginx-worker.md
description.md
directives.md
header_filter_by_lua.md
header_filter_by_lua_file.md
http-10-support.md
http-method-constants.md
http-status-constants.md
init_by_lua.md
init_by_lua_file.md
init_worker_by_lua.md
init_worker_by_lua_file.md
installation-on-ubuntu-1110.md
installation.md
introduction.md
locations-configured-by-subrequest-directives-of-other-modules.md
log_by_lua.md
log_by_lua_file.md
lua-code-cache.md
lua-coroutine-yieldingresuming.md
lua-use-default-type.md
lua-variable-scope.md
lua_check_client_abort.md
lua_http10_buffering.md
lua_max_pending_timers.md
lua_max_running_timers.md
lua_need_request_body.md
lua_package_cpath.md
lua_package_path.md
lua_regex_cache_max_entries.md
lua_regex_match_limit.md
lua_shared_dict.md
lua_socket_buffer_size.md
lua_socket_connect_timeout.md
lua_socket_keepalive_timeout.md
lua_socket_log_errors.md
lua_socket_pool_size.md
lua_socket_read_timeout.md
lua_socket_send_lowat.md
lua_socket_send_timeout.md
lua_ssl_ciphers.md
lua_ssl_crl.md
lua_ssl_protocols.md
lua_ssl_trusted_certificate.md
lua_ssl_verify_depth.md
lua_transform_underscores_in_response_headers.md
lualuajit-bytecode-support.md
missing-data-on-short-circuited-requests.md
mixing-with-ssi-not-supported.md
name.md
ndkset_vardirective.md
nginx-api-for-lua.md
nginx-compatibility.md
nginx-log-level-constants.md
ngxarg.md
ngxconfigdebug.md
ngxconfignginx_configure.md
ngxconfignginx_version.md
ngxconfigngx_lua_version.md
ngxconfigprefix.md
ngxcookie_time.md
ngxcrc32_long.md
ngxcrc32_short.md
ngxctx.md
ngxdecode_args.md
ngxdecode_base64.md
ngxencode_args.md
ngxencode_base64.md
ngxeof.md
ngxescape_uri.md
ngxexec.md
ngxexit.md
ngxflush.md
ngxget_phase.md
ngxheaderheader.md
ngxheaders_sent.md
ngxhmac_sha1.md
ngxhttp_time.md
ngxis_subrequest.md
ngxlocaltime.md
ngxlocationcapture.md
ngxlocationcapture_multi.md
ngxlog.md
ngxmd5.md
ngxmd5_bin.md
ngxnow.md
ngxon_abort.md
ngxparse_http_time.md
ngxprint.md
ngxquote_sql_str.md
ngxredirect.md
ngxrefind.md
ngxregmatch.md
ngxregsub.md
ngxrematch.md
ngxreqappend_body.md
ngxreqclear_header.md
ngxreqdiscard_body.md
ngxreqfinish_body.md
ngxreqget_body_data.md
ngxreqget_body_file.md
ngxreqget_headers.md
ngxreqget_method.md
ngxreqget_post_args.md
ngxreqget_uri_args.md
ngxreqhttp_version.md
ngxreqinit_body.md
ngxreqraw_header.md
ngxreqread_body.md
ngxreqset_body_data.md
ngxreqset_body_file.md
ngxreqset_header.md
ngxreqset_method.md
ngxreqset_uri.md
ngxreqset_uri_args.md
ngxreqsocket.md
ngxreqstart_time.md
ngxrespget_headers.md
ngxresub.md
ngxsay.md
ngxsend_headers.md
ngxsha1_bin.md
ngxshareddict.md
ngxshareddictadd.md
ngxshareddictdelete.md
ngxshareddictflush_all.md
ngxshareddictflush_expired.md
ngxshareddictget.md
ngxshareddictget_keys.md
ngxshareddictget_stale.md
ngxshareddictincr.md
ngxshareddictreplace.md
ngxshareddictsafe_add.md
ngxshareddictsafe_set.md
ngxshareddictset.md
ngxsleep.md
ngxsocketconnect.md
ngxsockettcp.md
ngxsocketudp.md
ngxstatus.md
ngxthreadkill.md
ngxthreadspawn.md
ngxthreadwait.md
ngxtime.md
ngxtimerat.md
ngxtoday.md
ngxunescape_uri.md
ngxupdate_time.md
ngxutctime.md
ngxvarvariable.md
ngxworkerexiting.md
ngxworkerpid.md
obsolete-sections.md
print.md
rewrite_by_lua.md
rewrite_by_lua_file.md
rewrite_by_lua_no_postpone.md
see-also.md
set_by_lua.md
set_by_lua_file.md
spdy-mode-not-fully-supported.md
special-escaping-sequences.md
special-pcre-sequences.md
statically-linking-pure-lua-modules.md
status.md
synopsis.md
system-environment-variable-support.md
tcp-socket-connect-operation-issues.md
tcpsockclose.md
tcpsockconnect.md
tcpsockgetreusedtimes.md
tcpsockreceive.md
tcpsockreceiveuntil.md
tcpsocksend.md
tcpsocksetkeepalive.md
tcpsocksetoption.md
tcpsocksettimeout.md
tcpsocksslhandshake.md
test-suite.md
todo.md
typical-uses.md
udpsockclose.md
udpsockreceive.md
udpsocksend.md
udpsocksetpeername.md
udpsocksettimeout.md
README.md
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
tcpsocksend.md 2.77 KB
一键复制 编辑 原始数据 按行查看 历史
王院生 提交于 10年前 . 完成 tcpsock:send 章节

tcpsock:send

语法: bytes, err = tcpsock:send(data)

内容: rewrite_by_lua, access_by_lua*, content_by_lua*, ngx.timer.**

在当前 TCP 或 Unix Domain Socket 连接上非阻塞的发送数据。

该方法是个异步操作,直到 所有 的数据全部被刷写到系统 socket 发送缓冲区或有错误发生,否则不会返回。

成功情况下,返回已经发送数据字节数的总数。其他情况,返回 nil 和错误描述信息。

输入参数 data 可以是 Lua 字符串,也可以是包含字符串的(嵌套)Lua 表。对于输入参数是表的情况,该方法将逐一拷贝所有的字符串对象到底层的 Nginx socket 发送缓冲区,这是比 Lua 层面完成字符串拼接更好的优化方案。

发送操作超时控制,是由 lua_socket_send_timeout 配置指令和 settimeout 方法设置的。而后者有更高的优先级,例如:


 sock:settimeout(1000)  -- one second timeout
 local bytes, err = sock:send(request)

调用这个方法 之前 调用 settimeout 方法设置超时时间,是非常重要的。

一旦有任何错误发生,该方法将自动关闭当前连接。

该特性在 v0.5.0rc1 版本首次引入。

返回目录

English source:

tcpsock:send

syntax: bytes, err = tcpsock:send(data)

context: rewrite_by_lua, access_by_lua*, content_by_lua*, ngx.timer.**

Sends data without blocking on the current TCP or Unix Domain Socket connection.

This method is a synchronous operation that will not return until all the data has been flushed into the system socket send buffer or an error occurs.

In case of success, it returns the total number of bytes that have been sent. Otherwise, it returns nil and a string describing the error.

The input argument data can either be a Lua string or a (nested) Lua table holding string fragments. In case of table arguments, this method will copy all the string elements piece by piece to the underlying Nginx socket send buffers, which is usually optimal than doing string concatenation operations on the Lua land.

Timeout for the sending operation is controlled by the lua_socket_send_timeout config directive and the settimeout method. And the latter takes priority. For example:


 sock:settimeout(1000)  -- one second timeout
 local bytes, err = sock:send(request)

It is important here to call the settimeout method before calling this method.

In case of any connection errors, this method always automatically closes the current connection.

This feature was first introduced in the v0.5.0rc1 release.

Back to TOC

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qizhendong_admin/nginx-lua-module-zh-wiki.git
git@gitee.com:qizhendong_admin/nginx-lua-module-zh-wiki.git
qizhendong_admin
nginx-lua-module-zh-wiki
nginx-lua-module-zh-wiki
master

搜索帮助