1
0
mirror of https://github.com/moparisthebest/socat synced 2024-12-21 22:48:48 -05:00

new address options shut-none, shut-down, and shut-close

This commit is contained in:
Gerhard Rieger 2009-04-02 08:52:11 +02:00
parent 50be6b25cf
commit 793763677a
8 changed files with 58 additions and 7 deletions

View File

@ -1,4 +1,8 @@
new features:
new address options shut-none, shut-down, and shut-close allow to
control socat's half close behaviour
####################### V 1.7.0.1: ####################### V 1.7.0.1:
corrections: corrections:

View File

@ -1481,6 +1481,15 @@ label(OPTION_END_CLOSE)dit(bf(tt(end-close)))
Similarly, when an address of type EXEC or SYSTEM is ended, socat usually Similarly, when an address of type EXEC or SYSTEM is ended, socat usually
will explicitely kill the sub process. With this option, it will just close will explicitely kill the sub process. With this option, it will just close
the file descriptors. the file descriptors.
label(OPTION_SHUT_NONE)dit(bf(tt(shut-none)))
Changes the (address dependent) method of shutting down the write part of a
connection to not do anything.
label(OPTION_SHUT_DOWN)dit(bf(tt(shut-down)))
Changes the (address dependent) method of shutting down the write part of a
connection to tt(shutdown\(fd, SHUT_WR)). Is only useful with sockets.
label(OPTION_SHUT_CLOSE)dit(bf(tt(shut-close)))
Changes the (address dependent) method of shutting down the write part of a
connection to tt(close\(fd)).
label(OPTION_IOCTL_VOID)dit(bf(tt(ioctl-void=<request>))) label(OPTION_IOCTL_VOID)dit(bf(tt(ioctl-void=<request>)))
Calls tt(ioctl()) with the request value as second argument and NULL as Calls tt(ioctl()) with the request value as second argument and NULL as
third argument. This option allows to utilize ioctls that are not third argument. This option allows to utilize ioctls that are not

View File

