diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2021-05-19 22:34:30 +0200 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2021-05-19 23:05:49 +0200 |
commit | 6a9db5f5bc41b706ff108112c0d7ec7a287b779c (patch) | |
tree | d276519671887d563c250f8da29fd26c4b8246ab | |
parent | b64b2ce806867356f632bf45c5a5070da4cc2c19 (diff) | |
download | psmq-6a9db5f5bc41b706ff108112c0d7ec7a287b779c.tar.gz psmq-6a9db5f5bc41b706ff108112c0d7ec7a287b779c.tar.bz2 psmq-6a9db5f5bc41b706ff108112c0d7ec7a287b779c.zip |
lower limit for minimum msg size, update docs
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r-- | configure.ac | 5 | ||||
-rw-r--r-- | inc/psmq.h.in | 18 | ||||
-rw-r--r-- | psmq-common.h | 21 | ||||
-rwxr-xr-x | tst/psmq-progs.sh | 18 | ||||
-rw-r--r-- | tst/psmqd.c | 26 |
5 files changed, 37 insertions, 51 deletions
diff --git a/configure.ac b/configure.ac index d458250..8c377b0 100644 --- a/configure.ac +++ b/configure.ac @@ -126,9 +126,10 @@ AC_ARG_VAR([PSMQ_MSG_MAX], [Maximum length of message (topic + payload)]) AS_IF([test "x$PSMQ_MSG_MAX" = x], [PSMQ_MSG_MAX="255"]) #AC_DEFINE_UNQUOTED([PSMQ_MSG_MAX], [$PSMQ_MSG_MAX], [Maximum length of message (topic + payload]) -AS_IF([test $PSMQ_MSG_MAX -lt 9], +# reason for this limit is documented in inc/psmq.h.in +AS_IF([test $PSMQ_MSG_MAX -lt 6], [ - AC_MSG_ERROR(PSMQ_MSG_MAX must be at least 9) + AC_MSG_ERROR(PSMQ_MSG_MAX must be at least 6) ]) AC_OUTPUT diff --git a/inc/psmq.h.in b/inc/psmq.h.in index d5577bd..fbcf504 100644 --- a/inc/psmq.h.in +++ b/inc/psmq.h.in @@ -50,7 +50,7 @@ struct psmq }; /* broker and clients both use this structure to communicate with - * each other. psmq will create single mqueue with size of this + * each other. psmqd will create single mqueue with size of this * structure and one for each connected client, so it's worth keeping * it as small as possible. */ struct psmq_msg @@ -65,7 +65,7 @@ struct psmq_msg * descriptor of a client, an id to identify which client * is performing request * - * during reply from the broker it hold request result + * during reply from the broker it holds request result * (0 for success or errno when error occured) */ unsigned char data; } ctrl; @@ -78,7 +78,19 @@ struct psmq_msg * null-terminated after which payload follows. This allows * for some flexibility, ie if PSMQ_MSG_MAX was be 10, then * topic could be 3 bytes long and payload 7, but also - * topic could take 9 bytes and payload only 1. */ + * topic could take 9 bytes and payload only 1. + * + * Minium value of PSMQ_MSG_MAX that makes sense is 4, + * 2 characters for topic (which always starts with '/'), + * null terminator for topic, and one byte of data. You + * could live with 3 bytes, but that would make psmq to + * be able to only send topics without any payload. + * + * timeout ioctl needs 3 bytes of data, thus increasing + * minimum value of PSMQ_MSG_MAX to 6. You still manually + * se this to lower value like 3, but you would get + * errors and hangs when calling timeout ioctl, so it's + * not recommended nor supported. */ char data[PSMQ_MSG_MAX]; }; diff --git a/psmq-common.h b/psmq-common.h index 28d320a..63e70f3 100644 --- a/psmq-common.h +++ b/psmq-common.h @@ -18,19 +18,6 @@ * psmq cannot properly work with different values that these or * internal types forbids some values to be bigger */ -/* psmq reserves 5 bytes in psmq_msg buffer for control - * messages. Request control messages can take up to 7 bytes. - * Format of request control message is "xNNN\0", where "x" is a - * command, and "NNN" is a file descriptor of a client. "N" - * would be enough when there is less than 10 clients, but we - * support up to 256 clients so to prevent any bugs, we force max - * value here. Control topic must always end with null character. - * - * When broker sends back reply, topic is in format "x\0", so we - * are well within 5 bytes reserved for request. - */ -#define PSMQ_CTRL_LEN 7 - #if PSMQ_MAX_CLIENTS > (UCHAR_MAX - 1) /* psmq uses unsigned char to hold, and transmit client's file * descriptors, so you cannot set max clients to be bigger than @@ -39,14 +26,6 @@ # error PSMQ_MAX_CLIENTS must not be bigger than (UCHAR_MAX - 1) #endif -#define PSMQ_MAX_CLIENTS_HARD_MAX 999 -#if PSMQ_MAX_CLIENTS > PSMQ_MAX_CLIENTS_HARD_MAX - /* some systems might have char size 10bits or bigger, but even - * then, we cannot go beyond 999 clients, which is 9bytes long - * in string representation. */ -# error PSMQ_MAX_CLIENTS must not be bigger than 999 -#endif - #define PSMQ_MAX_CLIENTS_HARD_MIN 2 #if PSMQ_MAX_CLIENTS < PSMQ_MAX_CLIENTS_HARD_MIN /* psmq is a publish subscriber program, so at least one client diff --git a/tst/psmq-progs.sh b/tst/psmq-progs.sh index a406119..87765db 100755 --- a/tst/psmq-progs.sh +++ b/tst/psmq-progs.sh @@ -390,8 +390,8 @@ psmq_pub_missing_t_argument() psmq_pub_from_stdin() { start_psmqs - echo "test" | ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 - mt_fail "psmq_grep "test.." \"${psmqs_stdout}\"" + echo "t" | ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 + mt_fail "psmq_grep "t.." \"${psmqs_stdout}\"" stop_psmqs } psmq_pub_from_stdin_max_line() @@ -439,9 +439,9 @@ psmq_pub_from_stdin_multi_line() # -3 since topic is 3 bytes long "/1\0"; msg1="$(randstr $((psmq_msg_max - 3 - 2)) )" msg2="$(randstr $((psmq_msg_max - 3 - 2)) )" - msg3="$(randstr 2)" + msg3="$(randstr 1)" msg4="$(randstr $((psmq_msg_max - 3 - 2)) )" - msg5="$(randstr 2)" + msg5="$(randstr 1)" printf "%s\n%s\n%s\n%s\n%s\n" ${msg1} ${msg2} ${msg3} ${msg4} ${msg5} | \ ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 2> ${psmqp_stderr} @@ -465,7 +465,7 @@ psmq_pub_with_prio() psmq_pub_with_invalid_prio() { start_psmqs - ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 -mtest -p7812364 \ + ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 -mt -p7812364 \ 2> ${psmqp_stderr} mt_fail "psmq_grep \"f/failed to publish, invalid prio 7812364\" \ \"${psmqp_stderr}\"" @@ -474,10 +474,10 @@ psmq_pub_with_invalid_prio() psmq_pub_from_stdin_with_prio() { start_psmqs - echo test | ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 -p2 - mt_fail "psmq_grep \"topic: /1, priority: 2, paylen: 6, payload\" \ + echo t | ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 -p2 + mt_fail "psmq_grep \"topic: /1, priority: 2, paylen: 3, payload\" \ \"${psmqs_stdout}\"" - mt_fail "psmq_grep \"test.\" \"${psmqs_stdout}\"" + mt_fail "psmq_grep \"t..\" \"${psmqs_stdout}\"" stop_psmqs } psmq_pub_empty_message() @@ -551,7 +551,7 @@ psmq_pub_binary_many_split() psmq_pub_from_stdin_with_invalid_prio() { start_psmqs - echo test | ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 -p7812364 \ + echo t | ${psmqp_bin} -n${psmqp_name} -b${broker_name} -t/1 -p7812364 \ 2> ${psmqp_stderr} mt_fail "psmq_grep \"f/failed to publish, invalid prio 7812364\" \ \"${psmqp_stderr}\"" diff --git a/tst/psmqd.c b/tst/psmqd.c index b1163b1..01d3a03 100644 --- a/tst/psmqd.c +++ b/tst/psmqd.c @@ -667,7 +667,7 @@ static void psmqd_detect_dead_client(void) struct psmq sub_psmq; struct psmq_msg msg; struct timespec tp; - int i; + char i; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ @@ -712,6 +712,7 @@ static void psmqd_detect_dead_client(void) /* ========================================================================== ========================================================================== */ +#if PSMQ_MSG_MAX > 5 static void psmqd_multi_pub_sub(void *arg) { @@ -920,6 +921,7 @@ static void psmqd_multi_pub_sub(void *arg) free(psmq_pub); } +#endif /* ========================================================================== ========================================================================== */ @@ -1328,35 +1330,27 @@ void psmqd_test_group(void) char mps_name[64]; struct multi_ps mps; -#if PSMQ_MSG_MAX < 6 - /* these tests may spawn a lot of mqueues, so to prevent - * name clashes (and thus weird test failures), payload - * must be big enough to create that much queues */ +#if PSMQ_MAX_CLIENTS < 5 num_pub_max = 0; num_sub_max = 0; -#else -# if PSMQ_MAX_CLIENTS < 5 - num_pub_max = 0; - num_sub_max = 0; -# elif PSMQ_MAX_CLIENTS < 10 +#elif PSMQ_MAX_CLIENTS < 10 num_pub_max = 2; num_sub_max = 3; -# elif PSMQ_MAX_CLIENTS < 19 +#elif PSMQ_MAX_CLIENTS < 19 num_pub_max = 3; num_sub_max = 7; -# elif PSMQ_MAX_CLIENTS < 36 +#elif PSMQ_MAX_CLIENTS < 36 num_pub_max = 4; num_sub_max = 15; -# elif PSMQ_MAX_CLIENTS < 69 +#elif PSMQ_MAX_CLIENTS < 69 num_pub_max = 5; num_sub_max = 31; -# elif PSMQ_MAX_CLIENTS < 134 +#elif PSMQ_MAX_CLIENTS < 134 num_pub_max = 6; num_sub_max = 63; -# else +#else num_pub_max = 7; num_sub_max = 127; -# endif #endif /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |