mirror of
https://github.com/SCST-project/scst.git
synced 2026-08-19 13:46:25 +00:00
Cleanup: move misc routines in misc.c
This patch moves the following utility functions from iscsi_scstd.c to misc.c and makes them public (i.e. non-static): * set_non_blocking * sock_set_keepalive Signed-off-by: Sergey Myasnikov <tigra564@gmail.com> git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4160 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
@@ -16,7 +16,8 @@
|
||||
# GNU General Public License for more details.
|
||||
|
||||
SRCS_D = iscsid.c iscsi_scstd.c conn.c session.c target.c message.c ctldev.c \
|
||||
log.c chap.c event.c param.c config.c isns.c md5.c sha1.c
|
||||
log.c chap.c event.c param.c config.c isns.c md5.c sha1.c \
|
||||
misc.c
|
||||
OBJS_D = $(SRCS_D:.c=.o)
|
||||
|
||||
SRCS_ADM = iscsi_adm.c param.c
|
||||
|
||||
@@ -92,39 +92,6 @@ iSCSI target daemon.\n\
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void set_non_blocking(int fd)
|
||||
{
|
||||
int res = fcntl(fd, F_GETFL);
|
||||
|
||||
if (res != -1) {
|
||||
res = fcntl(fd, F_SETFL, res | O_NONBLOCK);
|
||||
if (res)
|
||||
log_warning("unable to set fd flags (%s)!", strerror(errno));
|
||||
} else
|
||||
log_warning("unable to get fd flags (%s)!", strerror(errno));
|
||||
}
|
||||
|
||||
static void sock_set_keepalive(int sock, int timeout)
|
||||
{
|
||||
if (timeout) { /* timeout [s] */
|
||||
int opt = 2;
|
||||
|
||||
if (setsockopt(sock, SOL_TCP, TCP_KEEPCNT, &opt, sizeof(opt)))
|
||||
log_warning("unable to set TCP_KEEPCNT on server socket (%s)!", strerror(errno));
|
||||
|
||||
if (setsockopt(sock, SOL_TCP, TCP_KEEPIDLE, &timeout, sizeof(timeout)))
|
||||
log_warning("unable to set TCP_KEEPIDLE on server socket (%s)!", strerror(errno));
|
||||
|
||||
opt = 3;
|
||||
if (setsockopt(sock, SOL_TCP, TCP_KEEPINTVL, &opt, sizeof(opt)))
|
||||
log_warning("unable to set KEEPINTVL on server socket (%s)!", strerror(errno));
|
||||
|
||||
opt = 1;
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt)))
|
||||
log_warning("unable to set SO_KEEPALIVE on server socket (%s)!", strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
const char *get_error_str(int error)
|
||||
{
|
||||
if (error == EAI_SYSTEM)
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2007 - 2011 Vladislav Bolkhovitin
|
||||
* Copyright (C) 2010 - 2011 SCST Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, version 2
|
||||
* of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "iscsid.h"
|
||||
|
||||
void set_non_blocking(int fd)
|
||||
{
|
||||
int res = fcntl(fd, F_GETFL);
|
||||
|
||||
if (res != -1) {
|
||||
res = fcntl(fd, F_SETFL, res | O_NONBLOCK);
|
||||
if (res)
|
||||
log_warning("unable to set fd flags (%s)!", strerror(errno));
|
||||
} else
|
||||
log_warning("unable to get fd flags (%s)!", strerror(errno));
|
||||
}
|
||||
|
||||
void sock_set_keepalive(int sock, int timeout)
|
||||
{
|
||||
if (timeout) { /* timeout [s] */
|
||||
int opt = 2;
|
||||
|
||||
if (setsockopt(sock, SOL_TCP, TCP_KEEPCNT, &opt, sizeof(opt)))
|
||||
log_warning("unable to set TCP_KEEPCNT on server socket (%s)!", strerror(errno));
|
||||
|
||||
if (setsockopt(sock, SOL_TCP, TCP_KEEPIDLE, &timeout, sizeof(timeout)))
|
||||
log_warning("unable to set TCP_KEEPIDLE on server socket (%s)!", strerror(errno));
|
||||
|
||||
opt = 3;
|
||||
if (setsockopt(sock, SOL_TCP, TCP_KEEPINTVL, &opt, sizeof(opt)))
|
||||
log_warning("unable to set KEEPINTVL on server socket (%s)!", strerror(errno));
|
||||
|
||||
opt = 1;
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt)))
|
||||
log_warning("unable to set SO_KEEPALIVE on server socket (%s)!", strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,4 +106,7 @@ static inline int list_length_is_one(const struct __qelem *head)
|
||||
#define IPV6_V6ONLY 26
|
||||
#endif
|
||||
|
||||
extern void set_non_blocking(int fd);
|
||||
extern void sock_set_keepalive(int sock, int timeout);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user