Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

checked in files that are missing in the previous commit for lua_sock…

…et_log_errors.
  • Loading branch information...
commit 93d12de226f946b50cb6d51f382368af95b037e4 1 parent 1efea1b
@agentzh agentzh authored
Showing with 130 additions and 0 deletions.
  1. +30 −0 src/ngx_http_lua_socket.h
  2. +100 −0 t/090-log-socket-errors.t
View
30 src/ngx_http_lua_socket.h
@@ -0,0 +1,30 @@
+#ifndef NGX_HTTP_LUA_SOCKET_H
+#define NGX_HTTP_LUA_SOCKET_H
+
+
+#include "ngx_http_lua_common.h"
+
+
+static ngx_inline void
+ngx_http_lua_socket_log_error(ngx_uint_t level, ngx_http_request_t *r,
+ ngx_err_t err, const char *fmt, ...)
+{
+ ngx_http_lua_loc_conf_t *llcf;
+ ngx_log_t *log;
+ va_list args;
+
+ llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
+
+ if (llcf->log_socket_errors) {
+ log = r->connection->log;
+ if (log->log_level >= level) {
+ va_start(args, fmt);
+ ngx_log_error_core(level, log, err, fmt, args);
+ va_end(args);
+ }
+ }
+}
+
+
+#endif /* NGX_HTTP_LUA_SOCKET_H */
+
View
100 t/090-log-socket-errors.t
@@ -0,0 +1,100 @@
+# vim:set ft= ts=4 sw=4 et fdm=marker:
+use lib 'lib';
+use Test::Nginx::Socket;
+
+#worker_connections(1014);
+#master_on();
+#workers(2);
+log_level('warn');
+
+repeat_each(2);
+#repeat_each(1);
+
+plan tests => repeat_each() * (blocks() * 3);
+
+#no_diff();
+#no_long_string();
+run_tests();
+
+__DATA__
+
+=== TEST 1: log socket errors off (tcp)
+--- config
+ location /t {
+ lua_socket_connect_timeout 1ms;
+ lua_socket_log_errors off;
+ content_by_lua '
+ local sock = ngx.socket.tcp()
+ local ok, err = sock:connect("8.8.8.8", 80)
+ ngx.say(err)
+ ';
+ }
+--- request
+GET /t
+--- response_body
+timeout
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: log socket errors on (tcp)
+--- config
+ location /t {
+ lua_socket_connect_timeout 1ms;
+ lua_socket_log_errors on;
+ content_by_lua '
+ local sock = ngx.socket.tcp()
+ local ok, err = sock:connect("8.8.8.8", 80)
+ ngx.say(err)
+ ';
+ }
+--- request
+GET /t
+--- response_body
+timeout
+--- error_log
+lua tcp socket connect timed out
+
+
+
+=== TEST 3: log socket errors on (udp)
+--- config
+ location /t {
+ lua_socket_log_errors on;
+ lua_socket_read_timeout 1ms;
+ content_by_lua '
+ local sock = ngx.socket.udp()
+ local ok, err = sock:setpeername("8.8.8.8", 80)
+ ok, err = sock:receive()
+ ngx.say(err)
+ ';
+ }
+--- request
+GET /t
+--- response_body
+timeout
+--- error_log
+lua udp socket read timed out
+
+
+
+=== TEST 4: log socket errors off (udp)
+--- config
+ location /t {
+ lua_socket_log_errors off;
+ lua_socket_read_timeout 1ms;
+ content_by_lua '
+ local sock = ngx.socket.udp()
+ local ok, err = sock:setpeername("8.8.8.8", 80)
+ ok, err = sock:receive()
+ ngx.say(err)
+ ';
+ }
+--- request
+GET /t
+--- response_body
+timeout
+--- no_error_log
+[error]
+
Please sign in to comment.
Something went wrong with that request. Please try again.