From 39d0b2983a88fe13e3fd778b560f2065a9afc753 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Tue, 28 Jan 2014 04:17:32 +0000 Subject: [PATCH] [PATCH 5/9] iscsid: Add start/stop transmit abstraction In order to be able to abstract from socket and iser connection fd's we need to have generic code that can handle both. Signed-off-by: Yan Burman git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/iser@5233 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/iscsi_scstd.c | 15 ++++++++++----- iscsi-scst/usr/iscsid.h | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/iscsi-scst/usr/iscsi_scstd.c b/iscsi-scst/usr/iscsi_scstd.c index ede7626b5..5425c4501 100644 --- a/iscsi-scst/usr/iscsi_scstd.c +++ b/iscsi-scst/usr/iscsi_scstd.c @@ -170,6 +170,12 @@ static void create_listen_socket(struct pollfd *array) exit(1); } +static int transmit_sock(int fd, bool start) +{ + int opt = start; + return setsockopt(fd, SOL_TCP, TCP_CORK, &opt, sizeof(opt)); +} + static void accept_connection(int listen) { union { @@ -261,6 +267,7 @@ static void accept_connection(int listen) } incoming[i] = conn; + conn->transmit = transmit_sock; conn_read_pdu(conn); set_non_blocking(fd); @@ -297,7 +304,7 @@ void isns_set_fd(int isns, int scn_listen, int scn) static void event_conn(struct connection *conn, struct pollfd *pollfd) { - int res, opt; + int res; again: switch (conn->iostate) { @@ -368,8 +375,7 @@ again: case IOSTATE_WRITE_AHS: case IOSTATE_WRITE_DATA: write_again: - opt = 1; - setsockopt(pollfd->fd, SOL_TCP, TCP_CORK, &opt, sizeof(opt)); + conn->transmit(pollfd->fd, true); res = write(pollfd->fd, conn->buffer, conn->rwsize); if (res < 0) { if (errno != EINTR && errno != EAGAIN) { @@ -409,8 +415,7 @@ again: goto write_again; } case IOSTATE_WRITE_DATA: - opt = 0; - setsockopt(pollfd->fd, SOL_TCP, TCP_CORK, &opt, sizeof(opt)); + conn->transmit(pollfd->fd, false); cmnd_finish(conn); switch (conn->state) { diff --git a/iscsi-scst/usr/iscsid.h b/iscsi-scst/usr/iscsid.h index 489ec9397..2a3b4490e 100644 --- a/iscsi-scst/usr/iscsid.h +++ b/iscsi-scst/usr/iscsid.h @@ -127,6 +127,8 @@ struct connection { } auth; struct __qelem clist; + + int (*transmit)(int fd, bool start); }; #define IOSTATE_FREE 0