Using static and constant linger structure.

This commit is contained in:
Igor Sysoev
2017-06-29 15:52:47 +03:00
parent 52f79c3e53
commit 499a8f9ac8
2 changed files with 16 additions and 16 deletions

View File

@@ -96,10 +96,13 @@ nxt_conn_create(nxt_mp_t *mp, nxt_task_t *task)
void void
nxt_conn_io_shutdown(nxt_task_t *task, void *obj, void *data) nxt_conn_io_shutdown(nxt_task_t *task, void *obj, void *data)
{ {
int ret; int ret;
socklen_t len; nxt_conn_t *c;
nxt_conn_t *c;
struct linger linger; static const struct linger linger_off = {
.l_onoff = 1,
.l_linger = 0,
};
c = obj; c = obj;
@@ -111,11 +114,8 @@ nxt_conn_io_shutdown(nxt_task_t *task, void *obj, void *data)
* releases kernel memory associated with socket. * releases kernel memory associated with socket.
* This also causes sending TCP/IP RST to a peer. * This also causes sending TCP/IP RST to a peer.
*/ */
linger.l_onoff = 1; ret = setsockopt(c->socket.fd, SOL_SOCKET, SO_LINGER, &linger_off,
linger.l_linger = 0; sizeof(struct linger));
len = sizeof(struct linger);
ret = setsockopt(c->socket.fd, SOL_SOCKET, SO_LINGER, &linger, len);
if (nxt_slow_path(ret != 0)) { if (nxt_slow_path(ret != 0)) {
nxt_log(task, NXT_LOG_CRIT, "setsockopt(%d, SO_LINGER) failed %E", nxt_log(task, NXT_LOG_CRIT, "setsockopt(%d, SO_LINGER) failed %E",

View File

@@ -19,11 +19,14 @@ void
nxt_conn_close(nxt_event_engine_t *engine, nxt_conn_t *c) nxt_conn_close(nxt_event_engine_t *engine, nxt_conn_t *c)
{ {
int ret; int ret;
socklen_t len;
struct linger linger;
nxt_work_queue_t *wq; nxt_work_queue_t *wq;
nxt_work_handler_t handler; nxt_work_handler_t handler;
static const struct linger linger_off = {
.l_onoff = 1,
.l_linger = 0,
};
nxt_debug(c->socket.task, "conn close fd:%d, to:%d", nxt_debug(c->socket.task, "conn close fd:%d, to:%d",
c->socket.fd, c->socket.timedout); c->socket.fd, c->socket.timedout);
@@ -33,11 +36,8 @@ nxt_conn_close(nxt_event_engine_t *engine, nxt_conn_t *c)
* releases kernel memory associated with socket. * releases kernel memory associated with socket.
* This also causes sending TCP/IP RST to a peer. * This also causes sending TCP/IP RST to a peer.
*/ */
linger.l_onoff = 1; ret = setsockopt(c->socket.fd, SOL_SOCKET, SO_LINGER, &linger_off,
linger.l_linger = 0; sizeof(struct linger));
len = sizeof(struct linger);
ret = setsockopt(c->socket.fd, SOL_SOCKET, SO_LINGER, &linger, len);
if (nxt_slow_path(ret != 0)) { if (nxt_slow_path(ret != 0)) {
nxt_log(c->socket.task, NXT_LOG_CRIT, nxt_log(c->socket.task, NXT_LOG_CRIT,