diff --git a/docs/src/content/docs/concepts/channels.mdx b/docs/src/content/docs/concepts/channels.mdx index db873769..ad48870d 100644 --- a/docs/src/content/docs/concepts/channels.mdx +++ b/docs/src/content/docs/concepts/channels.mdx @@ -182,7 +182,7 @@ Each socket counts its transfers. [`Channel`](/api/fair/mq/Channel/) gives the c | [`GetMessagesRx()`](/api/fair/mq/Channel/#GetMessagesRx) | Messages that `Receive()` got. | | [`GetBytesRx()`](/api/fair/mq/Channel/#GetBytesRx) | Bytes of these messages. | -The rules are in the send and receive functions of the transports ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L96-L255), [shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L118-L315)): +The rules are in the send and receive functions of the transports ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L96-L255), [shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L118-L320)): - The counters start at 0 when the transport makes the socket. In a device, this occurs in `BINDING` or `CONNECTING`. After `RESET DEVICE`, the next initialization makes new sockets, which start at 0 again. - Only a successful transfer counts. A timeout, an interruption or an error does not change the counters. diff --git a/docs/src/content/docs/concepts/messages.mdx b/docs/src/content/docs/concepts/messages.mdx index bb75efa3..e861b9e6 100644 --- a/docs/src/content/docs/concepts/messages.mdx +++ b/docs/src/content/docs/concepts/messages.mdx @@ -226,8 +226,7 @@ apply to each part. This test sends three parts, one of them empty, and receives :::caution[Rules for multipart messages] -- Do not send an empty `Parts` object. The zeromq transport returns `TransferCode::error`, but the - shmem transport sends a message with zero parts. +- Do not send an empty `Parts` object. Both transports return `TransferCode::error`. - Receive with the same form that the sender uses: `Parts` for `Parts`, `MessagePtr` for `MessagePtr`. The shmem transport cannot read a single message into a `Parts` object. - `Receive()` adds the received parts at the end of the `Parts` object. Give it an empty one. diff --git a/docs/src/content/docs/concepts/threads.mdx b/docs/src/content/docs/concepts/threads.mdx index 4c08309a..31d8ba59 100644 --- a/docs/src/content/docs/concepts/threads.mdx +++ b/docs/src/content/docs/concepts/threads.mdx @@ -88,7 +88,7 @@ Some rules follow from this table: | Subscribe and unsubscribe for state changes | Yes. A mutex protects the subscriptions. | [StateMachine.cxx](/source/fairmq/StateMachine.cxx/#L318-L335), test `PluginServices.SubscriptionThreadSafety` | | [`WaitForState()`](/api/fair/mq/Device/#WaitForState), [`WaitForNextState()`](/api/fair/mq/Device/#WaitForNextState) | Call them from one thread only. The queue of states gives each state to one caller. | [StateQueue.h](/source/fairmq/StateQueue.h/#L31-L35) | | [`Interrupt()`](/api/fair/mq/TransportFactory/#Interrupt), [`Resume()`](/api/fair/mq/TransportFactory/#Resume) of a transport | Yes. They set an atomic flag. | [zeromq/Context.h](/source/fairmq/zeromq/Context.h/#L149-L150), [shmem/Manager.h](/source/fairmq/shmem/Manager.h/#L283-L284), test `InterruptTransfer.Receive` | -| The byte and message counters of a channel, for example [`GetBytesTx()`](/api/fair/mq/Channel/#GetBytesTx) | Yes. The sockets keep them in atomic values. The rate logger thread reads them. | [zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L399-L402), [shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L459-L462) | +| The byte and message counters of a channel, for example [`GetBytesTx()`](/api/fair/mq/Channel/#GetBytesTx) | Yes. The sockets keep them in atomic values. The rate logger thread reads them. | [zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L399-L402), [shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L464-L467) | The device makes its channels in `INITIALIZING DEVICE`, after `Init()` ([Device.cxx](/source/fairmq/Device.cxx/#L153-L171)). It removes them in `RESETTING DEVICE` diff --git a/docs/src/content/docs/reference/channel-properties.mdx b/docs/src/content/docs/reference/channel-properties.mdx index fb7be8a6..5eeecf48 100644 --- a/docs/src/content/docs/reference/channel-properties.mdx +++ b/docs/src/content/docs/reference/channel-properties.mdx @@ -118,7 +118,7 @@ A poller and the data callbacks of `OnData()` use the transport of sub-channel 0 ### `sndBufSize` and `rcvBufSize` -The maximum number of messages in the send queue and in the receive queue of the socket. They are the ZeroMQ high-water marks `ZMQ_SNDHWM` and `ZMQ_RCVHWM` ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L310-L332)). The `shmem` transport sets the same options on its ZeroMQ socket, which carries the metadata of the messages ([shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L370-L392)). For ZeroMQ, 0 means no limit. A negative value makes `Validate()` throw `ChannelConfigurationError`. +The maximum number of messages in the send queue and in the receive queue of the socket. They are the ZeroMQ high-water marks `ZMQ_SNDHWM` and `ZMQ_RCVHWM` ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L310-L332)). The `shmem` transport sets the same options on its ZeroMQ socket, which carries the metadata of the messages ([shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L375-L397)). For ZeroMQ, 0 means no limit. A negative value makes `Validate()` throw `ChannelConfigurationError`. The behavior of a socket with a full queue depends on the socket type. The ZeroMQ documentation of `zmq_socket` describes it. diff --git a/docs/src/content/docs/reference/transfer-codes.mdx b/docs/src/content/docs/reference/transfer-codes.mdx index 4738e787..97db36bf 100644 --- a/docs/src/content/docs/reference/transfer-codes.mdx +++ b/docs/src/content/docs/reference/transfer-codes.mdx @@ -47,11 +47,8 @@ default is `-1` ([`Channel.h`](/source/fairmq/Channel.h/#L376-L377)). The steps the internal socket timeout of the zeromq and shmem transports ([`zeromq/Common.h`](/source/fairmq/zeromq/Common.h/#L64-L77)). -:::caution[Known defect] -The transports do not agree on an empty `Parts`. zeromq logs `Will not send empty vector` and returns -`error`. shmem sends a message with zero parts and returns 0. See the disabled test -`PartsTransfer.EmptyPartsIsRefused` in `test/parts/_access.cxx`. -::: +Both transports refuse to send an empty `Parts`. They log `Will not send empty vector` and return +`error`. The test `PartsTransfer.EmptyPartsIsRefused` in `test/parts/_access.cxx` checks this. ## Error codes diff --git a/fairmq/shmem/Socket.h b/fairmq/shmem/Socket.h index 149d8061..7458ae1a 100644 --- a/fairmq/shmem/Socket.h +++ b/fairmq/shmem/Socket.h @@ -209,8 +209,13 @@ class Socket final : public fair::mq::Socket } int elapsed = 0; - // meta msg format: | n | MetaHeader 1 | ... | MetaHeader n | padded to fMetadataMsgSize | auto const n = msgVec.size(); + if (n == 0) { // same as the zeromq transport + LOG(warn) << "Will not send empty vector"; + return static_cast(TransferCode::error); + } + + // meta msg format: | n | MetaHeader 1 | ... | MetaHeader n | padded to fMetadataMsgSize | zmq::ZMsg zmqMsg(std::max(fMetadataMsgSize, sizeof(std::size_t) + n * sizeof(MetaHeader))); auto meta_n = static_cast(zmqMsg.Data()); diff --git a/test/parts/_access.cxx b/test/parts/_access.cxx index e3bed4bb..95cff5a3 100644 --- a/test/parts/_access.cxx +++ b/test/parts/_access.cxx @@ -118,11 +118,8 @@ TEST_P(PartsTransfer, EmptyAndNonEmpty) EXPECT_EQ(AsString(in[2]), "cde"); } -// Known defect: the transports do not agree on an empty Parts. zeromq refuses -// it (TransferCode::error). shmem sends a message with zero parts, returns 0, -// and the receiver gets a Receive() with zero parts. Enable this test when -// both transports have the same behavior. -TEST_P(PartsTransfer, DISABLED_EmptyPartsIsRefused) +// All transports refuse to send an empty Parts. +TEST_P(PartsTransfer, EmptyPartsIsRefused) { ProgOptions config; test::Configure(config, tools::Uuid(), GetParam().expandedShmMetadata);