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

Added POSIXMQ-WRITE; warn on maxmsg,msgsize failure; doc

This commit is contained in:
Gerhard 2025-02-18 12:34:15 +01:00
parent 436d764029
commit b57d8668ec
5 changed files with 40 additions and 17 deletions

View file

@ -24,6 +24,7 @@ const struct addrdesc xioaddr_posixmq_bidir = { "POSIXMQ-BIDIRECTIONAL", 1+XIO
const struct addrdesc xioaddr_posixmq_read = { "POSIXMQ-READ", 1+XIO_RDONLY, xioopen_posixmq, GROUP_FD|GROUP_OPEN|GROUP_NAMED|GROUP_POSIXMQ|GROUP_RETRY, XIO_RDONLY, 0, 0 HELP(":<mqname>") };
const struct addrdesc xioaddr_posixmq_receive = { "POSIXMQ-RECEIVE", 1+XIO_RDONLY, xioopen_posixmq, GROUP_FD|GROUP_OPEN|GROUP_NAMED|GROUP_POSIXMQ|GROUP_RETRY|GROUP_CHILD, XIO_RDONLY, XIOREAD_RECV_ONESHOT, 0 HELP(":<mqname>") };
const struct addrdesc xioaddr_posixmq_send = { "POSIXMQ-SEND", 1+XIO_WRONLY, xioopen_posixmq, GROUP_FD|GROUP_OPEN|GROUP_NAMED|GROUP_POSIXMQ|GROUP_RETRY|GROUP_CHILD, XIO_WRONLY, 0, 0 HELP(":<mqname>") };
const struct addrdesc xioaddr_posixmq_write = { "POSIXMQ-WRITE", 1+XIO_WRONLY, xioopen_posixmq, GROUP_FD|GROUP_OPEN|GROUP_NAMED|GROUP_POSIXMQ|GROUP_RETRY|GROUP_CHILD, XIO_WRONLY, 0, 0 HELP(":<mqname>") };
const struct optdesc opt_posixmq_priority = { "posixmq-priority", "mq-prio", OPT_POSIXMQ_PRIORITY, GROUP_POSIXMQ, PH_INIT, TYPE_BOOL, OFUNC_OFFSET, XIO_OFFSETOF(para.posixmq.prio), XIO_SIZEOF(para.posixmq.prio), 0 };
const struct optdesc opt_posixmq_flush = { "posixmq-flush", "mq-flush", OPT_POSIXMQ_FLUSH, GROUP_POSIXMQ, PH_EARLY, TYPE_BOOL, OFUNC_SPEC, 0, 0, 0 };
@ -49,6 +50,8 @@ static int xioopen_posixmq(
bool opt_unlink_early = false;
bool nonblock = 0;
bool flush = false;
long maxmsg;
long msgsize;
struct mq_attr attr = { 0 };
bool setopts = false;
int oflag;
@ -110,13 +113,13 @@ static int xioopen_posixmq(
#endif
retropt_mode(opts, OPT_PERM, &opt_mode);
retropt_bool(opts, OPT_POSIXMQ_FLUSH, &flush);
retropt_long(opts, OPT_POSIXMQ_MAXMSG, &attr.mq_maxmsg) ||
retropt_long(opts, OPT_POSIXMQ_MAXMSG, &maxmsg) ||
(setopts = true);
retropt_long(opts, OPT_POSIXMQ_MSGSIZE, &attr.mq_msgsize) ||
retropt_long(opts, OPT_POSIXMQ_MSGSIZE, &msgsize) ||
(setopts = true);
/* When only one of mq-maxmsg and mq-msgsize options has been provided,
we must nevertheless set the other option value in strucht mq_attr.
/* When just one of mq-maxmsg and mq-msgsize options has been provided,
we must nevertheless set the other option value in struct mq_attr.
For this we have to find the default, read it from /proc fs */
if (setopts) {
int pfd;
@ -125,7 +128,7 @@ static int xioopen_posixmq(
char buff[21]; /* fit a 64bit num in decimal */
ssize_t bytes;
if (attr.mq_maxmsg == 0) {
if (maxmsg == 0) {
if ((pfd = Open(PROC_MAXMSG, O_RDONLY, 0)) < 0) {
Warn2("open(\"%s\", O_RDONLY, 0): %s", PROC_MAXMSG, strerror(errno));
} else if ((bytes = Read(pfd, buff, sizeof(buff)-1)) < 0) {
@ -133,12 +136,12 @@ static int xioopen_posixmq(
pfd, PROC_MAXMSG, sizeof(buff)-1, strerror (errno));
Close(pfd);
} else {
sscanf(buff, "%ld", &attr.mq_maxmsg);
sscanf(buff, "%ld", &maxmsg);
Close(pfd);
}
}
if (attr.mq_msgsize == 0) {
if (msgsize == 0) {
if ((pfd = Open(PROC_MSGSIZE, O_RDONLY, 0)) < 0) {
Warn2("open(\"%s\", O_RDONLY, 0): %s", PROC_MSGSIZE, strerror(errno));
} else if ((bytes = Read(pfd, buff, sizeof(buff)-1)) < 0) {
@ -146,7 +149,7 @@ static int xioopen_posixmq(
pfd, PROC_MSGSIZE, sizeof(buff)-1, strerror (errno));
Close(pfd);
} else {
sscanf(buff, "%ld", &attr.mq_msgsize);
sscanf(buff, "%ld", &msgsize);
Close(pfd);
}
}
@ -181,10 +184,13 @@ static int xioopen_posixmq(
}
/* Now open the message queue */
if (setopts)
if (setopts) {
attr.mq_maxmsg = maxmsg;
attr.mq_msgsize = msgsize;
Debug8("%s: mq_open(\"%s\", "F_mode", "F_mode", {flags=%ld, maxmsg=%ld, msgsize=%ld, curmsgs=%ld} )", argv[0], name, oflag, opt_mode, attr.mq_flags, attr.mq_maxmsg, attr.mq_msgsize, attr.mq_curmsgs);
else
} else {
Debug4("%s: mq_open(\"%s\", "F_mode", "F_mode", NULL)", argv[0], name, oflag, opt_mode);
}
mqd = mq_open(name, oflag, opt_mode, setopts ? &attr : NULL);
_errno = errno;
Debug1("mq_open() -> %d", mqd);
@ -206,8 +212,16 @@ static int xioopen_posixmq(
mq_close(mqd);
return STAT_NORETRY;
}
Info5("POSIXMQ queue \"%s\": flags=%ld, maxmsg=%ld, msgsize=%ld, curmsgs=%ld",
Info5("POSIXMQ queue \"%s\" attrs: { flags=%ld, maxmsg=%ld, msgsize=%ld, curmsgs=%ld }",
name, attr.mq_flags, attr.mq_maxmsg, attr.mq_msgsize, attr.mq_curmsgs);
if (setopts) {
if (attr.mq_maxmsg != maxmsg)
Warn2("mq_open(): requested maxmsg=%ld, but result is %ld",
maxmsg, attr.mq_maxmsg);
if (attr.mq_msgsize != msgsize)
Warn2("mq_open(): requested msgsize=%ld, but result is %ld",
msgsize, attr.mq_msgsize);
}
if (!dofork && !oneshot) {
return STAT_OK;