1
0
Fork 0
mirror of https://repo.or.cz/socat.git synced 2025-06-19 07:16:52 +00:00

POSIXMQ-RECV takes option o-nonblock

This commit is contained in:
Gerhard Rieger 2025-01-24 17:01:55 +01:00
parent 68f0143f7b
commit 9bf5fc625c
3 changed files with 18 additions and 8 deletions

View file

@ -41,6 +41,10 @@ Corrections:
input lines. Changed Socat to explicitly print the newline in this input lines. Changed Socat to explicitly print the newline in this
case. case.
Features:
POSIXMQ-RECV now takes option o-nonblock; this, in combination with -T,
makes it possible to terminate Socat in case the queue is empty.
Building: Building:
Disabling certain features during configure could break build process. Disabling certain features during configure could break build process.

View file

@ -332,7 +332,7 @@ label(ADDRESS_DCCP_CONNECT)dit(bf(tt(DCCP-CONNECT:<host>:<port>)) (bf(tt(DCCP:<h
link(connect-timeout)(OPTION_CONNECT_TIMEOUT), link(connect-timeout)(OPTION_CONNECT_TIMEOUT),
link(tos)(OPTION_TOS), link(tos)(OPTION_TOS),
link(dccp-set-ccid)(OPTION_DCCP_SET_CCID), link(dccp-set-ccid)(OPTION_DCCP_SET_CCID),
link(nonblock)(OPTION_NONBLOCK), link(nonblock)(OPTION_O_NONBLOCK),
link(sourceport)(OPTION_SOURCEPORT), link(sourceport)(OPTION_SOURCEPORT),
link(retry)(OPTION_RETRY), link(retry)(OPTION_RETRY),
link(readbytes)(OPTION_READBYTES)nl() link(readbytes)(OPTION_READBYTES)nl()
@ -747,7 +747,7 @@ label(ADDRESS_NAMED_PIPE)dit(bf(tt(PIPE:<filename>)))
Option groups: link(FD)(GROUP_FD),link(NAMED)(GROUP_NAMED),link(OPEN)(GROUP_OPEN) nl() Option groups: link(FD)(GROUP_FD),link(NAMED)(GROUP_NAMED),link(OPEN)(GROUP_OPEN) nl()
Useful options: Useful options:
link(rdonly)(OPTION_RDONLY), link(rdonly)(OPTION_RDONLY),
link(nonblock)(OPTION_NONBLOCK), link(nonblock)(OPTION_O_NONBLOCK),
link(group)(OPTION_GROUP), link(group)(OPTION_GROUP),
link(user)(OPTION_USER), link(user)(OPTION_USER),
link(mode)(OPTION_MODE), link(mode)(OPTION_MODE),
@ -784,7 +784,8 @@ label(ADDRESS_POSIXMQ_READ)dit(bf(tt(POSIXMQ-READ:/<mqueue>)))
Useful options: Useful options:
link(posixmq-priority)(OPTION_POSIXMQ_PRIORITY), link(posixmq-priority)(OPTION_POSIXMQ_PRIORITY),
link(unlink-early)(OPTION_UNLINK_EARLY), link(unlink-early)(OPTION_UNLINK_EARLY),
link(unlink-close)(OPTION_UNLINK_CLOSE) link(unlink-close)(OPTION_UNLINK_CLOSE),
link(o-nonblock)(OPTION_O_NONBLOCK)
label(ADDRESS_POSIXMQ_RECEIVE)dit(bf(tt(POSIXMQ-RECEIVE:/<mqueue>))) label(ADDRESS_POSIXMQ_RECEIVE)dit(bf(tt(POSIXMQ-RECEIVE:/<mqueue>)))
dit(bf(tt(POSIXMQ-RECV:/<mqueue>))) dit(bf(tt(POSIXMQ-RECV:/<mqueue>)))
@ -882,7 +883,7 @@ label(ADDRESS_SCTP_CONNECT)dit(bf(tt(SCTP-CONNECT:<host>:<port>)))
link(mtudiscover)(OPTION_MTUDISCOVER), link(mtudiscover)(OPTION_MTUDISCOVER),
link(sctp-maxseg)(OPTION_SCTP_MAXSEG), link(sctp-maxseg)(OPTION_SCTP_MAXSEG),
link(sctp-nodelay)(OPTION_SCTP_NODELAY), link(sctp-nodelay)(OPTION_SCTP_NODELAY),
link(nonblock)(OPTION_NONBLOCK), link(nonblock)(OPTION_O_NONBLOCK),
link(sourceport)(OPTION_SOURCEPORT), link(sourceport)(OPTION_SOURCEPORT),
link(retry)(OPTION_RETRY), link(retry)(OPTION_RETRY),
link(readbytes)(OPTION_READBYTES)nl() link(readbytes)(OPTION_READBYTES)nl()
@ -1234,7 +1235,7 @@ label(ADDRESS_TCP_CONNECT)dit(bf(tt(TCP:<host>:<port>)))
link(mtudiscover)(OPTION_MTUDISCOVER), link(mtudiscover)(OPTION_MTUDISCOVER),
link(mss)(OPTION_MSS), link(mss)(OPTION_MSS),
link(nodelay)(OPTION_TCP_NODELAY), link(nodelay)(OPTION_TCP_NODELAY),
link(nonblock)(OPTION_NONBLOCK), link(nonblock)(OPTION_O_NONBLOCK),
link(readbytes)(OPTION_READBYTES)nl() link(readbytes)(OPTION_READBYTES)nl()
See also: See also:
link(TCP4)(ADDRESS_TCP4_CONNECT), link(TCP4)(ADDRESS_TCP4_CONNECT),
@ -1853,7 +1854,7 @@ label(OPTION_APPEND)dit(bf(tt(append[=<bool>])))
socat() uses the code(O_APPEND) flag with the code(open()) system call socat() uses the code(O_APPEND) flag with the code(open()) system call
(link(example)(EXAMPLE_OPTION_APPEND)). (link(example)(EXAMPLE_OPTION_APPEND)).
Otherwise, socat() applies the code(fcntl(fd, F_SETFL, O_APPEND)) call. Otherwise, socat() applies the code(fcntl(fd, F_SETFL, O_APPEND)) call.
label(OPTION_NONBLOCK)dit(bf(tt(nonblock[=<bool>]))) label(OPTION_O_NONBLOCK)dit(bf(tt(nonblock[=<bool>])))
Tries to open or use file in nonblocking mode. Its only effects are that the Tries to open or use file in nonblocking mode. Its only effects are that the
code(connect()) call of TCP addresses does not block, and that opening a code(connect()) call of TCP addresses does not block, and that opening a
named pipe for reading does not block. named pipe for reading does not block.
@ -1988,7 +1989,7 @@ E.g., option `creat' sets the code(O_CREAT) flag. When the used address does
not use code(open()) (e.g.STDIO), the code(fcntl(..., F_SETFL, ...)) call is not use code(open()) (e.g.STDIO), the code(fcntl(..., F_SETFL, ...)) call is
used instead.nl() used instead.nl()
See also options link(append)(OPTION_APPEND) and See also options link(append)(OPTION_APPEND) and
link(nonblock)(OPTION_NONBLOCK). link(nonblock)(OPTION_O_NONBLOCK).
startdit() startdit()
label(OPTION_O_CREAT)dit(bf(tt(creat[=<bool>]))) label(OPTION_O_CREAT)dit(bf(tt(creat[=<bool>])))
Creates the file if it does not exist (link(example)(EXAMPLE_OPTION_CREAT)). Creates the file if it does not exist (link(example)(EXAMPLE_OPTION_CREAT)).
@ -3973,7 +3974,7 @@ prompts.
label(EXAMPLE_ADDRESS_PTY) label(EXAMPLE_ADDRESS_PTY)
label(EXAMPLE_OPTION_SYMBOLIC_LINK) label(EXAMPLE_OPTION_SYMBOLIC_LINK)
label(EXAMPLE_OPTION_WAIT_SLAVE) label(EXAMPLE_OPTION_WAIT_SLAVE)
label(EXAMPLE_OPTION_NONBLOCK) label(EXAMPLE_OPTION_O_NONBLOCK)
mancommand(\.LP) mancommand(\.LP)
mancommand(\.nf) mancommand(\.nf)
mancommand(\fBsocat \\) mancommand(\fBsocat \\)

View file

@ -45,6 +45,7 @@ static int xioopen_posixmq(
int dirs = addrdesc->arg1; int dirs = addrdesc->arg1;
int oneshot = addrdesc->arg2; int oneshot = addrdesc->arg2;
bool opt_unlink_early = false; bool opt_unlink_early = false;
bool nonblock;
int oflag; int oflag;
bool opt_o_excl = false; bool opt_o_excl = false;
mode_t opt_mode = 0666; mode_t opt_mode = 0666;
@ -113,6 +114,8 @@ static int xioopen_posixmq(
case XIO_RDONLY: oflag |= O_RDONLY; break; case XIO_RDONLY: oflag |= O_RDONLY; break;
case XIO_WRONLY: oflag |= O_WRONLY; break; case XIO_WRONLY: oflag |= O_WRONLY; break;
} }
if (retropt_bool(opts, OPT_O_NONBLOCK, &nonblock) >= 0 && nonblock)
oflag |= O_NONBLOCK;
/* Now open the message queue */ /* Now open the message queue */
Debug3("mq_open(\"%s\", %d, "F_mode", NULL)", name, oflag, opt_mode); Debug3("mq_open(\"%s\", %d, "F_mode", NULL)", name, oflag, opt_mode);
@ -155,6 +158,8 @@ static int xioopen_posixmq(
do { do {
struct pollfd pollfd; struct pollfd pollfd;
if (oflag & O_NONBLOCK)
break;
pollfd.fd = sfd->fd; pollfd.fd = sfd->fd;
pollfd.events = (dirs==XIO_RDONLY?POLLIN:POLLOUT); pollfd.events = (dirs==XIO_RDONLY?POLLIN:POLLOUT);
if (xiopoll(&pollfd, 1, NULL) > 0) { if (xiopoll(&pollfd, 1, NULL) > 0) {