@ -1,5 +1,5 @@
/* source: xio-fd.c */ /* source: xio-fd.c */
/* Copyright Gerhard Rieger 2001-2008 */ /* Copyright Gerhard Rieger 2001-2009 */
/* Published under the GNU General Public License V.2, see file COPYING */ /* Published under the GNU General Public License V.2, see file COPYING */
/* this file contains common file descriptor related option definitions */ /* this file contains common file descriptor related option definitions */
@ -75,6 +75,9 @@ const struct optdesc opt_cool_write = { "cool-write", "coolwrite", OPT_COOL_WRIT
/* control closing of connections */ /* control closing of connections */
const struct optdesc opt_end_close = { "end-close", "close", OPT_END_CLOSE, GROUP_FD, PH_INIT, TYPE_CONST, OFUNC_OFFSET, (bool)&((xiofile_t *)0)->stream.howtoend, END_CLOSE }; const struct optdesc opt_end_close = { "end-close", "close", OPT_END_CLOSE, GROUP_FD, PH_INIT, TYPE_CONST, OFUNC_OFFSET, (bool)&((xiofile_t *)0)->stream.howtoend, END_CLOSE };
const struct optdesc opt_shut_none = { "shut-none", NULL, OPT_SHUT_NONE, GROUP_FD, PH_INIT, TYPE_BOOL, OFUNC_OFFSET, (bool)&((xiofile_t *)0)->stream.howtoshut, XIOSHUT_NONE };
const struct optdesc opt_shut_down = { "shut-down", NULL, OPT_SHUT_DOWN, GROUP_FD, PH_INIT, TYPE_BOOL, OFUNC_OFFSET, (bool)&((xiofile_t *)0)->stream.howtoshut, XIOSHUT_DOWN };
const struct optdesc opt_shut_close= { "shut-close", NULL, OPT_SHUT_CLOSE, GROUP_FD, PH_INIT, TYPE_BOOL, OFUNC_OFFSET, (bool)&((xiofile_t *)0)->stream.howtoshut, XIOSHUT_CLOSE };
/****** generic ioctl() options ******/ /****** generic ioctl() options ******/
const struct optdesc opt_ioctl_void = { "ioctl-void", "ioctl", OPT_IOCTL_VOID, GROUP_FD, PH_FD, TYPE_INT, OFUNC_IOCTL_GENERIC, 0, 0, 0 }; const struct optdesc opt_ioctl_void = { "ioctl-void", "ioctl", OPT_IOCTL_VOID, GROUP_FD, PH_FD, TYPE_INT, OFUNC_IOCTL_GENERIC, 0, 0, 0 };

View File

@ -1,5 +1,5 @@
/* source: xio-fd.h */ /* source: xio-fd.h */
/* Copyright Gerhard Rieger 2001-2008 */ /* Copyright Gerhard Rieger 2001-2009 */
/* Published under the GNU General Public License V.2, see file COPYING */ /* Published under the GNU General Public License V.2, see file COPYING */
#ifndef __xio_fd_h_included #ifndef __xio_fd_h_included
@ -42,6 +42,9 @@ extern const struct optdesc opt_f_setlk_wr;
extern const struct optdesc opt_f_setlkw_wr; extern const struct optdesc opt_f_setlkw_wr;
extern const struct optdesc opt_cool_write; extern const struct optdesc opt_cool_write;
extern const struct optdesc opt_end_close; extern const struct optdesc opt_end_close;
extern const struct optdesc opt_shut_none;
extern const struct optdesc opt_shut_down;
extern const struct optdesc opt_shut_close;
extern const struct optdesc opt_streams_i_push; extern const struct optdesc opt_streams_i_push;
#endif /* !defined(__xio_fd_h_included) */ #endif /* !defined(__xio_fd_h_included) */

8
xio.h
View File

@ -1,5 +1,5 @@
/* source: xio.h */ /* source: xio.h */
/* Copyright Gerhard Rieger 2001-2008 */ /* Copyright Gerhard Rieger 2001-2009 */
/* Published under the GNU General Public License V.2, see file COPYING */ /* Published under the GNU General Public License V.2, see file COPYING */
#ifndef __xio_h_included #ifndef __xio_h_included
@ -146,6 +146,12 @@ typedef struct single {
bool opt_unlink_close; /* option unlink_close */ bool opt_unlink_close; /* option unlink_close */
char *unlink_close; /* name of a symlink or unix socket to be removed */ char *unlink_close; /* name of a symlink or unix socket to be removed */
int dtype; int dtype;
enum {
XIOSHUT_UNSPEC, /* fall back to old (up to 1.7.0.0) behaviour */
XIOSHUT_NONE, /* do nothing on shutdown */
XIOSHUT_CLOSE, /* close the FD */
XIOSHUT_DOWN /* shutdown() */
} howtoshut;
enum { enum {
END_UNSPEC, /* after init, when no end-close... option */ END_UNSPEC, /* after init, when no end-close... option */
END_NONE, /* no action */ END_NONE, /* no action */

View File

@ -1,5 +1,5 @@
/* source: xioopts.c */ /* source: xioopts.c */
/* Copyright Gerhard Rieger 2001-2008 */ /* Copyright Gerhard Rieger 2001-2009 */
/* Published under the GNU General Public License V.2, see file COPYING */ /* Published under the GNU General Public License V.2, see file COPYING */
/* this file contains the source for address options handling */ /* this file contains the source for address options handling */
@ -1313,6 +1313,9 @@ const struct optname optionnames[] = {
IF_SOCKET ("setsockopt-string", &opt_setsockopt_string) IF_SOCKET ("setsockopt-string", &opt_setsockopt_string)
IF_ANY ("setuid", &opt_setuid) IF_ANY ("setuid", &opt_setuid)
IF_ANY ("setuid-early", &opt_setuid_early) IF_ANY ("setuid-early", &opt_setuid_early)
IF_ANY ("shut-close", &opt_shut_close)
IF_ANY ("shut-down", &opt_shut_down)
IF_ANY ("shut-none", &opt_shut_none)
#if WITH_EXEC || WITH_SYSTEM #if WITH_EXEC || WITH_SYSTEM
IF_ANY ("sid", &opt_setsid) IF_ANY ("sid", &opt_setsid)
#endif #endif

View File

@ -1,5 +1,5 @@
/* source: xioopts.h */ /* source: xioopts.h */
/* Copyright Gerhard Rieger 2001-2008 */ /* Copyright Gerhard Rieger 2001-2009 */
/* Published under the GNU General Public License V.2, see file COPYING */ /* Published under the GNU General Public License V.2, see file COPYING */
#ifndef __xioopts_h_included #ifndef __xioopts_h_included
@ -590,6 +590,9 @@ enum e_optcode {
OPT_SETSOCKOPT_STRING, OPT_SETSOCKOPT_STRING,
OPT_SETUID, OPT_SETUID,
OPT_SETUID_EARLY, OPT_SETUID_EARLY,
OPT_SHUT_CLOSE,
OPT_SHUT_DOWN,
OPT_SHUT_NONE,
OPT_SIGHUP, OPT_SIGHUP,
OPT_SIGINT, OPT_SIGINT,
OPT_SIGQUIT, OPT_SIGQUIT,

View File

@ -1,5 +1,5 @@
/* source: xioshutdown.c */ /* source: xioshutdown.c */
/* Copyright Gerhard Rieger 2001-2008 */ /* Copyright Gerhard Rieger 2001-2009 */
/* Published under the GNU General Public License V.2, see file COPYING */ /* Published under the GNU General Public License V.2, see file COPYING */
/* this is the source of the extended shutdown function */ /* this is the source of the extended shutdown function */
@ -31,9 +31,29 @@ int xioshutdown(xiofile_t *sock, int how) {
if ((how+1)&2) { if ((how+1)&2) {
result |= xioshutdown((xiofile_t *)sock->dual.stream[1], 1); result |= xioshutdown((xiofile_t *)sock->dual.stream[1], 1);
} }
return result;
}
switch (sock->stream.howtoshut) {
case XIOSHUT_NONE:
return 0;
case XIOSHUT_CLOSE:
if (Close(sock->stream.fd) < 0) {
Info2("close(%d): %s",
sock->stream.fd, strerror(errno));
}
return 0;
case XIOSHUT_DOWN:
if ((result = Shutdown(sock->stream.fd, how)) < 0) {
Info3("shutdown(%d, %d): %s",
sock->stream.fd, how, strerror(errno));
}
return 0;
default: ;
}
#if WITH_OPENSSL #if WITH_OPENSSL
} else if ((sock->stream.dtype & XIODATA_MASK) == XIODATA_OPENSSL) { if ((sock->stream.dtype & XIODATA_MASK) == XIODATA_OPENSSL) {
sycSSL_shutdown (sock->stream.para.openssl.ssl); sycSSL_shutdown (sock->stream.para.openssl.ssl);
/*! what about half/full close? */ /*! what about half/full close? */
#endif /* WITH_OPENSSL */ #endif /* WITH_OPENSSL */