Skip to content

add req socket send function #1

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

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ ngx.req.socket

receive
receiveuntil
send

ngx.say/ngx.print
------------
Expand Down
8 changes: 7 additions & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,11 @@ NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_tcp.c \
$ngx_addon_dir/src/ngx_tcp_lua_exception.c \
$ngx_addon_dir/src/ngx_tcp_lua_output.c \
$ngx_addon_dir/src/ngx_tcp_lua_socket.c \
$ngx_addon_dir/src/ngx_tcp_lua_log.c"
$ngx_addon_dir/src/ngx_tcp_lua_log.c \
$ngx_addon_dir/src/ngx_tcp_lua_time.c \
$ngx_addon_dir/src/ngx_tcp_lua_shdict.c \
$ngx_addon_dir/src/ngx_tcp_variables.c \
$ngx_addon_dir/src/ngx_tcp_lua_variable.c \
$ngx_addon_dir/src/ngx_tcp_lua_string.c "


106 changes: 106 additions & 0 deletions src/log
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
ngx_tcp_access.c: if (s->connection->sockaddr->sa_family != AF_INET) {
ngx_tcp_access.c: sin = (struct sockaddr_in *) s->connection->sockaddr;
ngx_tcp_access.c: ngx_log_debug3(NGX_LOG_DEBUG, s->connection->log, 0,
ngx_tcp_access.c: ngx_log_error(NGX_LOG_NOTICE, s->connection->log, 0,
ngx_tcp_lua_log.c: if (s && s->connection && s->connection->log) {
ngx_tcp_lua_log.c: if (s && s->connection && s->connection->log) {
ngx_tcp_lua_log.c: if (level > s->connection->log->log_level) {
ngx_tcp_lua_log.c: ngx_log_error(level, s->connection->log, 0, "%s%s", ident, buf);
ngx_tcp_lua_module.c: ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
ngx_tcp_lua_module.c: ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
ngx_tcp_lua_module.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
ngx_tcp_lua_output.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_output.c: chain = s->connection->send_chain(s->connection, cl, 0);
ngx_tcp_lua_output.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: chain = s->connection->send_chain(s->connection, cl, 0);
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: pc->log = s->connection->log;
ngx_tcp_lua_socket.c: s->connection->single_connection = 0;
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug2(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug4(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: c->sendfile &= s->connection->sendfile;
ngx_tcp_lua_socket.c: c->log = s->connection->log;
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_tcp_lua_chains_get_free_buf(s->connection->log, s->pool,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, u->session->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug2(NGX_LOG_DEBUG_HTTP, u->session->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug2(NGX_LOG_DEBUG_HTTP, u->session->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug3(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug2(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: cl = ngx_tcp_lua_chains_get_free_buf(s->connection->log, s->pool,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug2(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_tcp_lua_socket_free_pool(r->connection->log, spool);
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: s->connection->log);
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_tcp_lua_chains_get_free_buf(s->connection->log, s->pool,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: pc->log = s->connection->log;
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_socket.c: cl = ngx_tcp_lua_chains_get_free_buf(s->connection->log, s->pool,
ngx_tcp_lua_socket.c: new_cl = ngx_tcp_lua_chains_get_free_buf(s->connection->log, s->pool,
ngx_tcp_lua_util.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_util.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_util.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_util.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_util.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_util.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_util.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_util.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_util.c: ngx_log_debug0(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_lua_util.c: ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
ngx_tcp_lua_util.c: ngx_log_debug1(NGX_LOG_DEBUG_HTTP, s->connection->log, 0,
ngx_tcp_session.c: if (setsockopt(s->connection->fd, SOL_SOCKET, SO_KEEPALIVE,
ngx_tcp_session.c: ngx_log_error(NGX_LOG_ALERT, s->connection->log, ngx_socket_errno,
ngx_tcp_session.c: if (setsockopt(s->connection->fd, IPPROTO_TCP, TCP_NODELAY,
ngx_tcp_session.c: ngx_log_error(NGX_LOG_ALERT, s->connection->log, ngx_socket_errno,
ngx_tcp_session.c: s->connection->tcp_nodelay = NGX_TCP_NODELAY_SET;
ngx_tcp_session.c: ngx_tcp_send(s->connection->write);
ngx_tcp_session.c: ngx_log_debug1(NGX_LOG_DEBUG_EVENT, s->connection->log, 0,
ngx_tcp_session.c: ngx_log_debug0(NGX_LOG_DEBUG_EVENT, r->connection->log, 0,
ngx_tcp_session.c: && s->connection->read->active)
ngx_tcp_session.c: if (ngx_del_event(s->connection->read, NGX_READ_EVENT, 0) != NGX_OK) {
27 changes: 25 additions & 2 deletions src/ngx_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <ngx_core.h>
#include <ngx_event.h>
#include "ngx_tcp.h"
#include "ngx_tcp_variables.h"


static char *ngx_tcp_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
Expand Down Expand Up @@ -151,6 +152,21 @@ ngx_tcp_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
pcf = *cf;
cf->ctx = ctx;


for (m = 0; ngx_modules[m]; m++) {
if (ngx_modules[m]->type != NGX_TCP_MODULE) {
continue;
}

module = ngx_modules[m]->ctx;

if (module->preconfiguration) {
if (module->preconfiguration(cf) != NGX_OK) {
return NGX_CONF_ERROR;
}
}
}

cf->module_type = NGX_TCP_MODULE;
cf->cmd_type = NGX_TCP_MAIN_CONF;
rv = ngx_conf_parse(cf, NULL);
Expand Down Expand Up @@ -217,6 +233,9 @@ ngx_tcp_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
}

if (ngx_tcp_variables_init_vars(cf) != NGX_OK) {
return NGX_CONF_ERROR;
}
/*
* tcp{}'s cf->ctx was needed while the configuration merging
* and in postconfiguration process
Expand Down Expand Up @@ -610,8 +629,11 @@ static ngx_listening_t *
ngx_tcp_add_listening(ngx_conf_t *cf, ngx_tcp_conf_addr_t *addr)
{
ngx_listening_t *ls;
//ngx_tcp_core_srv_conf_t *cscf;
ngx_tcp_core_srv_conf_t *cscf;

//cscf=ngx_tcp_conf_get_module_srv_conf(cf, ngx_tcp_core_module);
cscf=ngx_tcp_get_module_srv_conf(addr->ctx,ngx_tcp_core_module);

ls = ngx_create_listening(cf, addr->sockaddr, addr->socklen);
if (ls == NULL) {
return NULL;
Expand All @@ -624,7 +646,8 @@ ngx_tcp_add_listening(ngx_conf_t *cf, ngx_tcp_conf_addr_t *addr)
ls->pool_size = 256; //cscf->connection_pool_size;
ls->post_accept_timeout = 10000; //cscf->client_header_timeout;

ls->logp = &cf->cycle->new_log;
ls->logp = cscf->error_log;
/*ls->logp = &cf->cycle->new_log;*/
ls->log.data = &ls->addr_text;
ls->log.handler = ngx_accept_log_error;

Expand Down
12 changes: 11 additions & 1 deletion src/ngx_tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ typedef struct {
ngx_array_t servers; /* ngx_tcp_core_srv_conf_t */
ngx_array_t listen; /* ngx_tcp_listen_t */
ngx_array_t virtual_servers; /* ngx_tcp_virtual_server_t */
ngx_uint_t variables_hash_max_size;
ngx_uint_t variables_hash_bucket_size;
ngx_hash_t variables_hash;
ngx_array_t variables; /* ngx_http_variable_t */
ngx_hash_keys_arrays_t *variables_keys;
} ngx_tcp_core_main_conf_t;

typedef struct {
Expand Down Expand Up @@ -182,14 +187,18 @@ struct ngx_tcp_core_srv_conf_s {
/*ACL rules*/
ngx_array_t *rules;

ngx_log_t *error_log;

ngx_tcp_log_srv_conf_t *access_log;

/* server ctx */
ngx_tcp_conf_ctx_t *ctx;

off_t directio_alignment; /* directio_alignment */

size_t client_body_buffer_size; /* client_body_buffer_size */


};


Expand Down Expand Up @@ -220,6 +229,7 @@ struct ngx_tcp_protocol_s {
typedef struct {
ngx_tcp_protocol_t *protocol;

ngx_int_t (*preconfiguration)(ngx_conf_t *cf);
ngx_int_t (*postconfiguration)(ngx_conf_t *cf);

void *(*create_main_conf)(ngx_conf_t *cf);
Expand Down
Loading