Compare commits

...

46 Commits

Author SHA1 Message Date
Alexey Rybalchenko
291d00c73f Fix regression with ignored rateLogging channel argument 2019-01-07 11:28:15 +01:00
mkrzewic
4dc37efc12 Allow implicit conversion factory->resource
reduces boilerplate
2018-12-18 18:02:02 +01:00
Dennis Klein
5e24fdba8b Update alfa-ci 2018-12-11 01:24:18 +01:00
mkrzewic
0cb8f6166a Let getMessage deal with SSO
containers are not required to allocate, e.g. small string optimization
for now this is hypothetical since we cannot use std::basic_string with
at least gcc 7 since the basic_string there still uses the deprecated
rebind allocator interface (which pmr does not implement)
2018-12-10 15:10:53 +01:00
Alexey Rybalchenko
ee24144d61 Remove previously deprecated Copy method (since 1yr) 2018-11-28 21:16:29 +01:00
Alexey Rybalchenko
a9619a06d0 Add test for FairMQMessage::Rebuild 2018-11-28 21:16:29 +01:00
Alexey Rybalchenko
c605cbc3f6 Fix bug in shmem CloseMessage 2018-11-28 21:16:29 +01:00
Dennis Klein
ffd31aa09a Add coverity badge 2018-11-28 21:08:01 +01:00
Dennis Klein
a3fdfcad9e Adapt nightly build pipeline to new CI environments 2018-11-28 17:03:29 +01:00
Alexey Rybalchenko
44c0fe5abf Set EXTRA_FLAGS in CI script 2018-11-28 16:55:34 +01:00
Alexey Rybalchenko
66d6d0e07b Fix warning 2018-11-28 16:55:34 +01:00
Alexey Rybalchenko
ffbe90b638 Update to new DDS 2.2 API
- require DDS 2.2
 - fix regressions in automatic port binding
 - fix regression in channel API
 - update DDS example readme
2018-11-28 16:55:34 +01:00
Dennis Klein
dc1d7a23c1 Adapt CI script to new environments 2018-11-28 16:28:26 +01:00
Alexey Rybalchenko
33f5590626 Fix -Wsign-compare warning 2018-11-28 11:49:17 +01:00
mkrzewic
489bea5a51 Add simple test for factory pointer setting at receive 2018-11-27 14:36:35 +01:00
mkrzewic
cc0c525e0d Set pointer to factory also when receiving multi-part 2018-11-27 14:36:35 +01:00
Alexey Rybalchenko
25fcf13985 Move Bind/Connect/Attach to FairMQChannel 2018-11-13 11:08:48 +01:00
Alexey Rybalchenko
3ca0d7236a Add safety checks for process tools 2018-11-06 11:14:01 +01:00
Teo Mrnjavac
227a302903 Avoid boost::uuids::entropy_error on some systems 2018-11-05 13:18:08 +01:00
Alexey Rybalchenko
bd899a2806 Add test for channel validation 2018-11-01 15:43:40 +01:00
Alexey Rybalchenko
0b199e779a Add test for interface IP detection tools 2018-11-01 15:43:40 +01:00
Dennis Klein
5e4876c947 Allow plugins to create channels
This also fixes a bug, that prevented the usage of custom types with the
plugin config API.
2018-10-31 15:42:04 +01:00
Alexey Rybalchenko
3b5b2b501f Use exceptions for fatal errors in device/channel
- These will be caught by StateMachine::ProcessWork
   and lead to error state.
 - Solve issue where device goes into ready state if
   it encounters misconfigured channel in the Run.
 - deprecate WaitForInitialValidation().
2018-10-31 15:26:43 +01:00
Alexey Rybalchenko
3561255cf9 Add missing channel update handlers 2018-10-31 15:26:43 +01:00
mkrzewic
cbab7649be Return unique_ptr by value to allow RVO 2018-10-31 13:12:38 +01:00
mkrzewic
6ac94b7bc7 Fix ctor 2018-10-31 13:12:38 +01:00
mkrzewic
f9658f69a4 Alias boost::container::pmr -> fair::mq::pmr
so the eventual switch to std::pmr becomes easier
2018-10-31 13:12:38 +01:00
mkrzewic
34286ef75e Remove container adoption code 2018-10-31 13:12:38 +01:00
mkrzewic
1a07137dda Rename adoptVector into getVector 2018-10-31 13:12:38 +01:00
mkrzewic
1f42f49ae5 Update some comments 2018-10-31 13:12:38 +01:00
mkrzewic
d40bbfe208 Equip FairMQMessage with pointer to factory (at creation)
the patch seems big but most of it is just propagating the new notion of
constness of the factory - since it keeps track of created messages with
the internal allocator it no longer is const
2018-10-31 13:12:38 +01:00
mkrzewic
310b9647b5 Adopt FairMQMessage backed memory resource collection from AliceO2
Add a pmr interface to FairMQTransportFactory

refactor

Port the unit tests for MemoryResources

clang format
2018-10-31 13:12:38 +01:00
Alexey Rybalchenko
919193a1ad Extend transfer timeout test 2018-10-30 10:39:35 +01:00
Alexey Rybalchenko
0cfa9192d7 Deprecate Send-/ReceiveAsync, use timeout variant instead 2018-10-30 10:39:35 +01:00
Alexey Rybalchenko
c40bd7d6a9 Apply clang-tidy suggestions [performance-faster-string-find] 2018-10-29 13:45:36 +01:00
Alexey Rybalchenko
4951433330 Apply clang-tidy suggestions [modernize-loop-convert] 2018-10-29 13:45:36 +01:00
Alexey Rybalchenko
1b53538d8c Move test helper devices to headers 2018-10-18 21:33:47 +02:00
Alexey Rybalchenko
d4a4ea14d2 Add example/test for built-in devices 2018-10-18 21:33:47 +02:00
Alexey Rybalchenko
ffab4ac78c Add options tests and (re-)/enable more nanomsg tests 2018-10-17 13:28:50 +02:00
Alexey Rybalchenko
ce4062f3a0 Remove GetSocket interface that exposes transport details 2018-10-17 13:28:50 +02:00
Alexey Rybalchenko
f8824335a5 Add setters/getters for socket options 2018-10-17 13:28:50 +02:00
Alexey Rybalchenko
2e7005225e Remove sleeps from tests that were helping broken linger 2018-10-17 13:28:50 +02:00
Alexey Rybalchenko
dfa1b68867 Make factory classes final (optimization potential) 2018-10-17 13:28:50 +02:00
Alexey Rybalchenko
00800f16f1 Remove support for nanomsg <= 0.6 2018-10-17 13:28:50 +02:00
Alexey Rybalchenko
44acd4997d Implement nanomsg linger in our transport 2018-10-17 13:28:50 +02:00
Alexey Rybalchenko
cfb727181f Remove set/get timeout from general socket interface 2018-10-12 20:29:50 +02:00
115 changed files with 3278 additions and 2647 deletions

View File

@@ -49,7 +49,7 @@ find_package(Threads REQUIRED)
if(BUILD_FAIRMQ) if(BUILD_FAIRMQ)
find_package2(PUBLIC Boost VERSION 1.64 REQUIRED find_package2(PUBLIC Boost VERSION 1.64 REQUIRED
COMPONENTS program_options thread system filesystem regex date_time signals COMPONENTS container program_options thread system filesystem regex date_time signals
) )
find_package2(PUBLIC FairLogger VERSION 1.2.0 REQUIRED) find_package2(PUBLIC FairLogger VERSION 1.2.0 REQUIRED)
find_package2(PRIVATE ZeroMQ VERSION 4.1.5 REQUIRED) find_package2(PRIVATE ZeroMQ VERSION 4.1.5 REQUIRED)
@@ -67,7 +67,7 @@ if(BUILD_OFI_TRANSPORT)
endif() endif()
if(BUILD_DDS_PLUGIN) if(BUILD_DDS_PLUGIN)
find_package2(PRIVATE DDS VERSION 2.0 REQUIRED) find_package2(PRIVATE DDS VERSION 2.2 REQUIRED)
endif() endif()
if(BUILD_TESTING) if(BUILD_TESTING)

View File

@@ -4,6 +4,7 @@ Eulisse, Giulio
Karabowicz, Radoslaw Karabowicz, Radoslaw
Kretz, Matthias <kretz@kde.org> Kretz, Matthias <kretz@kde.org>
Krzewicki, Mikolaj Krzewicki, Mikolaj
Mrnjavac, Teo <teo.m@cern.ch>
Neskovic, Gvozden Neskovic, Gvozden
Richter, Matthias Richter, Matthias
Uhlig, Florian Uhlig, Florian

30
Jenkinsfile vendored
View File

@@ -8,6 +8,9 @@ def jobMatrix(String prefix, List specs, Closure callback) {
def nodes = [:] def nodes = [:]
for (spec in specs) { for (spec in specs) {
def label = specToLabel(spec) def label = specToLabel(spec)
def fairsoft = spec.fairsoft
def os = spec.os
def compiler = spec.compiler
nodes["${prefix}/${label}"] = { nodes["${prefix}/${label}"] = {
node(label) { node(label) {
githubNotify(context: "${prefix}/${label}", description: 'Building ...', status: 'PENDING') githubNotify(context: "${prefix}/${label}", description: 'Building ...', status: 'PENDING')
@@ -15,12 +18,31 @@ def jobMatrix(String prefix, List specs, Closure callback) {
deleteDir() deleteDir()
checkout scm checkout scm
sh """\
echo "export SIMPATH=\${SIMPATH_PREFIX}${fairsoft}" >> Dart.cfg
echo "export FAIRSOFT_VERSION=${fairsoft}" >> Dart.cfg
"""
if (os =~ /Debian/ && compiler =~ /gcc8/) {
sh '''\
echo "source /etc/profile.d/modules.sh" >> Dart.cfg
echo "module use /cvmfs/it.gsi.de/modulefiles" >> Dart.cfg
echo "module load compiler/gcc/8" >> Dart.cfg
'''
}
if (os =~ /MacOS/) {
sh "echo \"export EXTRA_FLAGS='-DCMAKE_CXX_COMPILER=clang++'\" >> Dart.cfg"
} else {
sh "echo \"export EXTRA_FLAGS='-DCMAKE_CXX_COMPILER=g++'\" >> Dart.cfg"
}
sh '''\ sh '''\
echo "export BUILDDIR=$PWD/build" >> Dart.cfg echo "export BUILDDIR=$PWD/build" >> Dart.cfg
echo "export SOURCEDIR=$PWD" >> Dart.cfg echo "export SOURCEDIR=$PWD" >> Dart.cfg
echo "export PATH=$SIMPATH/bin:$PATH" >> Dart.cfg echo "export PATH=\\\$SIMPATH/bin:\\\$PATH" >> Dart.cfg
echo "export GIT_BRANCH=$JOB_BASE_NAME" >> Dart.cfg echo "export GIT_BRANCH=$JOB_BASE_NAME" >> Dart.cfg
echo "echo \\\$PATH" >> Dart.cfg
''' '''
sh 'cat Dart.cfg'
callback.call(spec, label) callback.call(spec, label)
@@ -44,14 +66,14 @@ pipeline{
steps{ steps{
script { script {
def build_jobs = jobMatrix('alfa-ci/build', [ def build_jobs = jobMatrix('alfa-ci/build', [
[os: 'Debian8', arch: 'x86_64', compiler: 'gcc4.9', fairsoft: 'may18'], [os: 'Debian8', arch: 'x86_64', compiler: 'gcc8.1.0', fairsoft: 'fairmq_dev'],
[os: 'MacOS10.13', arch: 'x86_64', compiler: 'AppleLLVM9.0.0', fairsoft: 'may18'], [os: 'MacOS10.13', arch: 'x86_64', compiler: 'AppleLLVM10.0.0', fairsoft: 'fairmq_dev'],
]) { spec, label -> ]) { spec, label ->
sh './Dart.sh alfa_ci Dart.cfg' sh './Dart.sh alfa_ci Dart.cfg'
} }
def profile_jobs = jobMatrix('alfa-ci/codecov', [ def profile_jobs = jobMatrix('alfa-ci/codecov', [
[os: 'Debian8', arch: 'x86_64', compiler: 'gcc4.9', fairsoft: 'may18'], [os: 'Debian8', arch: 'x86_64', compiler: 'gcc8.1.0', fairsoft: 'fairmq_dev'],
]) { spec, label -> ]) { spec, label ->
withCredentials([string(credentialsId: 'fairmq_codecov_token', variable: 'CODECOV_TOKEN')]) { withCredentials([string(credentialsId: 'fairmq_codecov_token', variable: 'CODECOV_TOKEN')]) {
sh './Dart.sh codecov Dart.cfg' sh './Dart.sh codecov Dart.cfg'

View File

@@ -8,12 +8,40 @@ def buildMatrix(List specs, Closure callback) {
def nodes = [:] def nodes = [:]
for (spec in specs) { for (spec in specs) {
def label = specToLabel(spec) def label = specToLabel(spec)
def fairsoft = spec.fairsoft
def os = spec.os
def compiler = spec.compiler
nodes[label] = { nodes[label] = {
node(label) { node(label) {
try { try {
deleteDir() deleteDir()
checkout scm checkout scm
sh """\
echo "export SIMPATH=\${SIMPATH_PREFIX}${fairsoft}" >> Dart.cfg
echo "export FAIRSOFT_VERSION=${fairsoft}" >> Dart.cfg
"""
if (os =~ /Debian/ && compiler =~ /gcc8/) {
sh '''\
echo "source /etc/profile.d/modules.sh" >> Dart.cfg
echo "module use /cvmfs/it.gsi.de/modulefiles" >> Dart.cfg
echo "module load compiler/gcc/8" >> Dart.cfg
'''
}
if (os =~ /MacOS/) {
sh "echo \"export EXTRA_FLAGS='-DCMAKE_CXX_COMPILER=clang++'\" >> Dart.cfg"
} else {
sh "echo \"export EXTRA_FLAGS='-DCMAKE_CXX_COMPILER=g++'\" >> Dart.cfg"
}
sh '''\
echo "export BUILDDIR=$PWD/build" >> Dart.cfg
echo "export SOURCEDIR=$PWD" >> Dart.cfg
echo "export PATH=\\\$SIMPATH/bin:\\\$PATH" >> Dart.cfg
echo "export GIT_BRANCH=dev" >> Dart.cfg
echo "echo \\\$PATH" >> Dart.cfg
'''
sh 'cat Dart.cfg'
callback.call(spec, label) callback.call(spec, label)
deleteDir() deleteDir()
@@ -35,16 +63,9 @@ pipeline{
steps{ steps{
script { script {
parallel(buildMatrix([ parallel(buildMatrix([
[os: 'Debian8', arch: 'x86_64', compiler: 'gcc4.9', fairsoft: 'may18'], [os: 'Debian8', arch: 'x86_64', compiler: 'gcc8.1.0', fairsoft: 'fairmq_dev'],
[os: 'MacOS10.11', arch: 'x86_64', compiler: 'AppleLLVM8.0.0', fairsoft: 'may18'], [os: 'MacOS10.13', arch: 'x86_64', compiler: 'AppleLLVM10.0.0', fairsoft: 'fairmq_dev'],
[os: 'MacOS10.13', arch: 'x86_64', compiler: 'AppleLLVM9.0.0', fairsoft: 'may18'],
]) { spec, label -> ]) { spec, label ->
sh '''\
echo "export BUILDDIR=$PWD/build" >> Dart.cfg
echo "export SOURCEDIR=$PWD" >> Dart.cfg
echo "export PATH=$SIMPATH/bin:$PATH" >> Dart.cfg
echo "export GIT_BRANCH=dev" >> Dart.cfg
'''
sh './Dart.sh Nightly Dart.cfg' sh './Dart.sh Nightly Dart.cfg'
sh './Dart.sh Profile Dart.cfg' sh './Dart.sh Profile Dart.cfg'
}) })

View File

@@ -1,5 +1,5 @@
<!-- {#mainpage} --> <!-- {#mainpage} -->
# FairMQ [![license](https://alfa-ci.gsi.de/shields/badge/license-LGPL--3.0-orange.svg)](COPYRIGHT) [![build status](https://alfa-ci.gsi.de/buildStatus/icon?job=FairRootGroup/FairMQ/master)](https://alfa-ci.gsi.de/blue/organizations/jenkins/FairRootGroup%2FFairMQ/branches) [![test coverage master branch](https://codecov.io/gh/FairRootGroup/FairMQ/branch/master/graph/badge.svg)](https://codecov.io/gh/FairRootGroup/FairMQ/branch/master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/6b648d95d68d4c4eae833b84f84d299c)](https://www.codacy.com/app/dennisklein/FairMQ?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=FairRootGroup/FairMQ&amp;utm_campaign=Badge_Grade) # FairMQ [![license](https://alfa-ci.gsi.de/shields/badge/license-LGPL--3.0-orange.svg)](COPYRIGHT) [![build status](https://alfa-ci.gsi.de/buildStatus/icon?job=FairRootGroup/FairMQ/master)](https://alfa-ci.gsi.de/blue/organizations/jenkins/FairRootGroup%2FFairMQ/branches) [![test coverage master branch](https://codecov.io/gh/FairRootGroup/FairMQ/branch/master/graph/badge.svg)](https://codecov.io/gh/FairRootGroup/FairMQ/branch/master) [![Coverity Badge](https://alfa-ci.gsi.de/shields/coverity/scan/fairrootgroup-fairmq.svg)](https://scan.coverity.com/projects/fairrootgroup-fairmq) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/6b648d95d68d4c4eae833b84f84d299c)](https://www.codacy.com/app/dennisklein/FairMQ?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=FairRootGroup/FairMQ&amp;utm_campaign=Badge_Grade)
C++ Message Queuing Library and Framework C++ Message Queuing Library and Framework

View File

@@ -8,6 +8,7 @@
add_subdirectory(1-1) add_subdirectory(1-1)
add_subdirectory(1-n-1) add_subdirectory(1-n-1)
add_subdirectory(builtin-devices)
add_subdirectory(copypush) add_subdirectory(copypush)
add_subdirectory(dds) add_subdirectory(dds)
add_subdirectory(multipart) add_subdirectory(multipart)

View File

@@ -0,0 +1,50 @@
################################################################################
# Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
# #
# This software is distributed under the terms of the #
# GNU Lesser General Public Licence (LGPL) version 3, #
# copied verbatim in the file "LICENSE" #
################################################################################
set(EX_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(FAIRMQ_BIN_DIR ${CMAKE_BINARY_DIR}/fairmq)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fairmq-start-ex-builtin-devices.sh.in ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-builtin-devices.sh)
# test
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test-ex-builtin-devices.sh.in ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh)
add_test(NAME Example-Builtin-Devices-zeromq COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh zeromq)
set_tests_properties(Example-Builtin-Devices-zeromq PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Configured maximum number of iterations reached")
if(BUILD_NANOMSG_TRANSPORT)
add_test(NAME Example-Builtin-Devices-nanomsg COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh nanomsg)
set_tests_properties(Example-Builtin-Devices-nanomsg PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Configured maximum number of iterations reached")
endif()
add_test(NAME Example-Builtin-Devices-shmem COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh shmem)
set_tests_properties(Example-Builtin-Devices-shmem PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Configured maximum number of iterations reached")
add_test(NAME Example-Builtin-Devices-zeromq-multipart COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh zeromq true 2)
set_tests_properties(Example-Builtin-Devices-zeromq-multipart PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Configured maximum number of iterations reached")
if(BUILD_NANOMSG_TRANSPORT)
add_test(NAME Example-Builtin-Devices-nanomsg-multipart COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh nanomsg true 2)
set_tests_properties(Example-Builtin-Devices-nanomsg-multipart PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Configured maximum number of iterations reached")
endif()
add_test(NAME Example-Builtin-Devices-shmem-multipart COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh shmem true 2)
set_tests_properties(Example-Builtin-Devices-shmem-multipart PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Configured maximum number of iterations reached")
# install
# configure run script with different executable paths for build and for install directories
set(EX_BIN_DIR ${CMAKE_INSTALL_PREFIX}/${PROJECT_INSTALL_BINDIR})
set(FAIRMQ_BIN_DIR ${CMAKE_INSTALL_PREFIX}/${PROJECT_INSTALL_BINDIR}/fairmq)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fairmq-start-ex-builtin-devices.sh.in ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-builtin-devices.sh_install)
install(
PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-builtin-devices.sh_install
DESTINATION ${PROJECT_INSTALL_BINDIR}
RENAME fairmq-start-ex-builtin-devices.sh
)

View File

@@ -0,0 +1,4 @@
Built-in devices
==========================
This example demonstrates use of generic devices that are provided with FairMQ - BenchmarkSampler, Merger, Multiplier, Proxy, Sink, Splitter. They are all connected in one topology and transfer some dummy buffers generated by the BenchmarkSampler.

View File

@@ -0,0 +1,93 @@
#!/bin/bash
export FAIRMQ_PATH=@FAIRMQ_BIN_DIR@
transport="zeromq"
multipart="false"
numParts="1"
if [[ $1 =~ ^[a-z]+$ ]]; then
transport=$1
fi
if [[ $2 =~ ^[a-z]+$ ]]; then
multipart=$2
fi
if [[ $3 =~ ^[0-9]+$ ]]; then
numParts=$3
fi
SAMPLER="fairmq-bsampler"
SAMPLER+=" --id bsampler1"
SAMPLER+=" --transport $transport"
SAMPLER+=" --control interactive"
SAMPLER+=" --severity debug"
SAMPLER+=" --msg-size 100000"
SAMPLER+=" --multipart $multipart"
SAMPLER+=" --num-parts $numParts"
SAMPLER+=" --msg-rate 100"
SAMPLER+=" --max-iterations 0"
SAMPLER+=" --out-channel data1"
SAMPLER+=" --channel-config name=data1,type=push,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5555"
xterm -geometry 90x20+0+175 -hold -e @FAIRMQ_BIN_DIR@/$SAMPLER &
SPLITTER="fairmq-splitter"
SPLITTER+=" --id splitter"
SPLITTER+=" --transport $transport"
SPLITTER+=" --multipart $multipart"
SPLITTER+=" --in-channel data1"
SPLITTER+=" --out-channel data2"
SPLITTER+=" --channel-config name=data1,type=pull,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5555"
SPLITTER+=" name=data2,type=push,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5556,address=tcp://localhost:5557"
xterm -geometry 90x20+0+475 -hold -e @FAIRMQ_BIN_DIR@/$SPLITTER &
PROXY1="fairmq-proxy"
PROXY1+=" --id proxy1"
PROXY1+=" --transport $transport"
PROXY1+=" --multipart $multipart"
PROXY1+=" --in-channel data2"
PROXY1+=" --out-channel data3"
PROXY1+=" --channel-config name=data2,type=pull,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5556"
PROXY1+=" name=data3,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5558"
xterm -geometry 90x20+550+175 -hold -e @FAIRMQ_BIN_DIR@/$PROXY1 &
PROXY2="fairmq-proxy"
PROXY2+=" --id proxy2"
PROXY2+=" --transport $transport"
PROXY2+=" --multipart $multipart"
PROXY2+=" --in-channel data2"
PROXY2+=" --out-channel data3"
PROXY2+=" --channel-config name=data2,type=pull,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5557"
PROXY2+=" name=data3,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5559"
xterm -geometry 90x20+550+475 -hold -e @FAIRMQ_BIN_DIR@/$PROXY2 &
MERGER="fairmq-merger"
MERGER+=" --id merger"
MERGER+=" --transport $transport"
MERGER+=" --multipart $multipart"
MERGER+=" --in-channel data3"
MERGER+=" --out-channel data4"
MERGER+=" --channel-config name=data3,type=pull,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5558,address=tcp://localhost:5559"
MERGER+=" name=data4,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5560"
xterm -geometry 90x20+1100+50 -hold -e @FAIRMQ_BIN_DIR@/$MERGER &
MULTIPLIER="fairmq-multiplier"
MULTIPLIER+=" --id multiplier"
MULTIPLIER+=" --transport $transport"
MULTIPLIER+=" --multipart $multipart"
MULTIPLIER+=" --in-channel data4"
MULTIPLIER+=" --out-channel data5"
MULTIPLIER+=" --channel-config name=data4,type=pull,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5560"
MULTIPLIER+=" name=data5,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5561,address=tcp://localhost:5561"
xterm -geometry 90x20+1100+350 -hold -e @FAIRMQ_BIN_DIR@/$MULTIPLIER &
SINK="fairmq-sink"
SINK+=" --id sink1"
SINK+=" --transport $transport"
SINK+=" --severity debug"
SINK+=" --multipart $multipart"
SINK+=" --max-iterations 0"
SINK+=" --in-channel data5"
SINK+=" --channel-config name=data5,type=pull,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5561"
xterm -geometry 90x20+1100+650 -hold -e @FAIRMQ_BIN_DIR@/$SINK &

View File

@@ -0,0 +1,148 @@
#!/bin/bash
export FAIRMQ_PATH=@FAIRMQ_BIN_DIR@
SESSION="$(@CMAKE_BINARY_DIR@/fairmq/fairmq-uuid-gen -h)"
transport="zeromq"
multipart="false"
numParts="1"
if [[ $1 =~ ^[a-z]+$ ]]; then
transport=$1
fi
if [[ $2 =~ ^[a-z]+$ ]]; then
multipart=$2
fi
if [[ $3 =~ ^[0-9]+$ ]]; then
numParts=$3
fi
# setup a trap to kill everything if the test fails/timeouts
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SPLITTER_PID; kill -TERM $PROXY1_PID; kill -TERM $PROXY2_PID; kill -TERM $MERGER_PID; kill -TERM $MULTIPLIER_PID; kill -TERM $SINK_PID;' TERM
SAMPLER="fairmq-bsampler"
SAMPLER+=" --id bsampler1"
SAMPLER+=" --session $SESSION"
SAMPLER+=" --transport $transport"
SAMPLER+=" --color false"
SAMPLER+=" --control static"
SAMPLER+=" --verbosity veryhigh"
SAMPLER+=" --severity debug"
SAMPLER+=" --msg-size 100000"
SAMPLER+=" --multipart $multipart"
SAMPLER+=" --num-parts $numParts"
SAMPLER+=" --msg-rate 1"
SAMPLER+=" --max-iterations 0"
SAMPLER+=" --out-channel data1"
SAMPLER+=" --channel-config name=data1,type=push,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5555"
@FAIRMQ_BIN_DIR@/$SAMPLER &
SAMPLER_PID=$!
SPLITTER="fairmq-splitter"
SPLITTER+=" --id splitter"
SPLITTER+=" --session $SESSION"
SPLITTER+=" --transport $transport"
SPLITTER+=" --color false"
SPLITTER+=" --control static"
SPLITTER+=" --verbosity veryhigh"
SPLITTER+=" --multipart $multipart"
SPLITTER+=" --in-channel data1"
SPLITTER+=" --out-channel data2"
SPLITTER+=" --channel-config name=data1,type=pull,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5555"
SPLITTER+=" name=data2,type=push,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5556,address=tcp://localhost:5557"
@FAIRMQ_BIN_DIR@/$SPLITTER &
SPLITTER_PID=$!
PROXY1="fairmq-proxy"
PROXY1+=" --id proxy1"
PROXY1+=" --session $SESSION"
PROXY1+=" --transport $transport"
PROXY1+=" --color false"
PROXY1+=" --control static"
PROXY1+=" --verbosity veryhigh"
PROXY1+=" --multipart $multipart"
PROXY1+=" --in-channel data2"
PROXY1+=" --out-channel data3"
PROXY1+=" --channel-config name=data2,type=pull,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5556"
PROXY1+=" name=data3,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5558"
@FAIRMQ_BIN_DIR@/$PROXY1 &
PROXY1_PID=$!
PROXY2="fairmq-proxy"
PROXY2+=" --id proxy2"
PROXY2+=" --session $SESSION"
PROXY2+=" --transport $transport"
PROXY2+=" --color false"
PROXY2+=" --control static"
PROXY2+=" --verbosity veryhigh"
PROXY2+=" --multipart $multipart"
PROXY2+=" --in-channel data2"
PROXY2+=" --out-channel data3"
PROXY2+=" --channel-config name=data2,type=pull,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5557"
PROXY2+=" name=data3,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5559"
@FAIRMQ_BIN_DIR@/$PROXY2 &
PROXY2_PID=$!
MERGER="fairmq-merger"
MERGER+=" --id merger"
MERGER+=" --session $SESSION"
MERGER+=" --transport $transport"
MERGER+=" --color false"
MERGER+=" --control static"
MERGER+=" --verbosity veryhigh"
MERGER+=" --multipart $multipart"
MERGER+=" --in-channel data3"
MERGER+=" --out-channel data4"
MERGER+=" --channel-config name=data3,type=pull,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5558,address=tcp://localhost:5559"
MERGER+=" name=data4,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5560"
@FAIRMQ_BIN_DIR@/$MERGER &
MERGER_PID=$!
MULTIPLIER="fairmq-multiplier"
MULTIPLIER+=" --id multiplier"
MULTIPLIER+=" --session $SESSION"
MULTIPLIER+=" --transport $transport"
MULTIPLIER+=" --color false"
MULTIPLIER+=" --control static"
MULTIPLIER+=" --verbosity veryhigh"
MULTIPLIER+=" --multipart $multipart"
MULTIPLIER+=" --in-channel data4"
MULTIPLIER+=" --out-channel data5"
MULTIPLIER+=" --channel-config name=data4,type=pull,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5560"
MULTIPLIER+=" name=data5,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5561,address=tcp://localhost:5561"
@FAIRMQ_BIN_DIR@/$MULTIPLIER &
MULTIPLIER_PID=$!
SINK="fairmq-sink"
SINK+=" --id sink1"
SINK+=" --session $SESSION"
SINK+=" --transport $transport"
SINK+=" --color false"
SINK+=" --control static"
SINK+=" --verbosity veryhigh"
SINK+=" --severity debug"
SINK+=" --multipart $multipart"
SINK+=" --max-iterations 2"
SINK+=" --in-channel data5"
SINK+=" --channel-config name=data5,type=pull,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5561"
@FAIRMQ_BIN_DIR@/$SINK &
SINK_PID=$!
wait $SINK_PID
kill -SIGINT $SAMPLER_PID
kill -SIGINT $SPLITTER_PID
kill -SIGINT $PROXY1_PID
kill -SIGINT $PROXY2_PID
kill -SIGINT $MERGER_PID
kill -SIGINT $MULTIPLIER_PID
wait $SAMPLER_PID
wait $SPLITTER_PID
wait $PROXY1_PID
wait $PROXY2_PID
wait $MERGER_PID
wait $MULTIPLIER_PID

View File

@@ -47,7 +47,7 @@ The configuration of the channel connection addresses is done by the DDS plugin
Note that the attributes `value` contain a different value. Note that the attributes `value` contain a different value.
##### 4. Start DDS server. ##### 4. Start DDS session.
First you need to initialize DDS environment: First you need to initialize DDS environment:
@@ -55,10 +55,10 @@ First you need to initialize DDS environment:
source DDS_env.sh # this script is located in the DDS installation directory source DDS_env.sh # this script is located in the DDS installation directory
``` ```
The DDS server is started with: The DDS session is started with:
```bash ```bash
dds-server start -s dds-session start
``` ```
##### 5. Submit DDS Agents (configured in the hosts file). ##### 5. Submit DDS Agents (configured in the hosts file).
@@ -91,7 +91,7 @@ A simple utility (fairmq-dds-command-ui) is included with FairMQ to send command
To see it in action, start the fairmq-dds-command-ui while the topology is running. Run the utility with `-h` to see everything that it can do. To see it in action, start the fairmq-dds-command-ui while the topology is running. Run the utility with `-h` to see everything that it can do.
The utility requires a session parameter to connect to appropriate DDS session. The session value is given when starting dds-server. The utility requires a session parameter to connect to appropriate DDS session. The session value is given when starting dds-session.
By default the command UI sends commands to all tasks. This can be further refined by giving a specific topology path via `-p` argument. By default the command UI sends commands to all tasks. This can be further refined by giving a specific topology path via `-p` argument.
Given our topology file, here are some examples of valid paths: Given our topology file, here are some examples of valid paths:
@@ -108,15 +108,15 @@ Given our topology file, here are some examples of valid paths:
./fairmq/plugins/DDS/fairmq-dds-command-ui -s 937ffbca-b524-44d8-9898-1d69aedc3751 -c c -p main/ProcessorGroup/Processor_9 ./fairmq/plugins/DDS/fairmq-dds-command-ui -s 937ffbca-b524-44d8-9898-1d69aedc3751 -c c -p main/ProcessorGroup/Processor_9
``` ```
##### 9. Stop DDS server/topology. ##### 9. Stop DDS session/topology.
The execution of tasks can be stopped with: The execution of tasks can be stopped with:
```bash ```bash
dds-topology --stop dds-topology --stop
``` ```
Or by stopping the DDS server: Or by stopping the DDS session:
```bash ```bash
dds-server stop dds-session stop
``` ```
For general DDS documentation please refer to [DDS Website](http://dds.gsi.de/). For general DDS documentation please refer to [DDS Website](http://dds.gsi.de/).

View File

@@ -14,12 +14,12 @@ SAMPLER+=" --severity debug"
SAMPLER+=" --msg-size $msgSize" SAMPLER+=" --msg-size $msgSize"
# SAMPLER+=" --rate 10" # SAMPLER+=" --rate 10"
SAMPLER+=" --transport shmem" SAMPLER+=" --transport shmem"
SAMPLER+=" --channel-config name=data,type=push,method=bind,address=tcp://127.0.0.1:7777" SAMPLER+=" --channel-config name=data,type=push,method=bind,address=tcp://127.0.0.1:7777,sndKernelSize=212992"
xterm -geometry 80x23+0+0 -hold -e @EX_BIN_DIR@/$SAMPLER & xterm -geometry 80x23+0+0 -hold -e @EX_BIN_DIR@/$SAMPLER &
SINK="fairmq-ex-region-sink" SINK="fairmq-ex-region-sink"
SINK+=" --id sink1" SINK+=" --id sink1"
SINK+=" --severity debug" SINK+=" --severity debug"
SINK+=" --transport shmem" SINK+=" --transport shmem"
SINK+=" --channel-config name=data,type=pull,method=connect,address=tcp://127.0.0.1:7777" SINK+=" --channel-config name=data,type=pull,method=connect,address=tcp://127.0.0.1:7777,rcvKernelSize=212992"
xterm -geometry 80x23+500+0 -hold -e @EX_BIN_DIR@/$SINK & xterm -geometry 80x23+500+0 -hold -e @EX_BIN_DIR@/$SINK &

View File

@@ -49,6 +49,8 @@ set(FAIRMQ_PUBLIC_HEADER_FILES
FairMQSocket.h FairMQSocket.h
FairMQStateMachine.h FairMQStateMachine.h
FairMQTransportFactory.h FairMQTransportFactory.h
MemoryResources.h
MemoryResourceTools.h
Tools.h Tools.h
Transports.h Transports.h
options/FairMQProgOptions.h options/FairMQProgOptions.h
@@ -155,6 +157,7 @@ set(FAIRMQ_SOURCE_FILES
zeromq/FairMQUnmanagedRegionZMQ.cxx zeromq/FairMQUnmanagedRegionZMQ.cxx
zeromq/FairMQSocketZMQ.cxx zeromq/FairMQSocketZMQ.cxx
zeromq/FairMQTransportFactoryZMQ.cxx zeromq/FairMQTransportFactoryZMQ.cxx
MemoryResources.cxx
) )
if(BUILD_NANOMSG_TRANSPORT) if(BUILD_NANOMSG_TRANSPORT)
@@ -232,6 +235,7 @@ endif()
target_link_libraries(${_target} target_link_libraries(${_target}
INTERFACE # only consumers link against interface dependencies INTERFACE # only consumers link against interface dependencies
Boost::container
PUBLIC # libFairMQ AND consumers of libFairMQ link aginst public dependencies PUBLIC # libFairMQ AND consumers of libFairMQ link aginst public dependencies
Threads::Threads Threads::Threads

File diff suppressed because it is too large Load Diff

View File

@@ -10,10 +10,12 @@
#define FAIRMQCHANNEL_H_ #define FAIRMQCHANNEL_H_
#include <string> #include <string>
#include <memory> // unique_ptr #include <memory> // unique_ptr, shared_ptr
#include <vector> #include <vector>
#include <atomic> #include <atomic>
#include <mutex> #include <mutex>
#include <stdexcept>
#include <utility> // std::move
#include <FairMQTransportFactory.h> #include <FairMQTransportFactory.h>
#include <FairMQSocket.h> #include <FairMQSocket.h>
@@ -42,6 +44,14 @@ class FairMQChannel
/// @param factory TransportFactory /// @param factory TransportFactory
FairMQChannel(const std::string& name, const std::string& type, std::shared_ptr<FairMQTransportFactory> factory); FairMQChannel(const std::string& name, const std::string& type, std::shared_ptr<FairMQTransportFactory> factory);
/// Constructor
/// @param name Channel name
/// @param type Socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
/// @param method Socket method (bind/connect)
/// @param address Network address to bind/connect to (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
/// @param factory TransportFactory
FairMQChannel(const std::string& name, const std::string& type, const std::string& method, const std::string& address, std::shared_ptr<FairMQTransportFactory> factory);
/// Copy Constructor /// Copy Constructor
FairMQChannel(const FairMQChannel&); FairMQChannel(const FairMQChannel&);
@@ -49,18 +59,20 @@ class FairMQChannel
FairMQChannel& operator=(const FairMQChannel&); FairMQChannel& operator=(const FairMQChannel&);
/// Default destructor /// Default destructor
virtual ~FairMQChannel(); virtual ~FairMQChannel() {}
FairMQSocket const & GetSocket() const; struct ChannelConfigurationError : std::runtime_error { using std::runtime_error::runtime_error; };
auto Bind(const std::string& address) -> bool FairMQSocket& GetSocket() const;
bool Bind(const std::string& address)
{ {
fMethod = "bind"; fMethod = "bind";
fAddress = address; fAddress = address;
return fSocket->Bind(address); return fSocket->Bind(address);
} }
auto Connect(const std::string& address) -> void bool Connect(const std::string& address)
{ {
fMethod = "connect"; fMethod = "connect";
fAddress = address; fAddress = address;
@@ -69,15 +81,18 @@ class FairMQChannel
/// Get channel name /// Get channel name
/// @return Returns full channel name (e.g. "data[0]") /// @return Returns full channel name (e.g. "data[0]")
std::string GetChannelName() const; std::string GetChannelName() const { return GetName(); } // TODO: deprecate this in favor of following
std::string GetName() const;
/// Get channel prefix /// Get channel prefix
/// @return Returns channel prefix (e.g. "data" in "data[0]") /// @return Returns channel prefix (e.g. "data" in "data[0]")
std::string GetChannelPrefix() const; std::string GetChannelPrefix() const { return GetPrefix(); } // TODO: deprecate this in favor of following
std::string GetPrefix() const;
/// Get channel index /// Get channel index
/// @return Returns channel index (e.g. 0 in "data[0]") /// @return Returns channel index (e.g. 0 in "data[0]")
std::string GetChannelIndex() const; std::string GetChannelIndex() const { return GetIndex(); } // TODO: deprecate this in favor of following
std::string GetIndex() const;
/// Get socket type /// Get socket type
/// @return Returns socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/) /// @return Returns socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
@@ -111,10 +126,26 @@ class FairMQChannel
/// @return Returns socket kernel transmit receive buffer size (in bytes) /// @return Returns socket kernel transmit receive buffer size (in bytes)
int GetRcvKernelSize() const; int GetRcvKernelSize() const;
/// Get linger duration (in milliseconds)
/// @return Returns linger duration (in milliseconds)
int GetLinger() const;
/// Get socket rate logging interval (in seconds) /// Get socket rate logging interval (in seconds)
/// @return Returns socket rate logging interval (in seconds) /// @return Returns socket rate logging interval (in seconds)
int GetRateLogging() const; int GetRateLogging() const;
/// Get start of the port range for automatic binding
/// @return start of the port range
int GetPortRangeMin() const;
/// Get end of the port range for automatic binding
/// @return end of the port range
int GetPortRangeMax() const;
/// Set automatic binding (pick random port if bind fails)
/// @return true/false, true if automatic binding is enabled
bool GetAutoBind() const;
/// Set socket type /// Set socket type
/// @param type Socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/) /// @param type Socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
void UpdateType(const std::string& type); void UpdateType(const std::string& type);
@@ -147,13 +178,30 @@ class FairMQChannel
/// @param rcvKernelSize Socket receive buffer size (in bytes) /// @param rcvKernelSize Socket receive buffer size (in bytes)
void UpdateRcvKernelSize(const int rcvKernelSize); void UpdateRcvKernelSize(const int rcvKernelSize);
/// Set linger duration (in milliseconds)
/// @param duration linger duration (in milliseconds)
void UpdateLinger(const int duration);
/// Set socket rate logging interval (in seconds) /// Set socket rate logging interval (in seconds)
/// @param rateLogging Socket rate logging interval (in seconds) /// @param rateLogging Socket rate logging interval (in seconds)
void UpdateRateLogging(const int rateLogging); void UpdateRateLogging(const int rateLogging);
/// Set start of the port range for automatic binding
/// @param minPort start of the port range
void UpdatePortRangeMin(const int minPort);
/// Set end of the port range for automatic binding
/// @param maxPort end of the port range
void UpdatePortRangeMax(const int maxPort);
/// Set automatic binding (pick random port if bind fails)
/// @param autobind true/false, true to enable automatic binding
void UpdateAutoBind(const bool autobind);
/// Set channel name /// Set channel name
/// @param name Arbitrary channel name /// @param name Arbitrary channel name
void UpdateChannelName(const std::string& name); void UpdateChannelName(const std::string& name) { UpdateName(name); } // TODO: deprecate this in favor of following
void UpdateName(const std::string& name);
/// Checks if the configured channel settings are valid (checks the validity parameter, without running full validation (as oposed to ValidateChannel())) /// Checks if the configured channel settings are valid (checks the validity parameter, without running full validation (as oposed to ValidateChannel()))
/// @return true if channel settings are valid, false otherwise. /// @return true if channel settings are valid, false otherwise.
@@ -161,166 +209,163 @@ class FairMQChannel
/// Validates channel configuration /// Validates channel configuration
/// @return true if channel settings are valid, false otherwise. /// @return true if channel settings are valid, false otherwise.
bool ValidateChannel(); bool ValidateChannel() // TODO: deprecate this
{
return Validate();
}
/// Validates channel configuration
/// @return true if channel settings are valid, false otherwise.
bool Validate();
void Init();
bool ConnectEndpoint(const std::string& endpoint);
bool BindEndpoint(std::string& endpoint);
/// Resets the channel (requires validation to be used again). /// Resets the channel (requires validation to be used again).
void ResetChannel(); void ResetChannel();
int Send(FairMQMessagePtr& msg) const;
int Receive(FairMQMessagePtr& msg) const;
/// Sends a message to the socket queue. /// Sends a message to the socket queue.
/// @details Send method attempts to send a message by
/// putting it in the output queue. If the queue is full or queueing is not possible
/// for some other reason (e.g. no peers connected for a binding socket), the method blocks.
///
/// @param msg Constant reference of unique_ptr to a FairMQMessage /// @param msg Constant reference of unique_ptr to a FairMQMessage
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. /// @param sndTimeoutInMs send timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
/// In case of errors, returns -1. /// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. -1 if there was an error.
int Send(FairMQMessagePtr& msg, int sndTimeoutInMs) const; int Send(FairMQMessagePtr& msg, int sndTimeoutInMs = -1)
{
CheckSendCompatibility(msg);
return fSocket->Send(msg, sndTimeoutInMs);
}
/// Receives a message from the socket queue. /// Receives a message from the socket queue.
/// @details Receive method attempts to receive a message from the input queue.
/// If the queue is empty the method blocks.
///
/// @param msg Constant reference of unique_ptr to a FairMQMessage /// @param msg Constant reference of unique_ptr to a FairMQMessage
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out. /// @param rcvTimeoutInMs receive timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
/// In case of errors, returns -1. /// @return Number of bytes that have been received. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
int Receive(FairMQMessagePtr& msg, int rcvTimeoutInMs) const; int Receive(FairMQMessagePtr& msg, int rcvTimeoutInMs = -1)
{
CheckReceiveCompatibility(msg);
return fSocket->Receive(msg, rcvTimeoutInMs);
}
/// Sends a message in non-blocking mode. int SendAsync(FairMQMessagePtr& msg) __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(msg, timeout);")))
/// @details SendAsync method attempts to send a message without blocking by {
/// putting it in the queue. CheckSendCompatibility(msg);
/// return fSocket->Send(msg, 0);
/// @param msg Constant reference of unique_ptr to a FairMQMessage }
/// @return Number of bytes that have been queued. If queueing failed due to int ReceiveAsync(FairMQMessagePtr& msg) __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(msg, timeout);")))
/// full queue or no connected peers (when binding), returns -2. {
/// In case of errors, returns -1. CheckReceiveCompatibility(msg);
int SendAsync(FairMQMessagePtr& msg) const; return fSocket->Receive(msg, 0);
}
/// Receives a message in non-blocking mode.
///
/// @param msg Constant reference of unique_ptr to a FairMQMessage
/// @return Number of bytes that have been received. If queue is empty, returns -2.
/// In case of errors, returns -1.
int ReceiveAsync(FairMQMessagePtr& msg) const;
int64_t Send(std::vector<FairMQMessagePtr>& msgVec) const;
int64_t Receive(std::vector<FairMQMessagePtr>& msgVec) const;
/// Send a vector of messages /// Send a vector of messages
///
/// @param msgVec message vector reference /// @param msgVec message vector reference
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. /// @param sndTimeoutInMs send timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
/// In case of errors, returns -1. /// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. -1 if there was an error.
int64_t Send(std::vector<FairMQMessagePtr>& msgVec, int sndTimeoutInMs) const; int64_t Send(std::vector<FairMQMessagePtr>& msgVec, int sndTimeoutInMs = -1)
{
CheckSendCompatibility(msgVec);
return fSocket->Send(msgVec, sndTimeoutInMs);
}
/// Receive a vector of messages /// Receive a vector of messages
///
/// @param msgVec message vector reference /// @param msgVec message vector reference
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out. /// @param rcvTimeoutInMs receive timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
/// In case of errors, returns -1. /// @return Number of bytes that have been received. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
int64_t Receive(std::vector<FairMQMessagePtr>& msgVec, int rcvTimeoutInMs) const; int64_t Receive(std::vector<FairMQMessagePtr>& msgVec, int rcvTimeoutInMs = -1)
/// Sends a vector of message in non-blocking mode.
/// @details SendAsync method attempts to send a vector of messages without blocking by
/// putting it them the queue.
///
/// @param msgVec message vector reference
/// @return Number of bytes that have been queued. If queueing failed due to
/// full queue or no connected peers (when binding), returns -2. In case of errors, returns -1.
int64_t SendAsync(std::vector<FairMQMessagePtr>& msgVec) const;
/// Receives a vector of messages in non-blocking mode.
///
/// @param msgVec message vector reference
/// @return Number of bytes that have been received. If queue is empty, returns -2.
/// In case of errors, returns -1.
int64_t ReceiveAsync(std::vector<FairMQMessagePtr>& msgVec) const;
int64_t Send(FairMQParts& parts) const
{ {
return Send(parts.fParts); CheckReceiveCompatibility(msgVec);
return fSocket->Receive(msgVec, rcvTimeoutInMs);
} }
int64_t Receive(FairMQParts& parts) const int64_t SendAsync(std::vector<FairMQMessagePtr>& msgVec) __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(msgVec, timeout);")))
{ {
return Receive(parts.fParts); CheckSendCompatibility(msgVec);
return fSocket->Send(msgVec, 0);
}
int64_t ReceiveAsync(std::vector<FairMQMessagePtr>& msgVec) __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(msgVec, timeout);")))
{
CheckReceiveCompatibility(msgVec);
return fSocket->Receive(msgVec, 0);
} }
int64_t Send(FairMQParts& parts, int sndTimeoutInMs) const /// Send FairMQParts
/// @param parts FairMQParts reference
/// @param sndTimeoutInMs send timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. -1 if there was an error.
int64_t Send(FairMQParts& parts, int sndTimeoutInMs = -1)
{ {
return Send(parts.fParts, sndTimeoutInMs); return Send(parts.fParts, sndTimeoutInMs);
} }
int64_t Receive(FairMQParts& parts, int rcvTimeoutInMs) const /// Receive FairMQParts
/// @param parts FairMQParts reference
/// @param rcvTimeoutInMs receive timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
/// @return Number of bytes that have been received. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
int64_t Receive(FairMQParts& parts, int rcvTimeoutInMs = -1)
{ {
return Receive(parts.fParts, rcvTimeoutInMs); return Receive(parts.fParts, rcvTimeoutInMs);
} }
int64_t SendAsync(FairMQParts& parts) const int64_t SendAsync(FairMQParts& parts) __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(parts, timeout);")))
{ {
return SendAsync(parts.fParts); return Send(parts.fParts, 0);
} }
int64_t ReceiveAsync(FairMQParts& parts) const int64_t ReceiveAsync(FairMQParts& parts) __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(parts, timeout);")))
{ {
return ReceiveAsync(parts.fParts); return Receive(parts.fParts, 0);
} }
unsigned long GetBytesTx() const; unsigned long GetBytesTx() const { return fSocket->GetBytesTx(); }
unsigned long GetBytesRx() const; unsigned long GetBytesRx() const { return fSocket->GetBytesRx(); }
unsigned long GetMessagesTx() const; unsigned long GetMessagesTx() const { return fSocket->GetMessagesTx(); }
unsigned long GetMessagesRx() const; unsigned long GetMessagesRx() const { return fSocket->GetMessagesRx(); }
auto Transport() const -> const FairMQTransportFactory* auto Transport() -> FairMQTransportFactory*
{ {
return fTransportFactory.get(); return fTransportFactory.get();
}; };
template<typename... Args> template<typename... Args>
FairMQMessagePtr NewMessage(Args&&... args) const FairMQMessagePtr NewMessage(Args&&... args)
{ {
return Transport()->CreateMessage(std::forward<Args>(args)...); return Transport()->CreateMessage(std::forward<Args>(args)...);
} }
template<typename T> template<typename T>
FairMQMessagePtr NewSimpleMessage(const T& data) const FairMQMessagePtr NewSimpleMessage(const T& data)
{ {
return Transport()->NewSimpleMessage(data); return Transport()->NewSimpleMessage(data);
} }
template<typename T> template<typename T>
FairMQMessagePtr NewStaticMessage(const T& data) const FairMQMessagePtr NewStaticMessage(const T& data)
{ {
return Transport()->NewStaticMessage(data); return Transport()->NewStaticMessage(data);
} }
private: private:
std::shared_ptr<FairMQTransportFactory> fTransportFactory;
fair::mq::Transport fTransportType;
std::unique_ptr<FairMQSocket> fSocket; std::unique_ptr<FairMQSocket> fSocket;
std::string fType; std::string fType;
std::string fMethod; std::string fMethod;
std::string fAddress; std::string fAddress;
fair::mq::Transport fTransportType;
int fSndBufSize; int fSndBufSize;
int fRcvBufSize; int fRcvBufSize;
int fSndKernelSize; int fSndKernelSize;
int fRcvKernelSize; int fRcvKernelSize;
int fLinger;
int fRateLogging; int fRateLogging;
int fPortRangeMin;
int fPortRangeMax;
bool fAutoBind;
std::string fName; std::string fName;
std::atomic<bool> fIsValid; std::atomic<bool> fIsValid;
std::shared_ptr<FairMQTransportFactory> fTransportFactory;
void CheckSendCompatibility(FairMQMessagePtr& msg) const;
void CheckSendCompatibility(std::vector<FairMQMessagePtr>& msgVec) const;
void CheckReceiveCompatibility(FairMQMessagePtr& msg) const;
void CheckReceiveCompatibility(std::vector<FairMQMessagePtr>& msgVec) const;
void InitTransport(std::shared_ptr<FairMQTransportFactory> factory);
// use static mutex to make the class easily copyable // use static mutex to make the class easily copyable
// implication: same mutex is used for all instances of the class // implication: same mutex is used for all instances of the class
// this does not hurt much, because mutex is used only during initialization with very low contention // this does not hurt much, because mutex is used only during initialization with very low contention
@@ -329,8 +374,66 @@ class FairMQChannel
bool fMultipart; bool fMultipart;
bool fModified; bool fModified;
auto SetModified(const bool modified) -> void;
bool fReset; bool fReset;
void CheckSendCompatibility(FairMQMessagePtr& msg)
{
if (fTransportType != msg->GetType()) {
// LOG(debug) << "Channel type does not match message type. Creating wrapper";
FairMQMessagePtr msgWrapper(NewMessage(
msg->GetData(),
msg->GetSize(),
[](void* /*data*/, void* _msg) { delete static_cast<FairMQMessage*>(_msg); },
msg.get()
));
msg.release();
msg = move(msgWrapper);
}
}
void CheckSendCompatibility(std::vector<FairMQMessagePtr>& msgVec)
{
for (auto& msg : msgVec) {
if (fTransportType != msg->GetType()) {
// LOG(debug) << "Channel type does not match message type. Creating wrapper";
FairMQMessagePtr msgWrapper(NewMessage(
msg->GetData(),
msg->GetSize(),
[](void* /*data*/, void* _msg) { delete static_cast<FairMQMessage*>(_msg); },
msg.get()
));
msg.release();
msg = move(msgWrapper);
}
}
}
void CheckReceiveCompatibility(FairMQMessagePtr& msg)
{
if (fTransportType != msg->GetType()) {
// LOG(debug) << "Channel type does not match message type. Creating wrapper";
FairMQMessagePtr newMsg(NewMessage());
msg = move(newMsg);
}
}
void CheckReceiveCompatibility(std::vector<FairMQMessagePtr>& msgVec)
{
for (auto& msg : msgVec) {
if (fTransportType != msg->GetType()) {
// LOG(debug) << "Channel type does not match message type. Creating wrapper";
FairMQMessagePtr newMsg(NewMessage());
msg = move(newMsg);
}
}
}
void InitTransport(std::shared_ptr<FairMQTransportFactory> factory)
{
fTransportFactory = factory;
fTransportType = factory->GetType();
}
auto SetModified(const bool modified) -> void;
}; };
#endif /* FAIRMQCHANNEL_H_ */ #endif /* FAIRMQCHANNEL_H_ */

View File

@@ -16,8 +16,6 @@
#include <list> #include <list>
#include <cstdlib> #include <cstdlib>
#include <stdexcept>
#include <random>
#include <chrono> #include <chrono>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
@@ -56,11 +54,6 @@ FairMQDevice::FairMQDevice(FairMQProgOptions* config, const fair::mq::tools::Ver
, fInternalConfig(config ? nullptr : fair::mq::tools::make_unique<FairMQProgOptions>()) , fInternalConfig(config ? nullptr : fair::mq::tools::make_unique<FairMQProgOptions>())
, fConfig(config ? config : fInternalConfig.get()) , fConfig(config ? config : fInternalConfig.get())
, fId() , fId()
, fInitialValidationFinished(false)
, fInitialValidationCondition()
, fInitialValidationMutex()
, fPortRangeMin(22000)
, fPortRangeMax(32000)
, fDefaultTransportType(fair::mq::Transport::DEFAULT) , fDefaultTransportType(fair::mq::Transport::DEFAULT)
, fDataCallbacks(false) , fDataCallbacks(false)
, fMsgInputs() , fMsgInputs()
@@ -76,6 +69,7 @@ FairMQDevice::FairMQDevice(FairMQProgOptions* config, const fair::mq::tools::Ver
, fInterrupted(false) , fInterrupted(false)
, fInterruptedCV() , fInterruptedCV()
, fInterruptedMtx() , fInterruptedMtx()
, fRateLogging(true)
{ {
} }
@@ -83,27 +77,20 @@ void FairMQDevice::InitWrapper()
{ {
fId = fConfig->GetValue<string>("id"); fId = fConfig->GetValue<string>("id");
fRate = fConfig->GetValue<float>("rate"); fRate = fConfig->GetValue<float>("rate");
fPortRangeMin = fConfig->GetValue<int>("port-range-min");
fPortRangeMax = fConfig->GetValue<int>("port-range-max");
try try {
{
fDefaultTransportType = fair::mq::TransportTypes.at(fConfig->GetValue<string>("transport")); fDefaultTransportType = fair::mq::TransportTypes.at(fConfig->GetValue<string>("transport"));
} } catch (const exception& e) {
catch (const exception& e) LOG(error) << "exception: " << e.what();
{
LOG(error) << "invalid transport type provided: " << fConfig->GetValue<string>("transport"); LOG(error) << "invalid transport type provided: " << fConfig->GetValue<string>("transport");
throw;
} }
for (auto& c : fConfig->GetFairMQMap()) for (auto& c : fConfig->GetFairMQMap()) {
{ if (fChannels.find(c.first) == fChannels.end()) {
if (fChannels.find(c.first) == fChannels.end())
{
LOG(debug) << "Inserting new device channel from config: " << c.first; LOG(debug) << "Inserting new device channel from config: " << c.first;
fChannels.insert(c); fChannels.insert(c);
} } else {
else
{
LOG(debug) << "Updating existing device channel from config: " << c.first; LOG(debug) << "Updating existing device channel from config: " << c.first;
fChannels[c.first] = c.second; fChannels[c.first] = c.second;
} }
@@ -119,51 +106,44 @@ void FairMQDevice::InitWrapper()
string networkInterface = fConfig->GetValue<string>("network-interface"); string networkInterface = fConfig->GetValue<string>("network-interface");
// Fill the uninitialized channel containers // Fill the uninitialized channel containers
for (auto& mi : fChannels) for (auto& mi : fChannels) {
{ int subChannelIndex = 0;
for (auto vi = mi.second.begin(); vi != mi.second.end(); ++vi) for (auto& vi : mi.second) {
{ // set channel name: name + vector index
// if (vi->fModified) vi.fName = fair::mq::tools::ToString(mi.first, "[", subChannelIndex, "]");
// {
// if (vi->fReset)
// {
// vi->fSocket.reset();
// }
// set channel name: name + vector index
vi->fName = fair::mq::tools::ToString(mi.first, "[", vi - (mi.second).begin(), "]");
if (vi->fMethod == "bind") // set channel transport
{ if (vi.fTransportType == fair::mq::Transport::DEFAULT || vi.fTransportType == fTransportFactory->GetType()) {
// if binding address is not specified, try getting it from the configured network interface LOG(debug) << vi.fName << ": using default transport";
if (vi->fAddress == "unspecified" || vi->fAddress == "") vi.InitTransport(fTransportFactory);
{ } else {
// if the configured network interface is default, get its name from the default route LOG(debug) << vi.fName << ": channel transport (" << fair::mq::TransportNames.at(fDefaultTransportType) << ") overriden to " << fair::mq::TransportNames.at(vi.fTransportType);
if (networkInterface == "default") vi.InitTransport(AddTransport(vi.fTransportType));
{ }
networkInterface = fair::mq::tools::getDefaultRouteNetworkInterface();
} if (vi.fMethod == "bind") {
vi->fAddress = "tcp://" + fair::mq::tools::getInterfaceIP(networkInterface) + ":1"; // if binding address is not specified, try getting it from the configured network interface
if (vi.fAddress == "unspecified" || vi.fAddress == "") {
// if the configured network interface is default, get its name from the default route
if (networkInterface == "default") {
networkInterface = fair::mq::tools::getDefaultRouteNetworkInterface();
} }
// fill the uninitialized list vi.fAddress = "tcp://" + fair::mq::tools::getInterfaceIP(networkInterface) + ":1";
uninitializedBindingChannels.push_back(&(*vi));
} }
else if (vi->fMethod == "connect") // fill the uninitialized list
{ uninitializedBindingChannels.push_back(&vi);
// fill the uninitialized list } else if (vi.fMethod == "connect") {
uninitializedConnectingChannels.push_back(&(*vi)); // fill the uninitialized list
} uninitializedConnectingChannels.push_back(&vi);
else if (vi->fAddress.find_first_of("@+>") != string::npos) } else if (vi.fAddress.find_first_of("@+>") != string::npos) {
{ // fill the uninitialized list
// fill the uninitialized list uninitializedConnectingChannels.push_back(&vi);
uninitializedConnectingChannels.push_back(&(*vi)); } else {
} LOG(error) << "Cannot update configuration. Socket method (bind/connect) for channel '" << vi.fName << "' not specified.";
else throw runtime_error(fair::mq::tools::ToString("Cannot update configuration. Socket method (bind/connect) for channel ", vi.fName, " not specified."));
{ }
LOG(error) << "Cannot update configuration. Socket method (bind/connect) not specified.";
ChangeState(ERROR_FOUND); subChannelIndex++;
// throw runtime_error("Cannot update configuration. Socket method (bind/connect) not specified.");
}
// }
} }
} }
@@ -171,22 +151,13 @@ void FairMQDevice::InitWrapper()
// If necessary this could be handled in the same way as the connecting channels // If necessary this could be handled in the same way as the connecting channels
AttachChannels(uninitializedBindingChannels); AttachChannels(uninitializedBindingChannels);
if (uninitializedBindingChannels.size() > 0) if (!uninitializedBindingChannels.empty()) {
{
LOG(error) << uninitializedBindingChannels.size() << " of the binding channels could not initialize. Initial configuration incomplete."; LOG(error) << uninitializedBindingChannels.size() << " of the binding channels could not initialize. Initial configuration incomplete.";
ChangeState(ERROR_FOUND); throw runtime_error(fair::mq::tools::ToString(uninitializedBindingChannels.size(), " of the binding channels could not initialize. Initial configuration incomplete."));
// throw runtime_error(fair::mq::tools::ToString(uninitializedBindingChannels.size(), " of the binding channels could not initialize. Initial configuration incomplete."));
} }
CallStateChangeCallbacks(INITIALIZING_DEVICE); CallStateChangeCallbacks(INITIALIZING_DEVICE);
// notify parent thread about completion of first validation.
{
lock_guard<mutex> lock(fInitialValidationMutex);
fInitialValidationFinished = true;
fInitialValidationCondition.notify_one();
}
int initializationTimeoutInS = fConfig->GetValue<int>("initialization-timeout"); int initializationTimeoutInS = fConfig->GetValue<int>("initialization-timeout");
// go over the list of channels until all are initialized (and removed from the uninitialized list) // go over the list of channels until all are initialized (and removed from the uninitialized list)
@@ -196,28 +167,20 @@ void FairMQDevice::InitWrapper()
// first attempt // first attempt
AttachChannels(uninitializedConnectingChannels); AttachChannels(uninitializedConnectingChannels);
// if not all channels could be connected, update their address values from config and retry // if not all channels could be connected, update their address values from config and retry
while (!uninitializedConnectingChannels.empty()) while (!uninitializedConnectingChannels.empty()) {
{
this_thread::sleep_for(chrono::milliseconds(sleepTimeInMS)); this_thread::sleep_for(chrono::milliseconds(sleepTimeInMS));
if (fConfig) for (auto& chan : uninitializedConnectingChannels) {
{ string key{"chans." + chan->GetChannelPrefix() + "." + chan->GetChannelIndex() + ".address"};
for (auto& chan : uninitializedConnectingChannels) string newAddress = fConfig->GetValue<string>(key);
{ if (newAddress != chan->GetAddress()) {
string key{"chans." + chan->GetChannelPrefix() + "." + chan->GetChannelIndex() + ".address"}; chan->UpdateAddress(newAddress);
string newAddress = fConfig->GetValue<string>(key);
if (newAddress != chan->GetAddress())
{
chan->UpdateAddress(newAddress);
}
} }
} }
if (numAttempts++ > maxAttempts) if (numAttempts++ > maxAttempts) {
{
LOG(error) << "could not connect all channels after " << initializationTimeoutInS << " attempts"; LOG(error) << "could not connect all channels after " << initializationTimeoutInS << " attempts";
ChangeState(ERROR_FOUND); throw runtime_error(fair::mq::tools::ToString("could not connect all channels after ", initializationTimeoutInS, " attempts"));
// throw runtime_error(fair::mq::tools::ToString("could not connect all channels after ", initializationTimeoutInS, " attempts"));
} }
AttachChannels(uninitializedConnectingChannels); AttachChannels(uninitializedConnectingChannels);
@@ -225,13 +188,11 @@ void FairMQDevice::InitWrapper()
Init(); Init();
ChangeState(internal_DEVICE_READY); if (fChannels.empty()) {
} LOG(warn) << "No channels created after finishing initialization";
}
void FairMQDevice::WaitForInitialValidation() ChangeState(internal_DEVICE_READY);
{
unique_lock<mutex> lock(fInitialValidationMutex);
fInitialValidationCondition.wait(lock, [&] () { return fInitialValidationFinished; });
} }
void FairMQDevice::Init() void FairMQDevice::Init()
@@ -242,103 +203,54 @@ void FairMQDevice::AttachChannels(vector<FairMQChannel*>& chans)
{ {
auto itr = chans.begin(); auto itr = chans.begin();
while (itr != chans.end()) while (itr != chans.end()) {
{ if ((*itr)->ValidateChannel()) {
if ((*itr)->ValidateChannel()) (*itr)->Init();
{ if (AttachChannel(**itr)) {
if (AttachChannel(**itr))
{
(*itr)->SetModified(false); (*itr)->SetModified(false);
// remove the channel from the uninitialized container
itr = chans.erase(itr); itr = chans.erase(itr);
} } else {
else
{
LOG(error) << "failed to attach channel " << (*itr)->fName << " (" << (*itr)->fMethod << ")"; LOG(error) << "failed to attach channel " << (*itr)->fName << " (" << (*itr)->fMethod << ")";
++itr; ++itr;
} }
} } else {
else
{
++itr; ++itr;
} }
} }
} }
bool FairMQDevice::AttachChannel(FairMQChannel& ch) bool FairMQDevice::AttachChannel(FairMQChannel& chan)
{ {
if (ch.fTransportType == fair::mq::Transport::DEFAULT || ch.fTransportType == fTransportFactory->GetType())
{
LOG(debug) << ch.fName << ": using default transport";
ch.InitTransport(fTransportFactory);
}
else
{
LOG(debug) << ch.fName << ": channel transport (" << fair::mq::TransportNames.at(fDefaultTransportType) << ") overriden to " << fair::mq::TransportNames.at(ch.fTransportType);
ch.InitTransport(AddTransport(ch.fTransportType));
}
vector<string> endpoints; vector<string> endpoints;
boost::algorithm::split(endpoints, ch.fAddress, boost::algorithm::is_any_of(",")); string chanAddress = chan.GetAddress();
for (auto& endpoint : endpoints) boost::algorithm::split(endpoints, chanAddress, boost::algorithm::is_any_of(","));
{
//(re-)init socket
if (!ch.fSocket)
{
try
{
ch.fSocket = ch.fTransportFactory->CreateSocket(ch.fType, ch.fName);
}
catch (fair::mq::SocketError& se)
{
LOG(error) << se.what();
return false;
}
}
// set high water marks
ch.fSocket->SetOption("snd-hwm", &(ch.fSndBufSize), sizeof(ch.fSndBufSize));
ch.fSocket->SetOption("rcv-hwm", &(ch.fRcvBufSize), sizeof(ch.fRcvBufSize));
// set kernel transmit size
if (ch.fSndKernelSize != 0)
{
ch.fSocket->SetOption("snd-size", &(ch.fSndKernelSize), sizeof(ch.fSndKernelSize));
}
if (ch.fRcvKernelSize != 0)
{
ch.fSocket->SetOption("rcv-size", &(ch.fRcvKernelSize), sizeof(ch.fRcvKernelSize));
}
for (auto& endpoint : endpoints) {
// attach // attach
bool bind = (ch.fMethod == "bind"); bool bind = (chan.GetMethod() == "bind");
bool connectionModifier = false; bool connectionModifier = false;
string address = endpoint; string address = endpoint;
// check if the default fMethod is overridden by a modifier // check if the default fMethod is overridden by a modifier
if (endpoint[0] == '+' || endpoint[0] == '>') if (endpoint[0] == '+' || endpoint[0] == '>') {
{
connectionModifier = true; connectionModifier = true;
bind = false; bind = false;
address = endpoint.substr(1); address = endpoint.substr(1);
} } else if (endpoint[0] == '@') {
else if (endpoint[0] == '@')
{
connectionModifier = true; connectionModifier = true;
bind = true; bind = true;
address = endpoint.substr(1); address = endpoint.substr(1);
} }
if (address.compare(0, 6, "tcp://") == 0) if (address.compare(0, 6, "tcp://") == 0) {
{
string addressString = address.substr(6); string addressString = address.substr(6);
auto pos = addressString.find(":"); auto pos = addressString.find(':');
string hostPart = addressString.substr(0, pos); string hostPart = addressString.substr(0, pos);
if (!(bind && hostPart == "*")) if (!(bind && hostPart == "*")) {
{
string portPart = addressString.substr(pos + 1); string portPart = addressString.substr(pos + 1);
string resolvedHost = fair::mq::tools::getIpFromHostname(hostPart); string resolvedHost = fair::mq::tools::getIpFromHostname(hostPart);
if (resolvedHost == "") if (resolvedHost == "") {
{
return false; return false;
} }
address.assign("tcp://" + resolvedHost + ":" + portPart); address.assign("tcp://" + resolvedHost + ":" + portPart);
@@ -347,79 +259,35 @@ bool FairMQDevice::AttachChannel(FairMQChannel& ch)
bool success = true; bool success = true;
// make the connection // make the connection
if (bind) if (bind) {
{ success = chan.BindEndpoint(address);
success = BindEndpoint(*ch.fSocket, address); } else {
} success = chan.ConnectEndpoint(address);
else
{
success = ConnectEndpoint(*ch.fSocket, address);
} }
// bind might bind to an address different than requested, // bind might bind to an address different than requested,
// put the actual address back in the config // put the actual address back in the config
endpoint.clear(); endpoint.clear();
if (connectionModifier) if (connectionModifier) {
{
endpoint.push_back(bind?'@':'+'); endpoint.push_back(bind?'@':'+');
} }
endpoint += address; endpoint += address;
LOG(debug) << "Attached channel " << ch.fName << " to " << endpoint << (bind ? " (bind) " : " (connect) ");
// after the book keeping is done, exit in case of errors // after the book keeping is done, exit in case of errors
if (!success) if (!success) {
{
return success; return success;
} else {
LOG(debug) << "Attached channel " << chan.GetName() << " to " << endpoint << (bind ? " (bind) " : " (connect) ") << "(" << chan.GetType() << ")";
} }
} }
// put the (possibly) modified address back in the channel object and config // put the (possibly) modified address back in the channel object and config
string newAddress{boost::algorithm::join(endpoints, ",")}; string newAddress(boost::algorithm::join(endpoints, ","));
if (newAddress != ch.fAddress) if (newAddress != chanAddress) {
{ chan.UpdateAddress(newAddress);
ch.UpdateAddress(newAddress);
if (fConfig)
{
string key{"chans." + ch.GetChannelPrefix() + "." + ch.GetChannelIndex() + ".address"};
fConfig->SetValue(key, newAddress);
}
}
return true; // update address in the config, it could have been modified during binding
} fConfig->SetValue({"chans." + chan.GetPrefix() + "." + chan.GetIndex() + ".address"}, newAddress);
bool FairMQDevice::ConnectEndpoint(FairMQSocket& socket, string& endpoint)
{
socket.Connect(endpoint);
return true;
}
bool FairMQDevice::BindEndpoint(FairMQSocket& socket, string& endpoint)
{
// number of attempts when choosing a random port
int maxAttempts = 1000;
int numAttempts = 0;
// initialize random generator
default_random_engine generator(chrono::system_clock::now().time_since_epoch().count());
uniform_int_distribution<int> randomPort(fPortRangeMin, fPortRangeMax);
// try to bind to the saved port. In case of failure, try random one.
while (!socket.Bind(endpoint))
{
LOG(debug) << "Could not bind to configured (TCP) port, trying random port in range " << fPortRangeMin << "-" << fPortRangeMax;
++numAttempts;
if (numAttempts > maxAttempts)
{
LOG(error) << "could not bind to any (TCP) port in the given range after " << maxAttempts << " attempts";
return false;
}
size_t pos = endpoint.rfind(":");
endpoint = endpoint.substr(0, pos + 1) + fair::mq::tools::ToString(static_cast<int>(randomPort(generator)));
} }
return true; return true;
@@ -464,27 +332,6 @@ void FairMQDevice::SortChannel(const string& name, const bool reindex)
} }
} }
void FairMQDevice::PrintChannel(const string& name)
{
if (fChannels.find(name) != fChannels.end())
{
for (auto vi = fChannels[name].begin(); vi != fChannels[name].end(); ++vi)
{
LOG(info) << vi->fName << ": "
<< vi->fType << " | "
<< vi->fMethod << " | "
<< vi->fAddress << " | "
<< vi->fSndBufSize << " | "
<< vi->fRcvBufSize << " | "
<< vi->fRateLogging;
}
}
else
{
LOG(error) << "Printing failed: no channel with the name \"" << name << "\".";
}
}
void FairMQDevice::RunWrapper() void FairMQDevice::RunWrapper()
{ {
CallStateChangeCallbacks(RUNNING); CallStateChangeCallbacks(RUNNING);
@@ -492,6 +339,7 @@ void FairMQDevice::RunWrapper()
LOG(info) << "DEVICE: Running..."; LOG(info) << "DEVICE: Running...";
// start the rate logger thread // start the rate logger thread
fRateLogging = true;
future<void> rateLogger = async(launch::async, &FairMQDevice::LogSocketRates, this); future<void> rateLogger = async(launch::async, &FairMQDevice::LogSocketRates, this);
// notify transports to resume transfers // notify transports to resume transfers
@@ -504,8 +352,7 @@ void FairMQDevice::RunWrapper()
t.second->Resume(); t.second->Resume();
} }
try try {
{
PreRun(); PreRun();
// process either data callbacks or ConditionalRun/Run // process either data callbacks or ConditionalRun/Run
@@ -535,11 +382,14 @@ void FairMQDevice::RunWrapper()
Run(); Run();
} }
} } catch (const out_of_range& oor) {
catch (const out_of_range& oor)
{
LOG(error) << "out of range: " << oor.what(); LOG(error) << "out of range: " << oor.what();
LOG(error) << "incorrect/incomplete channel configuration?"; LOG(error) << "incorrect/incomplete channel configuration?";
fRateLogging = false;
throw;
} catch (...) {
fRateLogging = false;
throw;
} }
// if Run() exited and the state is still RUNNING, transition to READY. // if Run() exited and the state is still RUNNING, transition to READY.
@@ -593,17 +443,17 @@ void FairMQDevice::HandleMultipleChannelInput()
for (const auto& mi : fMsgInputs) for (const auto& mi : fMsgInputs)
{ {
for (unsigned int i = 0; i < fChannels.at(mi.first).size(); ++i) for (auto& i : fChannels.at(mi.first))
{ {
fChannels.at(mi.first).at(i).fMultipart = false; i.fMultipart = false;
} }
} }
for (const auto& mi : fMultipartInputs) for (const auto& mi : fMultipartInputs)
{ {
for (unsigned int i = 0; i < fChannels.at(mi.first).size(); ++i) for (auto& i : fChannels.at(mi.first))
{ {
fChannels.at(mi.first).at(i).fMultipart = true; i.fMultipart = true;
} }
} }
@@ -661,7 +511,7 @@ void FairMQDevice::HandleMultipleTransportInput()
for (const auto& i : fMultitransportInputs) for (const auto& i : fMultitransportInputs)
{ {
threads.push_back(thread(&FairMQDevice::PollForTransport, this, fTransports.at(i.first).get(), i.second)); threads.emplace_back(thread(&FairMQDevice::PollForTransport, this, fTransports.at(i.first).get(), i.second));
} }
for (thread& t : threads) for (thread& t : threads)
@@ -718,11 +568,11 @@ void FairMQDevice::PollForTransport(const FairMQTransportFactory* factory, const
catch (exception& e) catch (exception& e)
{ {
LOG(error) << "FairMQDevice::PollForTransport() failed: " << e.what() << ", going to ERROR state."; LOG(error) << "FairMQDevice::PollForTransport() failed: " << e.what() << ", going to ERROR state.";
ChangeState(ERROR_FOUND); throw runtime_error(fair::mq::tools::ToString("FairMQDevice::PollForTransport() failed: ", e.what(), ", going to ERROR state."));
} }
} }
bool FairMQDevice::HandleMsgInput(const string& chName, const InputMsgCallback& callback, int i) const bool FairMQDevice::HandleMsgInput(const string& chName, const InputMsgCallback& callback, int i)
{ {
unique_ptr<FairMQMessage> input(fChannels.at(chName).at(i).fTransportFactory->CreateMessage()); unique_ptr<FairMQMessage> input(fChannels.at(chName).at(i).fTransportFactory->CreateMessage());
@@ -736,7 +586,7 @@ bool FairMQDevice::HandleMsgInput(const string& chName, const InputMsgCallback&
} }
} }
bool FairMQDevice::HandleMultipartInput(const string& chName, const InputMultipartCallback& callback, int i) const bool FairMQDevice::HandleMultipartInput(const string& chName, const InputMultipartCallback& callback, int i)
{ {
FairMQParts input; FairMQParts input;
@@ -874,7 +724,7 @@ void FairMQDevice::LogSocketRates()
LOG(debug) << "<channel>: in: <#msgs> (<MB>) out: <#msgs> (<MB>)"; LOG(debug) << "<channel>: in: <#msgs> (<MB>) out: <#msgs> (<MB>)";
while (CheckCurrentState(RUNNING)) while (fRateLogging)
{ {
t1 = chrono::high_resolution_clock::now(); t1 = chrono::high_resolution_clock::now();
@@ -914,8 +764,7 @@ void FairMQDevice::LogSocketRates()
} }
t0 = t1; t0 = t1;
this_thread::sleep_for(chrono::milliseconds(1000)); WaitFor(chrono::milliseconds(1000));
// WaitFor(chrono::milliseconds(1000)); TODO: enable this when nanomsg linger is fixed
} }
} }
} }
@@ -929,6 +778,7 @@ void FairMQDevice::Unblock()
{ {
lock_guard<mutex> guard(fInterruptedMtx); lock_guard<mutex> guard(fInterruptedMtx);
fInterrupted = true; fInterrupted = true;
fRateLogging = false;
} }
fInterruptedCV.notify_all(); fInterruptedCV.notify_all();
} }
@@ -950,13 +800,11 @@ void FairMQDevice::ResetWrapper()
{ {
CallStateChangeCallbacks(RESETTING_DEVICE); CallStateChangeCallbacks(RESETTING_DEVICE);
Reset(); for (auto& t : fTransports)
{
t.second->Reset();
}
ChangeState(internal_IDLE);
}
void FairMQDevice::Reset()
{
// iterate over the channels map // iterate over the channels map
for (auto& mi : fChannels) for (auto& mi : fChannels)
{ {
@@ -967,11 +815,14 @@ void FairMQDevice::Reset()
vi.fSocket.reset(); // destroy FairMQSocket vi.fSocket.reset(); // destroy FairMQSocket
} }
} }
Reset();
ChangeState(internal_IDLE);
} }
const FairMQChannel& FairMQDevice::GetChannel(const string& channelName, const int index) const void FairMQDevice::Reset()
{ {
return fChannels.at(channelName).at(index);
} }
void FairMQDevice::Exit() void FairMQDevice::Exit()

View File

@@ -31,6 +31,7 @@
#include <functional> #include <functional>
#include <assert.h> // static_assert #include <assert.h> // static_assert
#include <type_traits> // is_trivially_copyable #include <type_traits> // is_trivially_copyable
#include <stdexcept>
#include <mutex> #include <mutex>
#include <condition_variable> #include <condition_variable>
@@ -80,10 +81,6 @@ class FairMQDevice : public FairMQStateMachine
/// @param reindex Should reindexing be done /// @param reindex Should reindexing be done
void SortChannel(const std::string& name, const bool reindex = true); void SortChannel(const std::string& name, const bool reindex = true);
/// Prints channel configuration
/// @param name Name of the channel
void PrintChannel(const std::string& name);
template<typename Serializer, typename DataType, typename... Args> template<typename Serializer, typename DataType, typename... Args>
void Serialize(FairMQMessage& msg, DataType&& data, Args&&... args) const void Serialize(FairMQMessage& msg, DataType&& data, Args&&... args) const
{ {
@@ -96,154 +93,108 @@ class FairMQDevice : public FairMQStateMachine
Deserializer().Deserialize(msg, std::forward<DataType>(data), std::forward<Args>(args)...); Deserializer().Deserialize(msg, std::forward<DataType>(data), std::forward<Args>(args)...);
} }
int Send(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const
{
return fChannels.at(chan).at(i).Send(msg);
}
int Receive(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const
{
return fChannels.at(chan).at(i).Receive(msg);
}
/// Shorthand method to send `msg` on `chan` at index `i` /// Shorthand method to send `msg` on `chan` at index `i`
/// @param msg message reference /// @param msg message reference
/// @param chan channel name /// @param chan channel name
/// @param i channel index /// @param i channel index
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. /// @param sndTimeoutInMs send timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
/// In case of errors, returns -1. /// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. -1 if there was an error.
int Send(FairMQMessagePtr& msg, const std::string& chan, const int i, int sndTimeoutInMs) const int Send(FairMQMessagePtr& msg, const std::string& channel, const int index = 0, int sndTimeoutInMs = -1)
{ {
return fChannels.at(chan).at(i).Send(msg, sndTimeoutInMs); return GetChannel(channel, index).Send(msg, sndTimeoutInMs);
} }
/// Shorthand method to receive `msg` on `chan` at index `i` /// Shorthand method to receive `msg` on `chan` at index `i`
/// @param msg message reference /// @param msg message reference
/// @param chan channel name /// @param chan channel name
/// @param i channel index /// @param i channel index
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out. /// @param rcvTimeoutInMs receive timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
/// In case of errors, returns -1. /// @return Number of bytes that have been received. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
int Receive(FairMQMessagePtr& msg, const std::string& chan, const int i, int rcvTimeoutInMs) const int Receive(FairMQMessagePtr& msg, const std::string& channel, const int index = 0, int rcvTimeoutInMs = -1)
{ {
return fChannels.at(chan).at(i).Receive(msg, rcvTimeoutInMs); return GetChannel(channel, index).Receive(msg, rcvTimeoutInMs);
} }
/// Shorthand method to send `msg` on `chan` at index `i` without blocking int SendAsync(FairMQMessagePtr& msg, const std::string& channel, const int index = 0) __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(msg, \"channelA\", subchannelIndex, timeout);")))
/// @param msg message reference
/// @param chan channel name
/// @param i channel index
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
/// In case of errors, returns -1.
int SendAsync(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const
{ {
return fChannels.at(chan).at(i).SendAsync(msg); return GetChannel(channel, index).Send(msg, 0);
} }
int ReceiveAsync(FairMQMessagePtr& msg, const std::string& channel, const int index = 0) __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(msg, \"channelA\", subchannelIndex, timeout);")))
/// Shorthand method to receive `msg` on `chan` at index `i` without blocking
/// @param msg message reference
/// @param chan channel name
/// @param i channel index
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
/// In case of errors, returns -1.
int ReceiveAsync(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const
{ {
return fChannels.at(chan).at(i).ReceiveAsync(msg); return GetChannel(channel, index).Receive(msg, 0);
}
int64_t Send(FairMQParts& parts, const std::string& chan, const int i = 0) const
{
return fChannels.at(chan).at(i).Send(parts.fParts);
}
int64_t Receive(FairMQParts& parts, const std::string& chan, const int i = 0) const
{
return fChannels.at(chan).at(i).Receive(parts.fParts);
} }
/// Shorthand method to send FairMQParts on `chan` at index `i` /// Shorthand method to send FairMQParts on `chan` at index `i`
/// @param parts parts reference /// @param parts parts reference
/// @param chan channel name /// @param chan channel name
/// @param i channel index /// @param i channel index
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. /// @param sndTimeoutInMs send timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
/// In case of errors, returns -1. /// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. -1 if there was an error.
int64_t Send(FairMQParts& parts, const std::string& chan, const int i, int sndTimeoutInMs) const int64_t Send(FairMQParts& parts, const std::string& channel, const int index = 0, int sndTimeoutInMs = -1)
{ {
return fChannels.at(chan).at(i).Send(parts.fParts, sndTimeoutInMs); return GetChannel(channel, index).Send(parts.fParts, sndTimeoutInMs);
} }
/// Shorthand method to receive FairMQParts on `chan` at index `i` /// Shorthand method to receive FairMQParts on `chan` at index `i`
/// @param parts parts reference /// @param parts parts reference
/// @param chan channel name /// @param chan channel name
/// @param i channel index /// @param i channel index
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out. /// @param rcvTimeoutInMs receive timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
/// In case of errors, returns -1. /// @return Number of bytes that have been received. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
int64_t Receive(FairMQParts& parts, const std::string& chan, const int i, int rcvTimeoutInMs) const int64_t Receive(FairMQParts& parts, const std::string& channel, const int index = 0, int rcvTimeoutInMs = -1)
{ {
return fChannels.at(chan).at(i).Receive(parts.fParts, rcvTimeoutInMs); return GetChannel(channel, index).Receive(parts.fParts, rcvTimeoutInMs);
} }
/// Shorthand method to send FairMQParts on `chan` at index `i` without blocking int64_t SendAsync(FairMQParts& parts, const std::string& channel, const int index = 0) __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(parts, \"channelA\", subchannelIndex, timeout);")))
/// @param parts parts reference
/// @param chan channel name
/// @param i channel index
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
/// In case of errors, returns -1.
int64_t SendAsync(FairMQParts& parts, const std::string& chan, const int i = 0) const
{ {
return fChannels.at(chan).at(i).SendAsync(parts.fParts); return GetChannel(channel, index).Send(parts.fParts, 0);
} }
int64_t ReceiveAsync(FairMQParts& parts, const std::string& channel, const int index = 0) __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(parts, \"channelA\", subchannelIndex, timeout);")))
/// Shorthand method to receive FairMQParts on `chan` at index `i` without blocking
/// @param parts parts reference
/// @param chan channel name
/// @param i channel index
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
/// In case of errors, returns -1.
int64_t ReceiveAsync(FairMQParts& parts, const std::string& chan, const int i = 0) const
{ {
return fChannels.at(chan).at(i).ReceiveAsync(parts.fParts); return GetChannel(channel, index).Receive(parts.fParts, 0);
} }
/// @brief Getter for default transport factory /// @brief Getter for default transport factory
auto Transport() const -> const FairMQTransportFactory* auto Transport() const -> FairMQTransportFactory*
{ {
return fTransportFactory.get(); return fTransportFactory.get();
} }
template<typename... Args> template<typename... Args>
FairMQMessagePtr NewMessage(Args&&... args) const FairMQMessagePtr NewMessage(Args&&... args)
{ {
return Transport()->CreateMessage(std::forward<Args>(args)...); return Transport()->CreateMessage(std::forward<Args>(args)...);
} }
template<typename... Args> template<typename... Args>
FairMQMessagePtr NewMessageFor(const std::string& channel, int index, Args&&... args) const FairMQMessagePtr NewMessageFor(const std::string& channel, int index, Args&&... args)
{ {
return fChannels.at(channel).at(index).NewMessage(std::forward<Args>(args)...); return GetChannel(channel, index).NewMessage(std::forward<Args>(args)...);
} }
template<typename T> template<typename T>
FairMQMessagePtr NewStaticMessage(const T& data) const FairMQMessagePtr NewStaticMessage(const T& data)
{ {
return Transport()->NewStaticMessage(data); return Transport()->NewStaticMessage(data);
} }
template<typename T> template<typename T>
FairMQMessagePtr NewStaticMessageFor(const std::string& channel, int index, const T& data) const FairMQMessagePtr NewStaticMessageFor(const std::string& channel, int index, const T& data)
{ {
return fChannels.at(channel).at(index).NewStaticMessage(data); return GetChannel(channel, index).NewStaticMessage(data);
} }
template<typename T> template<typename T>
FairMQMessagePtr NewSimpleMessage(const T& data) const FairMQMessagePtr NewSimpleMessage(const T& data)
{ {
return Transport()->NewSimpleMessage(data); return Transport()->NewSimpleMessage(data);
} }
template<typename T> template<typename T>
FairMQMessagePtr NewSimpleMessageFor(const std::string& channel, int index, const T& data) const FairMQMessagePtr NewSimpleMessageFor(const std::string& channel, int index, const T& data)
{ {
return fChannels.at(channel).at(index).NewSimpleMessage(data); return GetChannel(channel, index).NewSimpleMessage(data);
} }
FairMQUnmanagedRegionPtr NewUnmanagedRegion(const size_t size) FairMQUnmanagedRegionPtr NewUnmanagedRegion(const size_t size)
@@ -253,7 +204,7 @@ class FairMQDevice : public FairMQStateMachine
FairMQUnmanagedRegionPtr NewUnmanagedRegionFor(const std::string& channel, int index, const size_t size, FairMQRegionCallback callback = nullptr) FairMQUnmanagedRegionPtr NewUnmanagedRegionFor(const std::string& channel, int index, const size_t size, FairMQRegionCallback callback = nullptr)
{ {
return fChannels.at(channel).at(index).Transport()->CreateUnmanagedRegion(size, callback); return GetChannel(channel, index).Transport()->CreateUnmanagedRegion(size, callback);
} }
template<typename ...Ts> template<typename ...Ts>
@@ -264,22 +215,22 @@ class FairMQDevice : public FairMQStateMachine
// if more than one channel provided, check compatibility // if more than one channel provided, check compatibility
if (chans.size() > 1) if (chans.size() > 1)
{ {
fair::mq::Transport type = fChannels.at(chans.at(0)).at(0).Transport()->GetType(); fair::mq::Transport type = GetChannel(chans.at(0), 0).Transport()->GetType();
for (unsigned int i = 1; i < chans.size(); ++i) for (unsigned int i = 1; i < chans.size(); ++i)
{ {
if (type != fChannels.at(chans.at(i)).at(0).Transport()->GetType()) if (type != GetChannel(chans.at(i), 0).Transport()->GetType())
{ {
LOG(error) << "poller failed: different transports within same poller are not yet supported. Going to ERROR state."; LOG(error) << "poller failed: different transports within same poller are not yet supported. Going to ERROR state.";
ChangeState(ERROR_FOUND); throw std::runtime_error("poller failed: different transports within same poller are not yet supported.");
} }
} }
} }
return fChannels.at(chans.at(0)).at(0).Transport()->CreatePoller(fChannels, chans); return GetChannel(chans.at(0), 0).Transport()->CreatePoller(fChannels, chans);
} }
FairMQPollerPtr NewPoller(const std::vector<const FairMQChannel*>& channels) FairMQPollerPtr NewPoller(const std::vector<FairMQChannel*>& channels)
{ {
// if more than one channel provided, check compatibility // if more than one channel provided, check compatibility
if (channels.size() > 1) if (channels.size() > 1)
@@ -291,7 +242,7 @@ class FairMQDevice : public FairMQStateMachine
if (type != channels.at(i)->Transport()->GetType()) if (type != channels.at(i)->Transport()->GetType())
{ {
LOG(error) << "poller failed: different transports within same poller are not yet supported. Going to ERROR state."; LOG(error) << "poller failed: different transports within same poller are not yet supported. Going to ERROR state.";
ChangeState(ERROR_FOUND); throw std::runtime_error("poller failed: different transports within same poller are not yet supported.");
} }
} }
} }
@@ -300,7 +251,7 @@ class FairMQDevice : public FairMQStateMachine
} }
/// Waits for the first initialization run to finish /// Waits for the first initialization run to finish
void WaitForInitialValidation(); void WaitForInitialValidation() __attribute__((deprecated("This method will have no effect in future versions and will be removed. Instead subscribe for state changes and inspect configuration values."))) {}
/// Adds a transport to the device if it doesn't exist /// Adds a transport to the device if it doesn't exist
/// @param transport Transport string ("zeromq"/"nanomsg"/"shmem") /// @param transport Transport string ("zeromq"/"nanomsg"/"shmem")
@@ -319,6 +270,7 @@ class FairMQDevice : public FairMQStateMachine
/// @param rhs Left hand side value for comparison /// @param rhs Left hand side value for comparison
static bool SortSocketsByAddress(const FairMQChannel &lhs, const FairMQChannel &rhs); static bool SortSocketsByAddress(const FairMQChannel &lhs, const FairMQChannel &rhs);
// overload to easily bind member functions
template<typename T> template<typename T>
void OnData(const std::string& channelName, bool (T::* memberFunction)(FairMQMessagePtr& msg, int index)) void OnData(const std::string& channelName, bool (T::* memberFunction)(FairMQMessagePtr& msg, int index))
{ {
@@ -345,6 +297,7 @@ class FairMQDevice : public FairMQStateMachine
} }
} }
// overload to easily bind member functions
template<typename T> template<typename T>
void OnData(const std::string& channelName, bool (T::* memberFunction)(FairMQParts& parts, int index)) void OnData(const std::string& channelName, bool (T::* memberFunction)(FairMQParts& parts, int index))
{ {
@@ -371,7 +324,15 @@ class FairMQDevice : public FairMQStateMachine
} }
} }
const FairMQChannel& GetChannel(const std::string& channelName, const int index = 0) const; FairMQChannel& GetChannel(const std::string& channelName, const int index = 0)
try {
return fChannels.at(channelName).at(index);
} catch (const std::out_of_range& oor) {
LOG(error) << "out of range: " << oor.what();
LOG(error) << "requested channel has not been configured? check channel names/configuration.";
fRateLogging = false;
throw;
}
virtual void RegisterChannelEndpoints() {} virtual void RegisterChannelEndpoints() {}
@@ -408,12 +369,6 @@ class FairMQDevice : public FairMQStateMachine
void SetNumIoThreads(int numIoThreads) { fConfig->SetValue<int>("io-threads", numIoThreads);} void SetNumIoThreads(int numIoThreads) { fConfig->SetValue<int>("io-threads", numIoThreads);}
int GetNumIoThreads() const { return fConfig->GetValue<int>("io-threads"); } int GetNumIoThreads() const { return fConfig->GetValue<int>("io-threads"); }
void SetPortRangeMin(int portRangeMin) { fConfig->SetValue<int>("port-range-min", portRangeMin); }
int GetPortRangeMin() const { return fConfig->GetValue<int>("port-range-min"); }
void SetPortRangeMax(int portRangeMax) { fConfig->SetValue<int>("port-range-max", portRangeMax); }
int GetPortRangeMax() const { return fConfig->GetValue<int>("port-range-max"); }
void SetNetworkInterface(const std::string& networkInterface) { fConfig->SetValue<std::string>("network-interface", networkInterface); } void SetNetworkInterface(const std::string& networkInterface) { fConfig->SetValue<std::string>("network-interface", networkInterface); }
std::string GetNetworkInterface() const { return fConfig->GetValue<std::string>("network-interface"); } std::string GetNetworkInterface() const { return fConfig->GetValue<std::string>("network-interface"); }
@@ -432,7 +387,11 @@ class FairMQDevice : public FairMQStateMachine
void SetRawCmdLineArgs(const std::vector<std::string>& args) { fRawCmdLineArgs = args; } void SetRawCmdLineArgs(const std::vector<std::string>& args) { fRawCmdLineArgs = args; }
std::vector<std::string> GetRawCmdLineArgs() const { return fRawCmdLineArgs; } std::vector<std::string> GetRawCmdLineArgs() const { return fRawCmdLineArgs; }
void RunStateMachine() { ProcessWork(); }; void RunStateMachine()
{
CallStateChangeCallbacks(FairMQStateMachine::IDLE);
ProcessWork();
};
/// Wait for the supplied amount of time or for interruption. /// Wait for the supplied amount of time or for interruption.
/// If interrupted, returns false, otherwise true. /// If interrupted, returns false, otherwise true.
@@ -489,14 +448,6 @@ class FairMQDevice : public FairMQStateMachine
virtual void Reset(); virtual void Reset();
private: private:
// condition variable to notify parent thread about end of initial validation.
bool fInitialValidationFinished;
std::condition_variable fInitialValidationCondition;
std::mutex fInitialValidationMutex;
int fPortRangeMin; ///< Minimum value for the port range (if dynamic)
int fPortRangeMax; ///< Maximum value for the port range (if dynamic)
fair::mq::Transport fDefaultTransportType; ///< Default transport for the device fair::mq::Transport fDefaultTransportType; ///< Default transport for the device
/// Handles the initialization and the Init() method /// Handles the initialization and the Init() method
@@ -520,15 +471,6 @@ class FairMQDevice : public FairMQStateMachine
/// Attach (bind/connect) channels in the list /// Attach (bind/connect) channels in the list
void AttachChannels(std::vector<FairMQChannel*>& chans); void AttachChannels(std::vector<FairMQChannel*>& chans);
/// Sets up and connects/binds a socket to an endpoint
/// return a string with the actual endpoint if it happens
/// to stray from default.
bool ConnectEndpoint(FairMQSocket& socket, std::string& endpoint);
bool BindEndpoint(FairMQSocket& socket, std::string& endpoint);
/// Attaches the channel to all listed endpoints
/// the list is comma separated; the default method (bind/connect) is used.
/// to override default: prepend "@" to bind, "+" or ">" to connect endpoint.
bool AttachChannel(FairMQChannel& ch); bool AttachChannel(FairMQChannel& ch);
void HandleSingleChannelInput(); void HandleSingleChannelInput();
@@ -536,8 +478,8 @@ class FairMQDevice : public FairMQStateMachine
void HandleMultipleTransportInput(); void HandleMultipleTransportInput();
void PollForTransport(const FairMQTransportFactory* factory, const std::vector<std::string>& channelKeys); void PollForTransport(const FairMQTransportFactory* factory, const std::vector<std::string>& channelKeys);
bool HandleMsgInput(const std::string& chName, const InputMsgCallback& callback, int i) const; bool HandleMsgInput(const std::string& chName, const InputMsgCallback& callback, int i);
bool HandleMultipartInput(const std::string& chName, const InputMultipartCallback& callback, int i) const; bool HandleMultipartInput(const std::string& chName, const InputMultipartCallback& callback, int i);
void CreateOwnConfig(); void CreateOwnConfig();
@@ -557,6 +499,7 @@ class FairMQDevice : public FairMQStateMachine
std::atomic<bool> fInterrupted; std::atomic<bool> fInterrupted;
std::condition_variable fInterruptedCV; std::condition_variable fInterruptedCV;
std::mutex fInterruptedMtx; std::mutex fInterruptedMtx;
mutable std::atomic<bool> fRateLogging;
}; };
#endif /* FAIRMQDEVICE_H_ */ #endif /* FAIRMQDEVICE_H_ */

View File

@@ -15,10 +15,13 @@
#include <fairmq/Transports.h> #include <fairmq/Transports.h>
using fairmq_free_fn = void(void* data, void* hint); using fairmq_free_fn = void(void* data, void* hint);
class FairMQTransportFactory;
class FairMQMessage class FairMQMessage
{ {
public: public:
FairMQMessage() = default;
FairMQMessage(FairMQTransportFactory* factory):fTransport{factory} {}
virtual void Rebuild() = 0; virtual void Rebuild() = 0;
virtual void Rebuild(const size_t size) = 0; virtual void Rebuild(const size_t size) = 0;
virtual void Rebuild(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) = 0; virtual void Rebuild(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) = 0;
@@ -29,11 +32,15 @@ class FairMQMessage
virtual bool SetUsedSize(const size_t size) = 0; virtual bool SetUsedSize(const size_t size) = 0;
virtual fair::mq::Transport GetType() const = 0; virtual fair::mq::Transport GetType() const = 0;
FairMQTransportFactory* GetTransport() { return fTransport; }
//void SetTransport(FairMQTransportFactory* transport) { fTransport = transport; }
virtual void Copy(const std::unique_ptr<FairMQMessage>& msg) __attribute__((deprecated("Use 'Copy(const FairMQMessage& msg)'"))) = 0;
virtual void Copy(const FairMQMessage& msg) = 0; virtual void Copy(const FairMQMessage& msg) = 0;
virtual ~FairMQMessage() {}; virtual ~FairMQMessage() {};
private:
FairMQTransportFactory* fTransport{nullptr};
}; };
using FairMQMessagePtr = std::unique_ptr<FairMQMessage>; using FairMQMessagePtr = std::unique_ptr<FairMQMessage>;

View File

@@ -14,46 +14,52 @@
#include <memory> #include <memory>
#include "FairMQMessage.h" #include "FairMQMessage.h"
class FairMQTransportFactory;
class FairMQSocket class FairMQSocket
{ {
public: public:
FairMQSocket() {} FairMQSocket() {}
FairMQSocket(FairMQTransportFactory* fac): fTransport(fac) {}
virtual std::string GetId() = 0; virtual std::string GetId() = 0;
virtual bool Bind(const std::string& address) = 0; virtual bool Bind(const std::string& address) = 0;
virtual void Connect(const std::string& address) = 0; virtual bool Connect(const std::string& address) = 0;
virtual int Send(FairMQMessagePtr& msg, int timeout = 0) = 0; virtual int Send(FairMQMessagePtr& msg, int timeout = -1) = 0;
virtual int Receive(FairMQMessagePtr& msg, int timeout = 0) = 0; virtual int Receive(FairMQMessagePtr& msg, int timeout = -1) = 0;
virtual int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int timeout = 0) = 0; virtual int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int timeout = -1) = 0;
virtual int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int timeout = 0) = 0; virtual int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int timeout = -1) = 0;
virtual int TrySend(FairMQMessagePtr& msg) = 0;
virtual int TryReceive(FairMQMessagePtr& msg) = 0;
virtual int64_t TrySend(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) = 0;
virtual int64_t TryReceive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) = 0;
virtual void* GetSocket() const = 0;
virtual int GetSocket(int nothing) const = 0;
virtual void Close() = 0; virtual void Close() = 0;
virtual void SetOption(const std::string& option, const void* value, size_t valueSize) = 0; virtual void SetOption(const std::string& option, const void* value, size_t valueSize) = 0;
virtual void GetOption(const std::string& option, void* value, size_t* valueSize) = 0; virtual void GetOption(const std::string& option, void* value, size_t* valueSize) = 0;
virtual void SetLinger(const int value) = 0;
virtual int GetLinger() const = 0;
virtual void SetSndBufSize(const int value) = 0;
virtual int GetSndBufSize() const = 0;
virtual void SetRcvBufSize(const int value) = 0;
virtual int GetRcvBufSize() const = 0;
virtual void SetSndKernelSize(const int value) = 0;
virtual int GetSndKernelSize() const = 0;
virtual void SetRcvKernelSize(const int value) = 0;
virtual int GetRcvKernelSize() const = 0;
virtual unsigned long GetBytesTx() const = 0; virtual unsigned long GetBytesTx() const = 0;
virtual unsigned long GetBytesRx() const = 0; virtual unsigned long GetBytesRx() const = 0;
virtual unsigned long GetMessagesTx() const = 0; virtual unsigned long GetMessagesTx() const = 0;
virtual unsigned long GetMessagesRx() const = 0; virtual unsigned long GetMessagesRx() const = 0;
virtual bool SetSendTimeout(const int timeout, const std::string& address, const std::string& method) = 0; FairMQTransportFactory* GetTransport() { return fTransport; }
virtual int GetSendTimeout() const = 0; void SetTransport(FairMQTransportFactory* transport) { fTransport=transport; }
virtual bool SetReceiveTimeout(const int timeout, const std::string& address, const std::string& method) = 0;
virtual int GetReceiveTimeout() const = 0;
virtual ~FairMQSocket() {}; virtual ~FairMQSocket() {};
private:
FairMQTransportFactory* fTransport{nullptr};
}; };
using FairMQSocketPtr = std::unique_ptr<FairMQSocket>; using FairMQSocketPtr = std::unique_ptr<FairMQSocket>;

View File

@@ -175,12 +175,13 @@ struct Machine_ : public state_machine_def<Machine_>
using initial_state = boost::mpl::vector<IDLE_FSM_STATE, OK_FSM_STATE>; using initial_state = boost::mpl::vector<IDLE_FSM_STATE, OK_FSM_STATE>;
template<typename Event, typename FSM> template<typename Event, typename FSM>
void on_entry(Event const&, FSM& fsm) void on_entry(Event const&, FSM& /*fsm*/)
{ {
LOG(state) << "Starting FairMQ state machine"; LOG(state) << "Starting FairMQ state machine";
fState = FairMQStateMachine::IDLE; fState = FairMQStateMachine::IDLE;
LOG(state) << "Entering IDLE state"; LOG(state) << "Entering IDLE state";
fsm.CallStateChangeCallbacks(FairMQStateMachine::IDLE); // fsm.CallStateChangeCallbacks(FairMQStateMachine::IDLE);
// we call this for now in FairMQDevice::RunStateMachine()
} }
template<typename Event, typename FSM> template<typename Event, typename FSM>

View File

@@ -9,11 +9,12 @@
#ifndef FAIRMQTRANSPORTFACTORY_H_ #ifndef FAIRMQTRANSPORTFACTORY_H_
#define FAIRMQTRANSPORTFACTORY_H_ #define FAIRMQTRANSPORTFACTORY_H_
#include <FairMQMessage.h>
#include <FairMQSocket.h>
#include <FairMQPoller.h>
#include <FairMQUnmanagedRegion.h>
#include <FairMQLogger.h> #include <FairMQLogger.h>
#include <FairMQMessage.h>
#include <FairMQPoller.h>
#include <FairMQSocket.h>
#include <FairMQUnmanagedRegion.h>
#include <fairmq/MemoryResources.h>
#include <fairmq/Transports.h> #include <fairmq/Transports.h>
#include <string> #include <string>
@@ -30,6 +31,9 @@ class FairMQTransportFactory
/// Topology wide unique id /// Topology wide unique id
const std::string fkId; const std::string fkId;
/// The polymorphic memory resource associated with the transport
fair::mq::ChannelResource fMemoryResource{this};
public: public:
/// ctor /// ctor
/// @param id Topology wide unique id, usually the device id. /// @param id Topology wide unique id, usually the device id.
@@ -37,34 +41,36 @@ class FairMQTransportFactory
auto GetId() const -> const std::string { return fkId; }; auto GetId() const -> const std::string { return fkId; };
/// Get a pointer to the associated polymorphic memory resource
fair::mq::ChannelResource* GetMemoryResource() { return &fMemoryResource; }
operator fair::mq::ChannelResource*() { return &fMemoryResource; }
/// @brief Create empty FairMQMessage /// @brief Create empty FairMQMessage
/// @return pointer to FairMQMessage /// @return pointer to FairMQMessage
virtual FairMQMessagePtr CreateMessage() const = 0; virtual FairMQMessagePtr CreateMessage() = 0;
/// @brief Create new FairMQMessage of specified size /// @brief Create new FairMQMessage of specified size
/// @param size message size /// @param size message size
/// @return pointer to FairMQMessage /// @return pointer to FairMQMessage
virtual FairMQMessagePtr CreateMessage(const size_t size) const = 0; virtual FairMQMessagePtr CreateMessage(const size_t size) = 0;
/// @brief Create new FairMQMessage with user provided buffer and size /// @brief Create new FairMQMessage with user provided buffer and size
/// @param data pointer to user provided buffer /// @param data pointer to user provided buffer
/// @param size size of the user provided buffer /// @param size size of the user provided buffer
/// @param ffn callback, called when the message is transfered (and can be deleted) /// @param ffn callback, called when the message is transfered (and can be deleted)
/// @param obj optional helper pointer that can be used in the callback /// @param obj optional helper pointer that can be used in the callback
/// @return pointer to FairMQMessage /// @return pointer to FairMQMessage
virtual FairMQMessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) const = 0; virtual FairMQMessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) = 0;
virtual FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& unmanagedRegion, void* data, const size_t size, void* hint = 0) const = 0; virtual FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& unmanagedRegion, void* data, const size_t size, void* hint = 0) = 0;
/// Create a socket /// Create a socket
virtual FairMQSocketPtr CreateSocket(const std::string& type, const std::string& name) const = 0; virtual FairMQSocketPtr CreateSocket(const std::string& type, const std::string& name) = 0;
/// Create a poller for a single channel (all subchannels) /// Create a poller for a single channel (all subchannels)
virtual FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel>& channels) const = 0; virtual FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel>& channels) const = 0;
/// Create a poller for specific channels /// Create a poller for specific channels
virtual FairMQPollerPtr CreatePoller(const std::vector<const FairMQChannel*>& channels) const = 0; virtual FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel*>& channels) const = 0;
/// Create a poller for specific channels (all subchannels) /// Create a poller for specific channels (all subchannels)
virtual FairMQPollerPtr CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const = 0; virtual FairMQPollerPtr CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const = 0;
/// Create a poller for two sockets
virtual FairMQPollerPtr CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const = 0;
virtual FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback = nullptr) const = 0; virtual FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback = nullptr) const = 0;
@@ -73,6 +79,7 @@ class FairMQTransportFactory
virtual void Interrupt() = 0; virtual void Interrupt() = 0;
virtual void Resume() = 0; virtual void Resume() = 0;
virtual void Reset() = 0;
virtual ~FairMQTransportFactory() {}; virtual ~FairMQTransportFactory() {};
@@ -89,7 +96,7 @@ class FairMQTransportFactory
} }
template<typename T> template<typename T>
FairMQMessagePtr NewSimpleMessage(const T& data) const FairMQMessagePtr NewSimpleMessage(const T& data)
{ {
// todo: is_trivially_copyable not available on gcc < 5, workaround? // todo: is_trivially_copyable not available on gcc < 5, workaround?
// static_assert(std::is_trivially_copyable<T>::value, "The argument type for NewSimpleMessage has to be trivially copyable!"); // static_assert(std::is_trivially_copyable<T>::value, "The argument type for NewSimpleMessage has to be trivially copyable!");
@@ -98,13 +105,13 @@ class FairMQTransportFactory
} }
template<std::size_t N> template<std::size_t N>
FairMQMessagePtr NewSimpleMessage(const char(&data)[N]) const FairMQMessagePtr NewSimpleMessage(const char(&data)[N])
{ {
std::string* msgStr = new std::string(data); std::string* msgStr = new std::string(data);
return CreateMessage(const_cast<char*>(msgStr->c_str()), msgStr->length(), FairMQSimpleMsgCleanup<std::string>, msgStr); return CreateMessage(const_cast<char*>(msgStr->c_str()), msgStr->length(), FairMQSimpleMsgCleanup<std::string>, msgStr);
} }
FairMQMessagePtr NewSimpleMessage(const std::string& str) const FairMQMessagePtr NewSimpleMessage(const std::string& str)
{ {
std::string* msgStr = new std::string(str); std::string* msgStr = new std::string(str);
@@ -112,12 +119,12 @@ class FairMQTransportFactory
} }
template<typename T> template<typename T>
FairMQMessagePtr NewStaticMessage(const T& data) const FairMQMessagePtr NewStaticMessage(const T& data)
{ {
return CreateMessage(data, sizeof(T), FairMQNoCleanup, nullptr); return CreateMessage(data, sizeof(T), FairMQNoCleanup, nullptr);
} }
FairMQMessagePtr NewStaticMessage(const std::string& str) const FairMQMessagePtr NewStaticMessage(const std::string& str)
{ {
return CreateMessage(const_cast<char*>(str.c_str()), str.length(), FairMQNoCleanup, nullptr); return CreateMessage(const_cast<char*>(str.c_str()), str.length(), FairMQNoCleanup, nullptr);
} }

View File

@@ -0,0 +1,66 @@
/********************************************************************************
* Copyright (C) 2018 CERN and copyright holders of ALICE O2 *
* Copyright (C) 2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/// @brief Tools for interfacing containers to the transport via polymorphic
/// allocators
///
/// @author Mikolaj Krzewicki, mkrzewic@cern.ch
#include <fairmq/FairMQTransportFactory.h>
#include <fairmq/MemoryResources.h>
namespace fair {
namespace mq {
using BytePmrAllocator = pmr::polymorphic_allocator<fair::mq::byte>;
//_________________________________________________________________________________________________
// return the message associated with the container or throw if it is not possible
template<typename ContainerT>
// typename std::enable_if<
// std::is_base_of<
// pmr::polymorphic_allocator<typename
// ContainerT::value_type>,
// typename ContainerT::allocator_type>::value == true,
// FairMQMessagePtr>::type
FairMQMessagePtr getMessage(ContainerT &&container_, FairMQMemoryResource *targetResource = nullptr)
{
auto container = std::move(container_);
auto alloc = container.get_allocator();
auto resource = dynamic_cast<FairMQMemoryResource *>(alloc.resource());
if (!resource && !targetResource) {
throw std::runtime_error("Neither the container or target resource specified");
}
size_t containerSizeBytes = container.size() * sizeof(typename ContainerT::value_type);
if ((!targetResource && resource)
|| (resource && targetResource && resource->is_equal(*targetResource))) {
auto message = resource->getMessage(static_cast<void *>(
const_cast<typename std::remove_const<typename ContainerT::value_type>::type *>(
container.data())));
if (message)
{
message->SetUsedSize(containerSizeBytes);
return message;
} else {
//container is not required to allocate (like in std::string small string optimization)
//in case we get no message we fall back to default (copy) behaviour)
targetResource = resource;
}
}
auto message = targetResource->getTransportFactory()->CreateMessage(containerSizeBytes);
std::memcpy(static_cast<fair::mq::byte *>(message->GetData()),
container.data(),
containerSizeBytes);
return message;
};
} /* namespace mq */
} /* namespace fair */

View File

@@ -0,0 +1,22 @@
/********************************************************************************
* Copyright (C) 2018 CERN and copyright holders of ALICE O2 *
* Copyright (C) 2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/// @brief Memory allocators and interfaces related to managing memory via the
/// trasport layer
///
/// @author Mikolaj Krzewicki, mkrzewic@cern.ch
#include <fairmq/FairMQTransportFactory.h>
#include <fairmq/MemoryResources.h>
void *fair::mq::ChannelResource::do_allocate(std::size_t bytes, std::size_t /*alignment*/)
{
return setMessage(factory->CreateMessage(bytes));
};

116
fairmq/MemoryResources.h Normal file
View File

@@ -0,0 +1,116 @@
/********************************************************************************
* Copyright (C) 2018 CERN and copyright holders of ALICE O2 *
* Copyright (C) 2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/// @brief Memory allocators and interfaces related to managing memory via the
/// trasport layer
///
/// @author Mikolaj Krzewicki, mkrzewic@cern.ch
#ifndef FAIR_MQ_MEMORY_RESOURCES_H
#define FAIR_MQ_MEMORY_RESOURCES_H
#include <fairmq/FairMQMessage.h>
class FairMQTransportFactory;
#include <boost/container/flat_map.hpp>
#include <boost/container/pmr/memory_resource.hpp>
#include <boost/container/pmr/monotonic_buffer_resource.hpp>
#include <boost/container/pmr/polymorphic_allocator.hpp>
#include <cstring>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
namespace fair {
namespace mq {
using byte = unsigned char;
namespace pmr = boost::container::pmr;
/// All FairMQ related memory resources need to inherit from this interface
/// class for the
/// getMessage() api.
class FairMQMemoryResource : public pmr::memory_resource
{
public:
/// return the message containing data associated with the pointer (to start
/// of
/// buffer), e.g. pointer returned by std::vector::data() return nullptr if
/// returning
/// a message does not make sense!
virtual FairMQMessagePtr getMessage(void *p) = 0;
virtual void *setMessage(FairMQMessagePtr) = 0;
virtual FairMQTransportFactory *getTransportFactory() noexcept = 0;
virtual size_t getNumberOfMessages() const noexcept = 0;
};
/// This is the allocator that interfaces to FairMQ memory management. All
/// allocations are
/// delegated to FairMQ so standard (e.g. STL) containers can construct their
/// stuff in
/// memory regions appropriate for the data channel configuration.
class ChannelResource : public FairMQMemoryResource
{
protected:
FairMQTransportFactory *factory{nullptr};
// TODO: for now a map to keep track of allocations, something else would
// probably be
// faster, but for now this does not need to be fast.
boost::container::flat_map<void *, FairMQMessagePtr> messageMap;
public:
ChannelResource() = delete;
ChannelResource(FairMQTransportFactory *_factory)
: FairMQMemoryResource()
, factory(_factory)
, messageMap()
{
if (!_factory) {
throw std::runtime_error("Tried to construct from a nullptr FairMQTransportFactory");
}
};
FairMQMessagePtr getMessage(void *p) override
{
auto mes = std::move(messageMap[p]);
messageMap.erase(p);
return mes;
}
void *setMessage(FairMQMessagePtr message) override
{
void *addr = message->GetData();
messageMap[addr] = std::move(message);
return addr;
}
FairMQTransportFactory *getTransportFactory() noexcept override { return factory; }
size_t getNumberOfMessages() const noexcept override { return messageMap.size(); }
protected:
void *do_allocate(std::size_t bytes, std::size_t alignment) override;
void do_deallocate(void *p, std::size_t /*bytes*/, std::size_t /*alignment*/) override
{
messageMap.erase(p);
};
bool do_is_equal(const pmr::memory_resource &other) const noexcept override
{
return this == &other;
};
};
} /* namespace mq */
} /* namespace fair */
#endif /* FAIR_MQ_MEMORY_RESOURCES_H */

View File

@@ -186,13 +186,16 @@ class PluginServices
auto SetProperty(const std::string& key, T val) -> void auto SetProperty(const std::string& key, T val) -> void
{ {
auto currentState = GetCurrentDeviceState(); auto currentState = GetCurrentDeviceState();
if (currentState == DeviceState::InitializingDevice) if ( (currentState == DeviceState::InitializingDevice)
|| ((currentState == DeviceState::Idle) && (key == "channel-config")))
{ {
fConfig.SetValue(key, val); fConfig.SetValue(key, val);
} }
else else
{ {
throw InvalidStateError{tools::ToString("PluginServices::SetProperty is not supported in device state ", currentState, ". Supported state is ", DeviceState::InitializingDevice, ".")}; throw InvalidStateError{
tools::ToString("PluginServices::SetProperty is not supported in device state ", currentState, ". ",
"Supported state is ", DeviceState::InitializingDevice, ".")};
} }
} }
struct InvalidStateError : std::runtime_error { using std::runtime_error::runtime_error; }; struct InvalidStateError : std::runtime_error { using std::runtime_error::runtime_error; };

View File

@@ -18,7 +18,8 @@
using namespace std; using namespace std;
FairMQBenchmarkSampler::FairMQBenchmarkSampler() FairMQBenchmarkSampler::FairMQBenchmarkSampler()
: fSameMessage(true) : fMultipart(false)
, fNumParts(1)
, fMsgSize(10000) , fMsgSize(10000)
, fMsgRate(0) , fMsgRate(0)
, fNumIterations(0) , fNumIterations(0)
@@ -33,8 +34,9 @@ FairMQBenchmarkSampler::~FairMQBenchmarkSampler()
void FairMQBenchmarkSampler::InitTask() void FairMQBenchmarkSampler::InitTask()
{ {
fSameMessage = fConfig->GetValue<bool>("same-msg"); fMultipart = fConfig->GetValue<bool>("multipart");
fMsgSize = fConfig->GetValue<int>("msg-size"); fNumParts = fConfig->GetValue<size_t>("num-parts");
fMsgSize = fConfig->GetValue<size_t>("msg-size");
fMsgRate = fConfig->GetValue<float>("msg-rate"); fMsgRate = fConfig->GetValue<float>("msg-rate");
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations"); fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
fOutChannelName = fConfig->GetValue<string>("out-channel"); fOutChannelName = fConfig->GetValue<string>("out-channel");
@@ -54,12 +56,16 @@ void FairMQBenchmarkSampler::Run()
while (CheckCurrentState(RUNNING)) while (CheckCurrentState(RUNNING))
{ {
if (fSameMessage) if (fMultipart)
{ {
FairMQMessagePtr msg(dataOutChannel.NewMessage()); FairMQParts parts;
msg->Copy(*baseMsg);
if (dataOutChannel.Send(msg) >= 0) for (size_t i = 0; i < fNumParts; ++i)
{
parts.AddPart(dataOutChannel.NewMessage(fMsgSize));
}
if (dataOutChannel.Send(parts) >= 0)
{ {
if (fMaxIterations > 0) if (fMaxIterations > 0)
{ {

View File

@@ -26,8 +26,9 @@ class FairMQBenchmarkSampler : public FairMQDevice
virtual ~FairMQBenchmarkSampler(); virtual ~FairMQBenchmarkSampler();
protected: protected:
bool fSameMessage; bool fMultipart;
int fMsgSize; size_t fNumParts;
size_t fMsgSize;
std::atomic<int> fMsgCounter; std::atomic<int> fMsgCounter;
float fMsgRate; float fMsgRate;
uint64_t fNumIterations; uint64_t fNumIterations;

View File

@@ -20,7 +20,7 @@
using namespace std; using namespace std;
FairMQMerger::FairMQMerger() FairMQMerger::FairMQMerger()
: fMultipart(1) : fMultipart(true)
, fInChannelName("data-in") , fInChannelName("data-in")
, fOutChannelName("data-out") , fOutChannelName("data-out")
{ {
@@ -30,6 +30,8 @@ void FairMQMerger::RegisterChannelEndpoints()
{ {
RegisterChannelEndpoint(fInChannelName, 1, 10000); RegisterChannelEndpoint(fInChannelName, 1, 10000);
RegisterChannelEndpoint(fOutChannelName, 1, 1); RegisterChannelEndpoint(fOutChannelName, 1, 1);
PrintRegisteredChannels();
} }
FairMQMerger::~FairMQMerger() FairMQMerger::~FairMQMerger()
@@ -38,7 +40,7 @@ FairMQMerger::~FairMQMerger()
void FairMQMerger::InitTask() void FairMQMerger::InitTask()
{ {
fMultipart = fConfig->GetValue<int>("multipart"); fMultipart = fConfig->GetValue<bool>("multipart");
fInChannelName = fConfig->GetValue<string>("in-channel"); fInChannelName = fConfig->GetValue<string>("in-channel");
fOutChannelName = fConfig->GetValue<string>("out-channel"); fOutChannelName = fConfig->GetValue<string>("out-channel");
} }
@@ -47,7 +49,7 @@ void FairMQMerger::Run()
{ {
int numInputs = fChannels.at(fInChannelName).size(); int numInputs = fChannels.at(fInChannelName).size();
vector<const FairMQChannel*> chans; vector<FairMQChannel*> chans;
for (auto& chan : fChannels.at(fInChannelName)) for (auto& chan : fChannels.at(fInChannelName))
{ {

View File

@@ -26,7 +26,7 @@ class FairMQMerger : public FairMQDevice
virtual ~FairMQMerger(); virtual ~FairMQMerger();
protected: protected:
int fMultipart; bool fMultipart;
std::string fInChannelName; std::string fInChannelName;
std::string fOutChannelName; std::string fOutChannelName;

View File

@@ -14,7 +14,7 @@
using namespace std; using namespace std;
FairMQMultiplier::FairMQMultiplier() FairMQMultiplier::FairMQMultiplier()
: fMultipart(1) : fMultipart(true)
, fNumOutputs(0) , fNumOutputs(0)
, fInChannelName() , fInChannelName()
, fOutChannelNames() , fOutChannelNames()
@@ -27,7 +27,7 @@ FairMQMultiplier::~FairMQMultiplier()
void FairMQMultiplier::InitTask() void FairMQMultiplier::InitTask()
{ {
fMultipart = fConfig->GetValue<int>("multipart"); fMultipart = fConfig->GetValue<bool>("multipart");
fInChannelName = fConfig->GetValue<string>("in-channel"); fInChannelName = fConfig->GetValue<string>("in-channel");
fOutChannelNames = fConfig->GetValue<vector<string>>("out-channel"); fOutChannelNames = fConfig->GetValue<vector<string>>("out-channel");
fNumOutputs = fChannels.at(fOutChannelNames.at(0)).size(); fNumOutputs = fChannels.at(fOutChannelNames.at(0)).size();

View File

@@ -20,7 +20,7 @@ class FairMQMultiplier : public FairMQDevice
virtual ~FairMQMultiplier(); virtual ~FairMQMultiplier();
protected: protected:
int fMultipart; bool fMultipart;
int fNumOutputs; int fNumOutputs;
std::string fInChannelName; std::string fInChannelName;
std::vector<std::string> fOutChannelNames; std::vector<std::string> fOutChannelNames;

View File

@@ -20,7 +20,7 @@
using namespace std; using namespace std;
FairMQProxy::FairMQProxy() FairMQProxy::FairMQProxy()
: fMultipart(1) : fMultipart(true)
, fInChannelName() , fInChannelName()
, fOutChannelName() , fOutChannelName()
{ {
@@ -32,7 +32,7 @@ FairMQProxy::~FairMQProxy()
void FairMQProxy::InitTask() void FairMQProxy::InitTask()
{ {
fMultipart = fConfig->GetValue<int>("multipart"); fMultipart = fConfig->GetValue<bool>("multipart");
fInChannelName = fConfig->GetValue<string>("in-channel"); fInChannelName = fConfig->GetValue<string>("in-channel");
fOutChannelName = fConfig->GetValue<string>("out-channel"); fOutChannelName = fConfig->GetValue<string>("out-channel");
} }

View File

@@ -26,7 +26,7 @@ class FairMQProxy : public FairMQDevice
virtual ~FairMQProxy(); virtual ~FairMQProxy();
protected: protected:
int fMultipart; bool fMultipart;
std::string fInChannelName; std::string fInChannelName;
std::string fOutChannelName; std::string fOutChannelName;

View File

@@ -27,7 +27,8 @@ class FairMQSink : public FairMQDevice//, public OutputPolicy
{ {
public: public:
FairMQSink() FairMQSink()
: fMaxIterations(0) : fMultipart(false)
, fMaxIterations(0)
, fNumIterations(0) , fNumIterations(0)
, fInChannelName() , fInChannelName()
{} {}
@@ -36,12 +37,14 @@ class FairMQSink : public FairMQDevice//, public OutputPolicy
{} {}
protected: protected:
bool fMultipart;
uint64_t fMaxIterations; uint64_t fMaxIterations;
uint64_t fNumIterations; uint64_t fNumIterations;
std::string fInChannelName; std::string fInChannelName;
virtual void InitTask() virtual void InitTask()
{ {
fMultipart = fConfig->GetValue<bool>("multipart");
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations"); fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
fInChannelName = fConfig->GetValue<std::string>("in-channel"); fInChannelName = fConfig->GetValue<std::string>("in-channel");
} }
@@ -56,18 +59,39 @@ class FairMQSink : public FairMQDevice//, public OutputPolicy
while (CheckCurrentState(RUNNING)) while (CheckCurrentState(RUNNING))
{ {
FairMQMessagePtr msg(dataInChannel.NewMessage()); if (fMultipart)
if (dataInChannel.Receive(msg) >= 0)
{ {
if (fMaxIterations > 0) FairMQParts parts;
if (dataInChannel.Receive(parts) >= 0)
{ {
if (fNumIterations >= fMaxIterations) if (fMaxIterations > 0)
{ {
break; if (fNumIterations >= fMaxIterations)
{
LOG(info) << "Configured maximum number of iterations reached.";
break;
}
} }
fNumIterations++;
}
}
else
{
FairMQMessagePtr msg(dataInChannel.NewMessage());
if (dataInChannel.Receive(msg) >= 0)
{
if (fMaxIterations > 0)
{
if (fNumIterations >= fMaxIterations)
{
LOG(info) << "Configured maximum number of iterations reached.";
break;
}
}
fNumIterations++;
} }
fNumIterations++;
} }
} }

View File

@@ -20,7 +20,7 @@
using namespace std; using namespace std;
FairMQSplitter::FairMQSplitter() FairMQSplitter::FairMQSplitter()
: fMultipart(1) : fMultipart(true)
, fNumOutputs(0) , fNumOutputs(0)
, fDirection(0) , fDirection(0)
, fInChannelName() , fInChannelName()
@@ -34,7 +34,7 @@ FairMQSplitter::~FairMQSplitter()
void FairMQSplitter::InitTask() void FairMQSplitter::InitTask()
{ {
fMultipart = fConfig->GetValue<int>("multipart"); fMultipart = fConfig->GetValue<bool>("multipart");
fInChannelName = fConfig->GetValue<string>("in-channel"); fInChannelName = fConfig->GetValue<string>("in-channel");
fOutChannelName = fConfig->GetValue<string>("out-channel"); fOutChannelName = fConfig->GetValue<string>("out-channel");
fNumOutputs = fChannels.at(fOutChannelName).size(); fNumOutputs = fChannels.at(fOutChannelName).size();

View File

@@ -26,7 +26,7 @@ class FairMQSplitter : public FairMQDevice
virtual ~FairMQSplitter(); virtual ~FairMQSplitter();
protected: protected:
int fMultipart; bool fMultipart;
int fNumOutputs; int fNumOutputs;
int fDirection; int fDirection;
std::string fInChannelName; std::string fInChannelName;

View File

@@ -24,8 +24,9 @@ using namespace std;
fair::mq::Transport FairMQMessageNN::fTransportType = fair::mq::Transport::NN; fair::mq::Transport FairMQMessageNN::fTransportType = fair::mq::Transport::NN;
FairMQMessageNN::FairMQMessageNN() FairMQMessageNN::FairMQMessageNN(FairMQTransportFactory* factory)
: fMessage(nullptr) : FairMQMessage{factory}
, fMessage(nullptr)
, fSize(0) , fSize(0)
, fHint(0) , fHint(0)
, fReceiving(false) , fReceiving(false)
@@ -38,8 +39,9 @@ FairMQMessageNN::FairMQMessageNN()
} }
} }
FairMQMessageNN::FairMQMessageNN(const size_t size) FairMQMessageNN::FairMQMessageNN(const size_t size, FairMQTransportFactory* factory)
: fMessage(nullptr) : FairMQMessage{factory}
, fMessage(nullptr)
, fSize(0) , fSize(0)
, fHint(0) , fHint(0)
, fReceiving(false) , fReceiving(false)
@@ -59,8 +61,9 @@ FairMQMessageNN::FairMQMessageNN(const size_t size)
* create FairMQMessage object only with size parameter and fill it with data. * create FairMQMessage object only with size parameter and fill it with data.
* possible TODO: make this zero copy (will should then be as efficient as ZeroMQ). * possible TODO: make this zero copy (will should then be as efficient as ZeroMQ).
*/ */
FairMQMessageNN::FairMQMessageNN(void* data, const size_t size, fairmq_free_fn* ffn, void* hint) FairMQMessageNN::FairMQMessageNN(void* data, const size_t size, fairmq_free_fn* ffn, void* hint, FairMQTransportFactory* factory)
: fMessage(nullptr) : FairMQMessage{factory}
, fMessage(nullptr)
, fSize(0) , fSize(0)
, fHint(0) , fHint(0)
, fReceiving(false) , fReceiving(false)
@@ -86,8 +89,9 @@ FairMQMessageNN::FairMQMessageNN(void* data, const size_t size, fairmq_free_fn*
} }
} }
FairMQMessageNN::FairMQMessageNN(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint) FairMQMessageNN::FairMQMessageNN(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint, FairMQTransportFactory* factory)
: fMessage(data) : FairMQMessage{factory}
, fMessage(data)
, fSize(size) , fSize(size)
, fHint(reinterpret_cast<size_t>(hint)) , fHint(reinterpret_cast<size_t>(hint))
, fReceiving(false) , fReceiving(false)
@@ -201,30 +205,6 @@ void FairMQMessageNN::Copy(const FairMQMessage& msg)
} }
} }
void FairMQMessageNN::Copy(const FairMQMessagePtr& msg)
{
if (fMessage)
{
if (nn_freemsg(fMessage) < 0)
{
LOG(error) << "failed freeing message, reason: " << nn_strerror(errno);
}
}
size_t size = msg->GetSize();
fMessage = nn_allocmsg(size, 0);
if (!fMessage)
{
LOG(error) << "failed allocating message, reason: " << nn_strerror(errno);
}
else
{
memcpy(fMessage, static_cast<FairMQMessageNN*>(msg.get())->GetMessage(), size);
fSize = size;
}
}
void FairMQMessageNN::CloseMessage() void FairMQMessageNN::CloseMessage()
{ {
if (nn_freemsg(fMessage) < 0) if (nn_freemsg(fMessage) < 0)

View File

@@ -24,15 +24,15 @@
class FairMQSocketNN; class FairMQSocketNN;
class FairMQMessageNN : public FairMQMessage class FairMQMessageNN final : public FairMQMessage
{ {
friend class FairMQSocketNN; friend class FairMQSocketNN;
public: public:
FairMQMessageNN(); FairMQMessageNN(FairMQTransportFactory* factory = nullptr);
FairMQMessageNN(const size_t size); FairMQMessageNN(const size_t size, FairMQTransportFactory* factory = nullptr);
FairMQMessageNN(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr); FairMQMessageNN(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr, FairMQTransportFactory* factory = nullptr);
FairMQMessageNN(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0); FairMQMessageNN(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0, FairMQTransportFactory* factory = nullptr);
FairMQMessageNN(const FairMQMessageNN&) = delete; FairMQMessageNN(const FairMQMessageNN&) = delete;
FairMQMessageNN operator=(const FairMQMessageNN&) = delete; FairMQMessageNN operator=(const FairMQMessageNN&) = delete;
@@ -49,7 +49,6 @@ class FairMQMessageNN : public FairMQMessage
fair::mq::Transport GetType() const override; fair::mq::Transport GetType() const override;
void Copy(const FairMQMessage& msg) override; void Copy(const FairMQMessage& msg) override;
void Copy(const FairMQMessagePtr& msg) override;
~FairMQMessageNN() override; ~FairMQMessageNN() override;

View File

@@ -19,6 +19,7 @@
#include <nanomsg/pair.h> #include <nanomsg/pair.h>
#include "FairMQPollerNN.h" #include "FairMQPollerNN.h"
#include "FairMQSocketNN.h"
#include "FairMQLogger.h" #include "FairMQLogger.h"
using namespace std; using namespace std;
@@ -33,17 +34,17 @@ FairMQPollerNN::FairMQPollerNN(const vector<FairMQChannel>& channels)
for (int i = 0; i < fNumItems; ++i) for (int i = 0; i < fNumItems; ++i)
{ {
fItems[i].fd = channels.at(i).GetSocket().GetSocket(1); fItems[i].fd = static_cast<const FairMQSocketNN*>(&(channels.at(i).GetSocket()))->GetSocket();
int type = 0; int type = 0;
size_t sz = sizeof(type); size_t sz = sizeof(type);
nn_getsockopt(channels.at(i).GetSocket().GetSocket(1), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz); nn_getsockopt(static_cast<const FairMQSocketNN*>(&(channels.at(i).GetSocket()))->GetSocket(), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz);
SetItemEvents(fItems[i], type); SetItemEvents(fItems[i], type);
} }
} }
FairMQPollerNN::FairMQPollerNN(const vector<const FairMQChannel*>& channels) FairMQPollerNN::FairMQPollerNN(const vector<FairMQChannel*>& channels)
: fItems() : fItems()
, fNumItems(0) , fNumItems(0)
, fOffsetMap() , fOffsetMap()
@@ -53,11 +54,11 @@ FairMQPollerNN::FairMQPollerNN(const vector<const FairMQChannel*>& channels)
for (int i = 0; i < fNumItems; ++i) for (int i = 0; i < fNumItems; ++i)
{ {
fItems[i].fd = channels.at(i)->GetSocket().GetSocket(1); fItems[i].fd = static_cast<const FairMQSocketNN*>(&(channels.at(i)->GetSocket()))->GetSocket();
int type = 0; int type = 0;
size_t sz = sizeof(type); size_t sz = sizeof(type);
nn_getsockopt(channels.at(i)->GetSocket().GetSocket(1), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz); nn_getsockopt(static_cast<const FairMQSocketNN*>(&(channels.at(i)->GetSocket()))->GetSocket(), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz);
SetItemEvents(fItems[i], type); SetItemEvents(fItems[i], type);
} }
@@ -87,11 +88,11 @@ FairMQPollerNN::FairMQPollerNN(const unordered_map<string, vector<FairMQChannel>
for (unsigned int i = 0; i < channelsMap.at(channel).size(); ++i) for (unsigned int i = 0; i < channelsMap.at(channel).size(); ++i)
{ {
index = fOffsetMap[channel] + i; index = fOffsetMap[channel] + i;
fItems[index].fd = channelsMap.at(channel).at(i).GetSocket().GetSocket(1); fItems[index].fd = static_cast<const FairMQSocketNN*>(&(channelsMap.at(channel).at(i).GetSocket()))->GetSocket();
int type = 0; int type = 0;
size_t sz = sizeof(type); size_t sz = sizeof(type);
nn_getsockopt(channelsMap.at(channel).at(i).GetSocket().GetSocket(1), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz); nn_getsockopt(static_cast<const FairMQSocketNN*>(&(channelsMap.at(channel).at(i).GetSocket()))->GetSocket(), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz);
SetItemEvents(fItems[index], type); SetItemEvents(fItems[index], type);
} }
@@ -105,27 +106,6 @@ FairMQPollerNN::FairMQPollerNN(const unordered_map<string, vector<FairMQChannel>
} }
} }
FairMQPollerNN::FairMQPollerNN(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket)
: fItems()
, fNumItems(2)
, fOffsetMap()
{
fItems = new nn_pollfd[fNumItems];
fItems[0].fd = cmdSocket.GetSocket(1);
fItems[0].events = NN_POLLIN;
fItems[0].revents = 0;
fItems[1].fd = dataSocket.GetSocket(1);
fItems[1].revents = 0;
int type = 0;
size_t sz = sizeof(type);
nn_getsockopt(dataSocket.GetSocket(1), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz);
SetItemEvents(fItems[1], type);
}
void FairMQPollerNN::SetItemEvents(nn_pollfd& item, const int type) void FairMQPollerNN::SetItemEvents(nn_pollfd& item, const int type)
{ {
if (type == NN_REQ || type == NN_REP || type == NN_PAIR) if (type == NN_REQ || type == NN_REP || type == NN_PAIR)

View File

@@ -26,14 +26,14 @@
class FairMQChannel; class FairMQChannel;
struct nn_pollfd; struct nn_pollfd;
class FairMQPollerNN : public FairMQPoller class FairMQPollerNN final : public FairMQPoller
{ {
friend class FairMQChannel; friend class FairMQChannel;
friend class FairMQTransportFactoryNN; friend class FairMQTransportFactoryNN;
public: public:
FairMQPollerNN(const std::vector<FairMQChannel>& channels); FairMQPollerNN(const std::vector<FairMQChannel>& channels);
FairMQPollerNN(const std::vector<const FairMQChannel*>& channels); FairMQPollerNN(const std::vector<FairMQChannel*>& channels);
FairMQPollerNN(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList); FairMQPollerNN(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList);
FairMQPollerNN(const FairMQPollerNN&) = delete; FairMQPollerNN(const FairMQPollerNN&) = delete;
@@ -41,17 +41,15 @@ class FairMQPollerNN : public FairMQPoller
void SetItemEvents(nn_pollfd& item, const int type); void SetItemEvents(nn_pollfd& item, const int type);
virtual void Poll(const int timeout); void Poll(const int timeout) override;
virtual bool CheckInput(const int index); bool CheckInput(const int index) override;
virtual bool CheckOutput(const int index); bool CheckOutput(const int index) override;
virtual bool CheckInput(const std::string& channelKey, const int index); bool CheckInput(const std::string& channelKey, const int index) override;
virtual bool CheckOutput(const std::string& channelKey, const int index); bool CheckOutput(const std::string& channelKey, const int index) override;
virtual ~FairMQPollerNN(); ~FairMQPollerNN() override;
private: private:
FairMQPollerNN(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket);
nn_pollfd* fItems; nn_pollfd* fItems;
int fNumItems; int fNumItems;

View File

@@ -16,6 +16,7 @@
#include "FairMQMessageNN.h" #include "FairMQMessageNN.h"
#include "FairMQLogger.h" #include "FairMQLogger.h"
#include "FairMQUnmanagedRegionNN.h" #include "FairMQUnmanagedRegionNN.h"
#include <fairmq/Tools.h>
#include <nanomsg/nn.h> #include <nanomsg/nn.h>
#include <nanomsg/pipeline.h> #include <nanomsg/pipeline.h>
@@ -27,11 +28,13 @@
#include <msgpack.hpp> #include <msgpack.hpp>
using namespace std; using namespace std;
using namespace fair::mq;
atomic<bool> FairMQSocketNN::fInterrupted(false); atomic<bool> FairMQSocketNN::fInterrupted(false);
FairMQSocketNN::FairMQSocketNN(const string& type, const string& name, const string& id /*= ""*/) FairMQSocketNN::FairMQSocketNN(const string& type, const string& name, const string& id /*= ""*/, FairMQTransportFactory* fac /*=nullptr*/)
: fSocket(-1) : FairMQSocket{fac}
, fSocket(-1)
, fId(id + "." + name + "." + type) , fId(id + "." + name + "." + type)
, fBytesTx(0) , fBytesTx(0)
, fBytesRx(0) , fBytesRx(0)
@@ -39,6 +42,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, const string& name, const str
, fMessagesRx(0) , fMessagesRx(0)
, fSndTimeout(100) , fSndTimeout(100)
, fRcvTimeout(100) , fRcvTimeout(100)
, fLinger(500)
{ {
if (type == "router" || type == "dealer") if (type == "router" || type == "dealer")
{ {
@@ -84,7 +88,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, const string& name, const str
} }
#endif #endif
// LOG(info) << "created socket " << fId; LOG(debug) << "Created socket " << GetId();
} }
string FairMQSocketNN::GetId() string FairMQSocketNN::GetId()
@@ -96,38 +100,35 @@ bool FairMQSocketNN::Bind(const string& address)
{ {
// LOG(info) << "bind socket " << fId << " on " << address; // LOG(info) << "bind socket " << fId << " on " << address;
int eid = nn_bind(fSocket, address.c_str()); if (nn_bind(fSocket, address.c_str()) < 0)
if (eid < 0)
{ {
LOG(error) << "failed binding socket " << fId << ", reason: " << nn_strerror(errno); LOG(error) << "failed binding socket " << fId << ", reason: " << nn_strerror(errno);
return false; return false;
} }
return true; return true;
} }
void FairMQSocketNN::Connect(const string& address) bool FairMQSocketNN::Connect(const string& address)
{ {
// LOG(info) << "connect socket " << fId << " to " << address; // LOG(info) << "connect socket " << fId << " to " << address;
int eid = nn_connect(fSocket, address.c_str()); if (nn_connect(fSocket, address.c_str()) < 0)
if (eid < 0)
{ {
LOG(error) << "failed connecting socket " << fId << ", reason: " << nn_strerror(errno); LOG(error) << "failed connecting socket " << fId << ", reason: " << nn_strerror(errno);
return false;
} }
return true;
} }
int FairMQSocketNN::Send(FairMQMessagePtr& msg, const int timeout) { return SendImpl(msg, 0, timeout); } int FairMQSocketNN::Send(FairMQMessagePtr& msg, const int timeout)
int FairMQSocketNN::Receive(FairMQMessagePtr& msg, const int timeout) { return ReceiveImpl(msg, 0, timeout); }
int64_t FairMQSocketNN::Send(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return SendImpl(msgVec, 0, timeout); }
int64_t FairMQSocketNN::Receive(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return ReceiveImpl(msgVec, 0, timeout); }
int FairMQSocketNN::TrySend(FairMQMessagePtr& msg) { return SendImpl(msg, NN_DONTWAIT, 0); }
int FairMQSocketNN::TryReceive(FairMQMessagePtr& msg) { return ReceiveImpl(msg, NN_DONTWAIT, 0); }
int64_t FairMQSocketNN::TrySend(vector<unique_ptr<FairMQMessage>>& msgVec) { return SendImpl(msgVec, NN_DONTWAIT, 0); }
int64_t FairMQSocketNN::TryReceive(vector<unique_ptr<FairMQMessage>>& msgVec) { return ReceiveImpl(msgVec, NN_DONTWAIT, 0); }
int FairMQSocketNN::SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout)
{ {
int flags = 0;
if (timeout == 0)
{
flags = NN_DONTWAIT;
}
int nbytes = -1; int nbytes = -1;
int elapsed = 0; int elapsed = 0;
@@ -155,15 +156,11 @@ int FairMQSocketNN::SendImpl(FairMQMessagePtr& msg, const int flags, const int t
return nbytes; return nbytes;
} }
#if NN_VERSION_CURRENT>2 // backwards-compatibility with nanomsg version<=0.6
else if (nn_errno() == ETIMEDOUT) else if (nn_errno() == ETIMEDOUT)
#else
else if (nn_errno() == EAGAIN)
#endif
{ {
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0)) if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
{ {
if (timeout) if (timeout > 0)
{ {
elapsed += fSndTimeout; elapsed += fSndTimeout;
if (elapsed >= timeout) if (elapsed >= timeout)
@@ -195,8 +192,13 @@ int FairMQSocketNN::SendImpl(FairMQMessagePtr& msg, const int flags, const int t
} }
} }
int FairMQSocketNN::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout) int FairMQSocketNN::Receive(FairMQMessagePtr& msg, const int timeout)
{ {
int flags = 0;
if (timeout == 0)
{
flags = NN_DONTWAIT;
}
int elapsed = 0; int elapsed = 0;
FairMQMessageNN* msgPtr = static_cast<FairMQMessageNN*>(msg.get()); FairMQMessageNN* msgPtr = static_cast<FairMQMessageNN*>(msg.get());
@@ -213,15 +215,11 @@ int FairMQSocketNN::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const in
msgPtr->fReceiving = true; msgPtr->fReceiving = true;
return nbytes; return nbytes;
} }
#if NN_VERSION_CURRENT>2 // backwards-compatibility with nanomsg version<=0.6
else if (nn_errno() == ETIMEDOUT) else if (nn_errno() == ETIMEDOUT)
#else
else if (nn_errno() == EAGAIN)
#endif
{ {
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0)) if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
{ {
if (timeout) if (timeout > 0)
{ {
elapsed += fRcvTimeout; elapsed += fRcvTimeout;
if (elapsed >= timeout) if (elapsed >= timeout)
@@ -253,8 +251,13 @@ int FairMQSocketNN::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const in
} }
} }
int64_t FairMQSocketNN::SendImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout) int64_t FairMQSocketNN::Send(vector<FairMQMessagePtr>& msgVec, const int timeout)
{ {
int flags = 0;
if (timeout == 0)
{
flags = NN_DONTWAIT;
}
const unsigned int vecSize = msgVec.size(); const unsigned int vecSize = msgVec.size();
int elapsed = 0; int elapsed = 0;
@@ -287,15 +290,11 @@ int64_t FairMQSocketNN::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fla
++fMessagesTx; ++fMessagesTx;
return nbytes; return nbytes;
} }
#if NN_VERSION_CURRENT>2 // backwards-compatibility with nanomsg version<=0.6
else if (nn_errno() == ETIMEDOUT) else if (nn_errno() == ETIMEDOUT)
#else
else if (nn_errno() == EAGAIN)
#endif
{ {
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0)) if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
{ {
if (timeout) if (timeout > 0)
{ {
elapsed += fSndTimeout; elapsed += fSndTimeout;
if (elapsed >= timeout) if (elapsed >= timeout)
@@ -327,8 +326,13 @@ int64_t FairMQSocketNN::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fla
} }
} }
int64_t FairMQSocketNN::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout) int64_t FairMQSocketNN::Receive(vector<FairMQMessagePtr>& msgVec, const int timeout)
{ {
int flags = 0;
if (timeout == 0)
{
flags = NN_DONTWAIT;
}
// Warn if the vector is filled before Receive() and empty it. // Warn if the vector is filled before Receive() and empty it.
// if (msgVec.size() > 0) // if (msgVec.size() > 0)
// { // {
@@ -365,7 +369,7 @@ int64_t FairMQSocketNN::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int
object.convert(buf); object.convert(buf);
// get the single message size // get the single message size
size_t size = buf.size() * sizeof(char); size_t size = buf.size() * sizeof(char);
FairMQMessagePtr part(new FairMQMessageNN(size)); FairMQMessagePtr part(new FairMQMessageNN(size, GetTransport()));
static_cast<FairMQMessageNN*>(part.get())->fReceiving = true; static_cast<FairMQMessageNN*>(part.get())->fReceiving = true;
memcpy(part->GetData(), buf.data(), size); memcpy(part->GetData(), buf.data(), size);
msgVec.push_back(move(part)); msgVec.push_back(move(part));
@@ -374,15 +378,11 @@ int64_t FairMQSocketNN::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int
nn_freemsg(ptr); nn_freemsg(ptr);
return nbytes; return nbytes;
} }
#if NN_VERSION_CURRENT>2 // backwards-compatibility with nanomsg version<=0.6
else if (nn_errno() == ETIMEDOUT) else if (nn_errno() == ETIMEDOUT)
#else
else if (nn_errno() == EAGAIN)
#endif
{ {
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0)) if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
{ {
if (timeout) if (timeout > 0)
{ {
elapsed += fRcvTimeout; elapsed += fRcvTimeout;
if (elapsed >= timeout) if (elapsed >= timeout)
@@ -429,12 +429,7 @@ void FairMQSocketNN::Resume()
fInterrupted = false; fInterrupted = false;
} }
void* FairMQSocketNN::GetSocket() const int FairMQSocketNN::GetSocket() const
{
return nullptr; // dummy method to comply with the interface. functionality not possible in zeromq.
}
int FairMQSocketNN::GetSocket(int /*nothing*/) const
{ {
return fSocket; return fSocket;
} }
@@ -446,7 +441,7 @@ void FairMQSocketNN::SetOption(const string& option, const void* value, size_t v
int val = *(static_cast<int*>(const_cast<void*>(value))); int val = *(static_cast<int*>(const_cast<void*>(value)));
if (val <= 0) if (val <= 0)
{ {
LOG(warn) << "value for sndKernelSize/rcvKernelSize should be greater than 0, using defaults (128kB)."; LOG(warn) << "value for sndKernelSize/rcvKernelSize should be greater than 0, leaving unchanged.";
return; return;
} }
} }
@@ -456,6 +451,12 @@ void FairMQSocketNN::SetOption(const string& option, const void* value, size_t v
return; return;
} }
if (option == "linger")
{
fLinger = *static_cast<int*>(const_cast<void*>(value));
return;
}
int rc = nn_setsockopt(fSocket, NN_SOL_SOCKET, GetConstant(option), value, valueSize); int rc = nn_setsockopt(fSocket, NN_SOL_SOCKET, GetConstant(option), value, valueSize);
if (rc < 0) if (rc < 0)
{ {
@@ -465,6 +466,19 @@ void FairMQSocketNN::SetOption(const string& option, const void* value, size_t v
void FairMQSocketNN::GetOption(const string& option, void* value, size_t* valueSize) void FairMQSocketNN::GetOption(const string& option, void* value, size_t* valueSize)
{ {
if (option == "linger")
{
*static_cast<int*>(value) = fLinger;
return;
}
if (option == "snd-hwm" || option == "rcv-hwm")
{
*static_cast<int*>(value) = -1;
return;
}
int rc = nn_getsockopt(fSocket, NN_SOL_SOCKET, GetConstant(option), value, valueSize); int rc = nn_getsockopt(fSocket, NN_SOL_SOCKET, GetConstant(option), value, valueSize);
if (rc < 0) if (rc < 0)
{ {
@@ -472,6 +486,73 @@ void FairMQSocketNN::GetOption(const string& option, void* value, size_t* valueS
} }
} }
void FairMQSocketNN::SetLinger(const int value)
{
fLinger = value;
}
int FairMQSocketNN::GetLinger() const
{
return fLinger;
}
void FairMQSocketNN::SetSndBufSize(const int /* value */)
{
// not used in nanomsg
}
int FairMQSocketNN::GetSndBufSize() const
{
// not used in nanomsg
return -1;
}
void FairMQSocketNN::SetRcvBufSize(const int /* value */)
{
// not used in nanomsg
}
int FairMQSocketNN::GetRcvBufSize() const
{
// not used in nanomsg
return -1;
}
void FairMQSocketNN::SetSndKernelSize(const int value)
{
if (nn_setsockopt(fSocket, NN_SOL_SOCKET, NN_SNDBUF, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed setting NN_SNDBUF, reason: ", nn_strerror(errno)));
}
}
int FairMQSocketNN::GetSndKernelSize() const
{
int value = 0;
size_t valueSize;
if (nn_getsockopt(fSocket, NN_SOL_SOCKET, NN_SNDBUF, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting NN_SNDBUF, reason: ", nn_strerror(errno)));
}
return value;
}
void FairMQSocketNN::SetRcvKernelSize(const int value)
{
if (nn_setsockopt(fSocket, NN_SOL_SOCKET, NN_RCVBUF, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed setting NN_RCVBUF, reason: ", nn_strerror(errno)));
}
}
int FairMQSocketNN::GetRcvKernelSize() const
{
int value = 0;
size_t valueSize;
if (nn_getsockopt(fSocket, NN_SOL_SOCKET, NN_RCVBUF, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting NN_RCVBUF, reason: ", nn_strerror(errno)));
}
return value;
}
unsigned long FairMQSocketNN::GetBytesTx() const unsigned long FairMQSocketNN::GetBytesTx() const
{ {
return fBytesTx; return fBytesTx;
@@ -492,40 +573,6 @@ unsigned long FairMQSocketNN::GetMessagesRx() const
return fMessagesRx; return fMessagesRx;
} }
bool FairMQSocketNN::SetSendTimeout(const int timeout, const string& /*address*/, const string& /*method*/)
{
fSndTimeout = timeout;
if (nn_setsockopt(fSocket, NN_SOL_SOCKET, NN_SNDTIMEO, &fSndTimeout, sizeof(fSndTimeout)) != 0)
{
LOG(error) << "Failed setting option 'send timeout' on socket " << fId << ", reason: " << nn_strerror(errno);
return false;
}
return true;
}
int FairMQSocketNN::GetSendTimeout() const
{
return fSndTimeout;
}
bool FairMQSocketNN::SetReceiveTimeout(const int timeout, const string& /*address*/, const string& /*method*/)
{
fRcvTimeout = timeout;
if (nn_setsockopt(fSocket, NN_SOL_SOCKET, NN_RCVTIMEO, &fRcvTimeout, sizeof(fRcvTimeout)) != 0)
{
LOG(error) << "Failed setting option 'receive timeout' on socket " << fId << ", reason: " << nn_strerror(errno);
return false;
}
return true;
}
int FairMQSocketNN::GetReceiveTimeout() const
{
return fRcvTimeout;
}
int FairMQSocketNN::GetConstant(const string& constant) int FairMQSocketNN::GetConstant(const string& constant)
{ {
if (constant == "") if (constant == "")

View File

@@ -14,31 +14,26 @@
#include "FairMQSocket.h" #include "FairMQSocket.h"
#include "FairMQMessage.h" #include "FairMQMessage.h"
class FairMQTransportFactory;
class FairMQSocketNN : public FairMQSocket class FairMQSocketNN final : public FairMQSocket
{ {
public: public:
FairMQSocketNN(const std::string& type, const std::string& name, const std::string& id = ""); FairMQSocketNN(const std::string& type, const std::string& name, const std::string& id = "", FairMQTransportFactory* fac = nullptr);
FairMQSocketNN(const FairMQSocketNN&) = delete; FairMQSocketNN(const FairMQSocketNN&) = delete;
FairMQSocketNN operator=(const FairMQSocketNN&) = delete; FairMQSocketNN operator=(const FairMQSocketNN&) = delete;
std::string GetId() override; std::string GetId() override;
bool Bind(const std::string& address) override; bool Bind(const std::string& address) override;
void Connect(const std::string& address) override; bool Connect(const std::string& address) override;
int Send(FairMQMessagePtr& msg, const int timeout = 0) override; int Send(FairMQMessagePtr& msg, const int timeout = -1) override;
int Receive(FairMQMessagePtr& msg, const int timeout = 0) override; int Receive(FairMQMessagePtr& msg, const int timeout = -1) override;
int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override; int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override; int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
int TrySend(FairMQMessagePtr& msg) override; int GetSocket() const;
int TryReceive(FairMQMessagePtr& msg) override;
int64_t TrySend(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
int64_t TryReceive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
void* GetSocket() const override;
int GetSocket(int nothing) const override;
void Close() override; void Close() override;
@@ -48,16 +43,22 @@ class FairMQSocketNN : public FairMQSocket
void SetOption(const std::string& option, const void* value, size_t valueSize) override; void SetOption(const std::string& option, const void* value, size_t valueSize) override;
void GetOption(const std::string& option, void* value, size_t* valueSize) override; void GetOption(const std::string& option, void* value, size_t* valueSize) override;
void SetLinger(const int value) override;
int GetLinger() const override;
void SetSndBufSize(const int value) override;
int GetSndBufSize() const override;
void SetRcvBufSize(const int value) override;
int GetRcvBufSize() const override;
void SetSndKernelSize(const int value) override;
int GetSndKernelSize() const override;
void SetRcvKernelSize(const int value) override;
int GetRcvKernelSize() const override;
unsigned long GetBytesTx() const override; unsigned long GetBytesTx() const override;
unsigned long GetBytesRx() const override; unsigned long GetBytesRx() const override;
unsigned long GetMessagesTx() const override; unsigned long GetMessagesTx() const override;
unsigned long GetMessagesRx() const override; unsigned long GetMessagesRx() const override;
bool SetSendTimeout(const int timeout, const std::string& address, const std::string& method) override;
int GetSendTimeout() const override;
bool SetReceiveTimeout(const int timeout, const std::string& address, const std::string& method) override;
int GetReceiveTimeout() const override;
static int GetConstant(const std::string& constant); static int GetConstant(const std::string& constant);
~FairMQSocketNN() override; ~FairMQSocketNN() override;
@@ -74,11 +75,7 @@ class FairMQSocketNN : public FairMQSocket
int fSndTimeout; int fSndTimeout;
int fRcvTimeout; int fRcvTimeout;
int fLinger;
int SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
int ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
int64_t SendImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
int64_t ReceiveImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
}; };
#endif /* FAIRMQSOCKETNN_H_ */ #endif /* FAIRMQSOCKETNN_H_ */

View File

@@ -9,6 +9,9 @@
#include "FairMQTransportFactoryNN.h" #include "FairMQTransportFactoryNN.h"
#include <nanomsg/nn.h> #include <nanomsg/nn.h>
#include <algorithm>
#include <thread>
#include <chrono>
using namespace std; using namespace std;
@@ -20,29 +23,31 @@ FairMQTransportFactoryNN::FairMQTransportFactoryNN(const string& id, const FairM
LOG(debug) << "Transport: Using nanomsg library"; LOG(debug) << "Transport: Using nanomsg library";
} }
FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage() const FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage()
{ {
return unique_ptr<FairMQMessage>(new FairMQMessageNN()); return unique_ptr<FairMQMessage>(new FairMQMessageNN(this));
} }
FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage(const size_t size) const FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage(const size_t size)
{ {
return unique_ptr<FairMQMessage>(new FairMQMessageNN(size)); return unique_ptr<FairMQMessage>(new FairMQMessageNN(size, this));
} }
FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint) const FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint)
{ {
return unique_ptr<FairMQMessage>(new FairMQMessageNN(data, size, ffn, hint)); return unique_ptr<FairMQMessage>(new FairMQMessageNN(data, size, ffn, hint, this));
} }
FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint) const FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint)
{ {
return unique_ptr<FairMQMessage>(new FairMQMessageNN(region, data, size, hint)); return unique_ptr<FairMQMessage>(new FairMQMessageNN(region, data, size, hint, this));
} }
FairMQSocketPtr FairMQTransportFactoryNN::CreateSocket(const string& type, const string& name) const FairMQSocketPtr FairMQTransportFactoryNN::CreateSocket(const string& type, const string& name)
{ {
return unique_ptr<FairMQSocket>(new FairMQSocketNN(type, name, GetId())); unique_ptr<FairMQSocket> socket(new FairMQSocketNN(type, name, GetId(), this));
fSockets.push_back(socket.get());
return socket;
} }
FairMQPollerPtr FairMQTransportFactoryNN::CreatePoller(const vector<FairMQChannel>& channels) const FairMQPollerPtr FairMQTransportFactoryNN::CreatePoller(const vector<FairMQChannel>& channels) const
@@ -50,7 +55,7 @@ FairMQPollerPtr FairMQTransportFactoryNN::CreatePoller(const vector<FairMQChanne
return unique_ptr<FairMQPoller>(new FairMQPollerNN(channels)); return unique_ptr<FairMQPoller>(new FairMQPollerNN(channels));
} }
FairMQPollerPtr FairMQTransportFactoryNN::CreatePoller(const std::vector<const FairMQChannel*>& channels) const FairMQPollerPtr FairMQTransportFactoryNN::CreatePoller(const std::vector<FairMQChannel*>& channels) const
{ {
return unique_ptr<FairMQPoller>(new FairMQPollerNN(channels)); return unique_ptr<FairMQPoller>(new FairMQPollerNN(channels));
} }
@@ -60,11 +65,6 @@ FairMQPollerPtr FairMQTransportFactoryNN::CreatePoller(const unordered_map<strin
return unique_ptr<FairMQPoller>(new FairMQPollerNN(channelsMap, channelList)); return unique_ptr<FairMQPoller>(new FairMQPollerNN(channelsMap, channelList));
} }
FairMQPollerPtr FairMQTransportFactoryNN::CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const
{
return unique_ptr<FairMQPoller>(new FairMQPollerNN(cmdSocket, dataSocket));
}
FairMQUnmanagedRegionPtr FairMQTransportFactoryNN::CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const FairMQUnmanagedRegionPtr FairMQTransportFactoryNN::CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const
{ {
return unique_ptr<FairMQUnmanagedRegion>(new FairMQUnmanagedRegionNN(size, callback)); return unique_ptr<FairMQUnmanagedRegion>(new FairMQUnmanagedRegionNN(size, callback));
@@ -75,6 +75,17 @@ fair::mq::Transport FairMQTransportFactoryNN::GetType() const
return fTransportType; return fTransportType;
} }
void FairMQTransportFactoryNN::Reset()
{
auto it = max_element(fSockets.begin(), fSockets.end(), [](FairMQSocket* s1, FairMQSocket* s2) {
return static_cast<FairMQSocketNN*>(s1)->GetLinger() < static_cast<FairMQSocketNN*>(s2)->GetLinger();
});
if (it != fSockets.end()) {
this_thread::sleep_for(chrono::milliseconds(static_cast<FairMQSocketNN*>(*it)->GetLinger()));
}
fSockets.clear();
}
FairMQTransportFactoryNN::~FairMQTransportFactoryNN() FairMQTransportFactoryNN::~FairMQTransportFactoryNN()
{ {
// nn_term(); // nn_term();

View File

@@ -19,23 +19,22 @@
#include <vector> #include <vector>
#include <string> #include <string>
class FairMQTransportFactoryNN : public FairMQTransportFactory class FairMQTransportFactoryNN final : public FairMQTransportFactory
{ {
public: public:
FairMQTransportFactoryNN(const std::string& id = "", const FairMQProgOptions* config = nullptr); FairMQTransportFactoryNN(const std::string& id = "", const FairMQProgOptions* config = nullptr);
~FairMQTransportFactoryNN() override; ~FairMQTransportFactoryNN() override;
FairMQMessagePtr CreateMessage() const override; FairMQMessagePtr CreateMessage() override;
FairMQMessagePtr CreateMessage(const size_t size) const override; FairMQMessagePtr CreateMessage(const size_t size) override;
FairMQMessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) const override; FairMQMessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) override;
FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0) const override; FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0) override;
FairMQSocketPtr CreateSocket(const std::string& type, const std::string& name) const override; FairMQSocketPtr CreateSocket(const std::string& type, const std::string& name) override;
FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel>& channels) const override; FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel>& channels) const override;
FairMQPollerPtr CreatePoller(const std::vector<const FairMQChannel*>& channels) const override; FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel*>& channels) const override;
FairMQPollerPtr CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const override; FairMQPollerPtr CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const override;
FairMQPollerPtr CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const override;
FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const override; FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const override;
@@ -43,9 +42,11 @@ class FairMQTransportFactoryNN : public FairMQTransportFactory
void Interrupt() override { FairMQSocketNN::Interrupt(); } void Interrupt() override { FairMQSocketNN::Interrupt(); }
void Resume() override { FairMQSocketNN::Resume(); } void Resume() override { FairMQSocketNN::Resume(); }
void Reset() override;
private: private:
static fair::mq::Transport fTransportType; static fair::mq::Transport fTransportType;
mutable std::vector<FairMQSocket*> fSockets;
}; };
#endif /* FAIRMQTRANSPORTFACTORYNN_H_ */ #endif /* FAIRMQTRANSPORTFACTORYNN_H_ */

View File

@@ -13,7 +13,7 @@
#include <cstddef> // size_t #include <cstddef> // size_t
class FairMQUnmanagedRegionNN : public FairMQUnmanagedRegion class FairMQUnmanagedRegionNN final : public FairMQUnmanagedRegion
{ {
friend class FairMQSocketNN; friend class FairMQSocketNN;

View File

@@ -138,11 +138,6 @@ auto Message::Copy(const fair::mq::Message& /*msg*/) -> void
throw MessageError{"Not yet implemented."}; throw MessageError{"Not yet implemented."};
} }
auto Message::Copy(const fair::mq::MessagePtr& /*msg*/) -> void
{
throw MessageError{"Not yet implemented."};
}
Message::~Message() Message::~Message()
{ {
if (fFreeFunction) { if (fFreeFunction) {

View File

@@ -30,7 +30,7 @@ namespace ofi
* *
* @todo TODO insert long description * @todo TODO insert long description
*/ */
class Message : public fair::mq::Message class Message final : public fair::mq::Message
{ {
public: public:
Message(); Message();
@@ -53,7 +53,6 @@ class Message : public fair::mq::Message
auto GetType() const -> fair::mq::Transport override { return fair::mq::Transport::OFI; } auto GetType() const -> fair::mq::Transport override { return fair::mq::Transport::OFI; }
auto Copy(const fair::mq::Message& msg) -> void override; auto Copy(const fair::mq::Message& msg) -> void override;
auto Copy(const fair::mq::MessagePtr& msg) -> void override;
~Message() override; ~Message() override;

View File

@@ -7,6 +7,7 @@
********************************************************************************/ ********************************************************************************/
#include <fairmq/ofi/Poller.h> #include <fairmq/ofi/Poller.h>
#include <fairmq/ofi/Socket.h>
#include <fairmq/Tools.h> #include <fairmq/Tools.h>
#include <FairMQLogger.h> #include <FairMQLogger.h>
@@ -27,13 +28,13 @@ Poller::Poller(const vector<FairMQChannel>& channels)
fItems = new zmq_pollitem_t[fNumItems]; fItems = new zmq_pollitem_t[fNumItems];
for (int i = 0; i < fNumItems; ++i) { for (int i = 0; i < fNumItems; ++i) {
fItems[i].socket = channels.at(i).GetSocket().GetSocket(); fItems[i].socket = static_cast<const Socket*>(&(channels.at(i).GetSocket()))->GetSocket();
fItems[i].fd = 0; fItems[i].fd = 0;
fItems[i].revents = 0; fItems[i].revents = 0;
int type = 0; int type = 0;
size_t size = sizeof(type); size_t size = sizeof(type);
zmq_getsockopt(channels.at(i).GetSocket().GetSocket(), ZMQ_TYPE, &type, &size); zmq_getsockopt(static_cast<const Socket*>(&(channels.at(i).GetSocket()))->GetSocket(), ZMQ_TYPE, &type, &size);
SetItemEvents(fItems[i], type); SetItemEvents(fItems[i], type);
} }
@@ -45,13 +46,13 @@ Poller::Poller(const vector<const FairMQChannel*>& channels)
fItems = new zmq_pollitem_t[fNumItems]; fItems = new zmq_pollitem_t[fNumItems];
for (int i = 0; i < fNumItems; ++i) { for (int i = 0; i < fNumItems; ++i) {
fItems[i].socket = channels.at(i)->GetSocket().GetSocket(); fItems[i].socket = static_cast<const Socket*>(&(channels.at(i)->GetSocket()))->GetSocket();
fItems[i].fd = 0; fItems[i].fd = 0;
fItems[i].revents = 0; fItems[i].revents = 0;
int type = 0; int type = 0;
size_t size = sizeof(type); size_t size = sizeof(type);
zmq_getsockopt(channels.at(i)->GetSocket().GetSocket(), ZMQ_TYPE, &type, &size); zmq_getsockopt(static_cast<const Socket*>(&(channels.at(i)->GetSocket()))->GetSocket(), ZMQ_TYPE, &type, &size);
SetItemEvents(fItems[i], type); SetItemEvents(fItems[i], type);
} }
@@ -75,13 +76,13 @@ Poller::Poller(const unordered_map<string, vector<FairMQChannel>>& channelsMap,
for (unsigned int i = 0; i < channelsMap.at(channel).size(); ++i) { for (unsigned int i = 0; i < channelsMap.at(channel).size(); ++i) {
index = fOffsetMap[channel] + i; index = fOffsetMap[channel] + i;
fItems[index].socket = channelsMap.at(channel).at(i).GetSocket().GetSocket(); fItems[index].socket = static_cast<const Socket*>(&(channelsMap.at(channel).at(i).GetSocket()))->GetSocket();
fItems[index].fd = 0; fItems[index].fd = 0;
fItems[index].revents = 0; fItems[index].revents = 0;
int type = 0; int type = 0;
size_t size = sizeof(type); size_t size = sizeof(type);
zmq_getsockopt(channelsMap.at(channel).at(i).GetSocket().GetSocket(), ZMQ_TYPE, &type, &size); zmq_getsockopt(static_cast<const Socket*>(&(channelsMap.at(channel).at(i).GetSocket()))->GetSocket(), ZMQ_TYPE, &type, &size);
SetItemEvents(fItems[index], type); SetItemEvents(fItems[index], type);
} }
@@ -93,27 +94,6 @@ Poller::Poller(const unordered_map<string, vector<FairMQChannel>>& channelsMap,
} }
} }
Poller::Poller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket)
: fNumItems{2}
{
fItems = new zmq_pollitem_t[fNumItems];
fItems[0].socket = cmdSocket.GetSocket();
fItems[0].fd = 0;
fItems[0].events = ZMQ_POLLIN;
fItems[0].revents = 0;
fItems[1].socket = dataSocket.GetSocket();
fItems[1].fd = 0;
fItems[1].revents = 0;
int type = 0;
size_t size = sizeof(type);
zmq_getsockopt(dataSocket.GetSocket(), ZMQ_TYPE, &type, &size);
SetItemEvents(fItems[1], type);
}
auto Poller::SetItemEvents(zmq_pollitem_t& item, const int type) -> void auto Poller::SetItemEvents(zmq_pollitem_t& item, const int type) -> void
{ {
if (type == ZMQ_PAIR) { if (type == ZMQ_PAIR) {

View File

@@ -33,7 +33,7 @@ class TransportFactory;
* *
* @todo TODO insert long description * @todo TODO insert long description
*/ */
class Poller : public FairMQPoller class Poller final : public FairMQPoller
{ {
friend class FairMQChannel; friend class FairMQChannel;
friend class TransportFactory; friend class TransportFactory;
@@ -57,8 +57,6 @@ class Poller : public FairMQPoller
~Poller() override; ~Poller() override;
private: private:
Poller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket);
zmq_pollitem_t* fItems; zmq_pollitem_t* fItems;
int fNumItems; int fNumItems;

View File

@@ -31,8 +31,9 @@ namespace ofi
using namespace std; using namespace std;
Socket::Socket(Context& context, const string& type, const string& name, const string& id /*= ""*/) Socket::Socket(Context& context, const string& type, const string& name, const string& id /*= ""*/, FairMQTransportFactory* fac)
: fDataEndpoint(nullptr) : FairMQSocket{fac}
, fDataEndpoint(nullptr)
, fDataCompletionQueueTx(nullptr) , fDataCompletionQueueTx(nullptr)
, fDataCompletionQueueRx(nullptr) , fDataCompletionQueueRx(nullptr)
, fId(id + "." + name + "." + type) , fId(id + "." + name + "." + type)
@@ -107,13 +108,14 @@ catch (const SocketError& e)
return false; return false;
} }
auto Socket::Connect(const string& address) -> void auto Socket::Connect(const string& address) -> bool
{ {
auto addr = Context::VerifyAddress(address); auto addr = Context::VerifyAddress(address);
ConnectControlSocket(addr); ConnectControlSocket(addr);
fContext.InitOfi(ConnectionType::Connect, addr); fContext.InitOfi(ConnectionType::Connect, addr);
InitDataEndpoint(); InitDataEndpoint();
fWaitingForControlPeer = true; fWaitingForControlPeer = true;
return true;
} }
auto Socket::BindControlSocket(Context::Address address) -> void auto Socket::BindControlSocket(Context::Address address) -> void
@@ -514,7 +516,7 @@ auto Socket::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int flags, cons
// //
// do // do
// { // {
// FairMQMessagePtr part(new FairMQMessageSHM(fManager)); // FairMQMessagePtr part(new FairMQMessageSHM(fManager, GetTransport()));
// zmq_msg_t* msgPtr = static_cast<FairMQMessageSHM*>(part.get())->GetMessage(); // zmq_msg_t* msgPtr = static_cast<FairMQMessageSHM*>(part.get())->GetMessage();
// //
// int nbytes = zmq_msg_recv(msgPtr, fSocket, flags); // int nbytes = zmq_msg_recv(msgPtr, fSocket, flags);
@@ -619,114 +621,82 @@ auto Socket::GetOption(const string& option, void* value, size_t* valueSize) ->
} }
} }
auto Socket::SetSendTimeout(const int timeout, const string& address, const string& method) -> bool int Socket::GetLinger() const
{ {
throw SocketError{"Not yet implemented."}; int value = 0;
// fSndTimeout = timeout; size_t valueSize;
// if (method == "bind") if (zmq_getsockopt(fControlSocket, ZMQ_LINGER, &value, &valueSize) < 0) {
// { throw SocketError(tools::ToString("failed getting ZMQ_LINGER, reason: ", zmq_strerror(errno)));
// if (zmq_unbind(fSocket, address.c_str()) != 0) }
// { return value;
// LOG(error) << "Failed unbinding socket " << fId << ", reason: " << zmq_strerror(errno);
// return false;
// }
// if (zmq_setsockopt(fSocket, ZMQ_SNDTIMEO, &fSndTimeout, sizeof(fSndTimeout)) != 0)
// {
// LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
// return false;
// }
// if (zmq_bind(fSocket, address.c_str()) != 0)
// {
// LOG(error) << "Failed binding socket " << fId << ", reason: " << zmq_strerror(errno);
// return false;
// }
// }
// else if (method == "connect")
// {
// if (zmq_disconnect(fSocket, address.c_str()) != 0)
// {
// LOG(error) << "Failed disconnecting socket " << fId << ", reason: " << zmq_strerror(errno);
// return false;
// }
// if (zmq_setsockopt(fSocket, ZMQ_SNDTIMEO, &fSndTimeout, sizeof(fSndTimeout)) != 0)
// {
// LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
// return false;
// }
// if (zmq_connect(fSocket, address.c_str()) != 0)
// {
// LOG(error) << "Failed connecting socket " << fId << ", reason: " << zmq_strerror(errno);
// return false;
// }
// }
// else
// {
// LOG(error) << "timeout failed - unknown method provided!";
// return false;
// }
//
// return true;
} }
auto Socket::GetSendTimeout() const -> int void Socket::SetSndBufSize(const int value)
{ {
throw SocketError{"Not yet implemented."}; if (zmq_setsockopt(fControlSocket, ZMQ_SNDHWM, &value, sizeof(value)) < 0) {
// return fSndTimeout; throw SocketError(tools::ToString("failed setting ZMQ_SNDHWM, reason: ", zmq_strerror(errno)));
}
} }
auto Socket::SetReceiveTimeout(const int timeout, const string& address, const string& method) -> bool int Socket::GetSndBufSize() const
{ {
throw SocketError{"Not yet implemented."}; int value = 0;
// fRcvTimeout = timeout; size_t valueSize;
// if (method == "bind") if (zmq_getsockopt(fControlSocket, ZMQ_SNDHWM, &value, &valueSize) < 0) {
// { throw SocketError(tools::ToString("failed getting ZMQ_SNDHWM, reason: ", zmq_strerror(errno)));
// if (zmq_unbind(fSocket, address.c_str()) != 0) }
// { return value;
// LOG(error) << "Failed unbinding socket " << fId << ", reason: " << zmq_strerror(errno);
// return false;
// }
// if (zmq_setsockopt(fSocket, ZMQ_RCVTIMEO, &fRcvTimeout, sizeof(fRcvTimeout)) != 0)
// {
// LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
// return false;
// }
// if (zmq_bind(fSocket, address.c_str()) != 0)
// {
// LOG(error) << "Failed binding socket " << fId << ", reason: " << zmq_strerror(errno);
// return false;
// }
// }
// else if (method == "connect")
// {
// if (zmq_disconnect(fSocket, address.c_str()) != 0)
// {
// LOG(error) << "Failed disconnecting socket " << fId << ", reason: " << zmq_strerror(errno);
// return false;
// }
// if (zmq_setsockopt(fSocket, ZMQ_RCVTIMEO, &fRcvTimeout, sizeof(fRcvTimeout)) != 0)
// {
// LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
// return false;
// }
// if (zmq_connect(fSocket, address.c_str()) != 0)
// {
// LOG(error) << "Failed connecting socket " << fId << ", reason: " << zmq_strerror(errno);
// return false;
// }
// }
// else
// {
// LOG(error) << "timeout failed - unknown method provided!";
// return false;
// }
//
// return true;
} }
auto Socket::GetReceiveTimeout() const -> int void Socket::SetRcvBufSize(const int value)
{ {
throw SocketError{"Not yet implemented."}; if (zmq_setsockopt(fControlSocket, ZMQ_RCVHWM, &value, sizeof(value)) < 0) {
// return fRcvTimeout; throw SocketError(tools::ToString("failed setting ZMQ_RCVHWM, reason: ", zmq_strerror(errno)));
}
}
int Socket::GetRcvBufSize() const
{
int value = 0;
size_t valueSize;
if (zmq_getsockopt(fControlSocket, ZMQ_RCVHWM, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_RCVHWM, reason: ", zmq_strerror(errno)));
}
return value;
}
void Socket::SetSndKernelSize(const int value)
{
if (zmq_setsockopt(fControlSocket, ZMQ_SNDBUF, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_SNDBUF, reason: ", zmq_strerror(errno)));
}
}
int Socket::GetSndKernelSize() const
{
int value = 0;
size_t valueSize;
if (zmq_getsockopt(fControlSocket, ZMQ_SNDBUF, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_SNDBUF, reason: ", zmq_strerror(errno)));
}
return value;
}
void Socket::SetRcvKernelSize(const int value)
{
if (zmq_setsockopt(fControlSocket, ZMQ_RCVBUF, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_RCVBUF, reason: ", zmq_strerror(errno)));
}
}
int Socket::GetRcvKernelSize() const
{
int value = 0;
size_t valueSize;
if (zmq_getsockopt(fControlSocket, ZMQ_RCVBUF, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_RCVBUF, reason: ", zmq_strerror(errno)));
}
return value;
} }
auto Socket::GetConstant(const string& constant) -> int auto Socket::GetConstant(const string& constant) -> int

View File

@@ -18,6 +18,7 @@
#include <memory> // unique_ptr #include <memory> // unique_ptr
#include <netinet/in.h> #include <netinet/in.h>
#include <rdma/fabric.h> #include <rdma/fabric.h>
class FairMQTransportFactory;
namespace fair namespace fair
{ {
@@ -32,17 +33,17 @@ namespace ofi
* *
* @todo TODO insert long description * @todo TODO insert long description
*/ */
class Socket : public fair::mq::Socket class Socket final : public fair::mq::Socket
{ {
public: public:
Socket(Context& factory, const std::string& type, const std::string& name, const std::string& id = ""); Socket(Context& factory, const std::string& type, const std::string& name, const std::string& id = "", FairMQTransportFactory* fac);
Socket(const Socket&) = delete; Socket(const Socket&) = delete;
Socket operator=(const Socket&) = delete; Socket operator=(const Socket&) = delete;
auto GetId() -> std::string { return fId; } auto GetId() -> std::string { return fId; }
auto Bind(const std::string& address) -> bool override; auto Bind(const std::string& address) -> bool override;
auto Connect(const std::string& address) -> void override; auto Connect(const std::string& address) -> bool override;
auto Send(MessagePtr& msg, int timeout = 0) -> int override; auto Send(MessagePtr& msg, int timeout = 0) -> int override;
auto Receive(MessagePtr& msg, int timeout = 0) -> int override; auto Receive(MessagePtr& msg, int timeout = 0) -> int override;
@@ -54,8 +55,18 @@ class Socket : public fair::mq::Socket
auto TrySend(std::vector<MessagePtr>& msgVec) -> int64_t override; auto TrySend(std::vector<MessagePtr>& msgVec) -> int64_t override;
auto TryReceive(std::vector<MessagePtr>& msgVec) -> int64_t override; auto TryReceive(std::vector<MessagePtr>& msgVec) -> int64_t override;
auto GetSocket() const -> void* override { return fControlSocket; } auto GetSocket() const -> void* { return fControlSocket; }
auto GetSocket(int nothing) const -> int override { return -1; }
void SetLinger(const int value) override;
int GetLinger() const override;
void SetSndBufSize(const int value) override;
int GetSndBufSize() const override;
void SetRcvBufSize(const int value) override;
int GetRcvBufSize() const override;
void SetSndKernelSize(const int value) override;
int GetSndKernelSize() const override;
void SetRcvKernelSize(const int value) override;
int GetRcvKernelSize() const override;
auto Close() -> void override; auto Close() -> void override;
@@ -67,11 +78,6 @@ class Socket : public fair::mq::Socket
auto GetMessagesTx() const -> unsigned long override { return fMessagesTx; } auto GetMessagesTx() const -> unsigned long override { return fMessagesTx; }
auto GetMessagesRx() const -> unsigned long override { return fMessagesRx; } auto GetMessagesRx() const -> unsigned long override { return fMessagesRx; }
auto SetSendTimeout(const int timeout, const std::string& address, const std::string& method) -> bool override;
auto GetSendTimeout() const -> int override;
auto SetReceiveTimeout(const int timeout, const std::string& address, const std::string& method) -> bool override;
auto GetReceiveTimeout() const -> int override;
static auto GetConstant(const std::string& constant) -> int; static auto GetConstant(const std::string& constant) -> int;
~Socket() override; ~Socket() override;

View File

@@ -56,9 +56,9 @@ auto TransportFactory::CreateMessage(UnmanagedRegionPtr& region, void* data, con
return MessagePtr{new Message(region, data, size, hint)}; return MessagePtr{new Message(region, data, size, hint)};
} }
auto TransportFactory::CreateSocket(const string& type, const string& name) const -> SocketPtr auto TransportFactory::CreateSocket(const string& type, const string& name) -> SocketPtr
{ {
return SocketPtr{new Socket(fContext, type, name, GetId())}; return SocketPtr{new Socket(fContext, type, name, GetId(), this)};
} }
auto TransportFactory::CreatePoller(const vector<FairMQChannel>& channels) const -> PollerPtr auto TransportFactory::CreatePoller(const vector<FairMQChannel>& channels) const -> PollerPtr
@@ -76,11 +76,6 @@ auto TransportFactory::CreatePoller(const unordered_map<string, vector<FairMQCha
return PollerPtr{new Poller(channelsMap, channelList)}; return PollerPtr{new Poller(channelsMap, channelList)};
} }
auto TransportFactory::CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const -> PollerPtr
{
return PollerPtr{new Poller(cmdSocket, dataSocket)};
}
auto TransportFactory::CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const -> UnmanagedRegionPtr auto TransportFactory::CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const -> UnmanagedRegionPtr
{ {
throw runtime_error{"Not yet implemented UMR."}; throw runtime_error{"Not yet implemented UMR."};

View File

@@ -26,7 +26,7 @@ namespace ofi
* *
* @todo TODO insert long description * @todo TODO insert long description
*/ */
class TransportFactory : public FairMQTransportFactory class TransportFactory final : public FairMQTransportFactory
{ {
public: public:
TransportFactory(const std::string& id = "", const FairMQProgOptions* config = nullptr); TransportFactory(const std::string& id = "", const FairMQProgOptions* config = nullptr);
@@ -38,12 +38,11 @@ class TransportFactory : public FairMQTransportFactory
auto CreateMessage(void* data, const std::size_t size, fairmq_free_fn* ffn, void* hint = nullptr) const -> MessagePtr override; auto CreateMessage(void* data, const std::size_t size, fairmq_free_fn* ffn, void* hint = nullptr) const -> MessagePtr override;
auto CreateMessage(UnmanagedRegionPtr& region, void* data, const std::size_t size, void* hint = nullptr) const -> MessagePtr override; auto CreateMessage(UnmanagedRegionPtr& region, void* data, const std::size_t size, void* hint = nullptr) const -> MessagePtr override;
auto CreateSocket(const std::string& type, const std::string& name) const -> SocketPtr override; auto CreateSocket(const std::string& type, const std::string& name) -> SocketPtr override;
auto CreatePoller(const std::vector<FairMQChannel>& channels) const -> PollerPtr override; auto CreatePoller(const std::vector<FairMQChannel>& channels) const -> PollerPtr override;
auto CreatePoller(const std::vector<const FairMQChannel*>& channels) const -> PollerPtr override; auto CreatePoller(const std::vector<const FairMQChannel*>& channels) const -> PollerPtr override;
auto CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const -> PollerPtr override; auto CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const -> PollerPtr override;
auto CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const -> PollerPtr override;
auto CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback = nullptr) const -> UnmanagedRegionPtr override; auto CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback = nullptr) const -> UnmanagedRegionPtr override;
@@ -51,6 +50,7 @@ class TransportFactory : public FairMQTransportFactory
void Interrupt() override {} void Interrupt() override {}
void Resume() override {} void Resume() override {}
void Reset() override {}
private: private:
mutable Context fContext; mutable Context fContext;

View File

@@ -32,8 +32,7 @@ namespace parser
// function that convert property tree (given the json structure) to FairMQChannelMap // function that convert property tree (given the json structure) to FairMQChannelMap
FairMQChannelMap ptreeToMQMap(const boost::property_tree::ptree& pt, const string& id, const string& rootNode) FairMQChannelMap ptreeToMQMap(const boost::property_tree::ptree& pt, const string& id, const string& rootNode)
{ {
if (id == "") if (id == "") {
{
throw ParserError("no device ID provided. Provide with `--id` cmd option"); throw ParserError("no device ID provided. Provide with `--id` cmd option");
} }
@@ -44,8 +43,7 @@ FairMQChannelMap ptreeToMQMap(const boost::property_tree::ptree& pt, const strin
// Extract value from boost::property_tree // Extract value from boost::property_tree
Helper::DeviceParser(pt.get_child(rootNode), channelMap, id); Helper::DeviceParser(pt.get_child(rootNode), channelMap, id);
if (channelMap.empty()) if (channelMap.empty()) {
{
LOG(warn) << "---- No channel keys found for " << id; LOG(warn) << "---- No channel keys found for " << id;
LOG(warn) << "---- Check the JSON inputs and/or command line inputs"; LOG(warn) << "---- Check the JSON inputs and/or command line inputs";
} }
@@ -68,20 +66,14 @@ void PrintDeviceList(const boost::property_tree::ptree& tree)
string deviceIdKey; string deviceIdKey;
// do a first loop just to print the device-id in json input // do a first loop just to print the device-id in json input
for (const auto& p : tree) for (const auto& p : tree) {
{ if (p.first == "devices") {
if (p.first == "devices") for (const auto& q : p.second.get_child("")) {
{
for (const auto& q : p.second.get_child(""))
{
string key = q.second.get<string>("key", ""); string key = q.second.get<string>("key", "");
if (key != "") if (key != "") {
{
deviceIdKey = key; deviceIdKey = key;
LOG(debug) << "Found config for device key '" << deviceIdKey << "' in JSON input"; LOG(debug) << "Found config for device key '" << deviceIdKey << "' in JSON input";
} } else {
else
{
deviceIdKey = q.second.get<string>("id"); deviceIdKey = q.second.get<string>("id");
LOG(debug) << "Found config for device id '" << deviceIdKey << "' in JSON input"; LOG(debug) << "Found config for device id '" << deviceIdKey << "' in JSON input";
} }
@@ -95,33 +87,26 @@ void DeviceParser(const boost::property_tree::ptree& tree, FairMQChannelMap& cha
string deviceIdKey; string deviceIdKey;
// For each node in fairMQOptions // For each node in fairMQOptions
for (const auto& p : tree) for (const auto& p : tree) {
{ if (p.first == "devices") {
if (p.first == "devices") for (const auto& q : p.second) {
{
for (const auto& q : p.second)
{
// check if key is provided, otherwise use id // check if key is provided, otherwise use id
string key = q.second.get<string>("key", ""); string key = q.second.get<string>("key", "");
if (key != "") if (key != "") {
{
deviceIdKey = key; deviceIdKey = key;
// LOG(debug) << "Found config for device key '" << deviceIdKey << "' in JSON input"; // LOG(trace) << "Found config for device key '" << deviceIdKey << "' in JSON input";
} } else {
else
{
deviceIdKey = q.second.get<string>("id"); deviceIdKey = q.second.get<string>("id");
// LOG(debug) << "Found config for device id '" << deviceIdKey << "' in JSON input"; // LOG(trace) << "Found config for device id '" << deviceIdKey << "' in JSON input";
} }
// if not correct device id, do not fill MQMap // if not correct device id, do not fill MQMap
if (deviceId != deviceIdKey) if (deviceId != deviceIdKey) {
{
continue; continue;
} }
LOG(debug) << "Found following channels for device ID '" << deviceId << "' :"; LOG(trace) << "Found following channels for device ID '" << deviceId << "' :";
ChannelParser(q.second, channelMap); ChannelParser(q.second, channelMap);
} }
@@ -133,12 +118,9 @@ void ChannelParser(const boost::property_tree::ptree& tree, FairMQChannelMap& ch
{ {
string channelKey; string channelKey;
for (const auto& p : tree) for (const auto& p : tree) {
{ if (p.first == "channels") {
if (p.first == "channels") for (const auto& q : p.second) {
{
for (const auto& q : p.second)
{
channelKey = q.second.get<string>("name"); channelKey = q.second.get<string>("name");
int numSockets = q.second.get<int>("numSockets", 0); int numSockets = q.second.get<int>("numSockets", 0);
@@ -153,35 +135,39 @@ void ChannelParser(const boost::property_tree::ptree& tree, FairMQChannelMap& ch
commonChannel.UpdateRcvBufSize(q.second.get<int>("rcvBufSize", commonChannel.GetRcvBufSize())); commonChannel.UpdateRcvBufSize(q.second.get<int>("rcvBufSize", commonChannel.GetRcvBufSize()));
commonChannel.UpdateSndKernelSize(q.second.get<int>("sndKernelSize", commonChannel.GetSndKernelSize())); commonChannel.UpdateSndKernelSize(q.second.get<int>("sndKernelSize", commonChannel.GetSndKernelSize()));
commonChannel.UpdateRcvKernelSize(q.second.get<int>("rcvKernelSize", commonChannel.GetRcvKernelSize())); commonChannel.UpdateRcvKernelSize(q.second.get<int>("rcvKernelSize", commonChannel.GetRcvKernelSize()));
commonChannel.UpdateLinger(q.second.get<int>("linger", commonChannel.GetLinger()));
commonChannel.UpdateRateLogging(q.second.get<int>("rateLogging", commonChannel.GetRateLogging())); commonChannel.UpdateRateLogging(q.second.get<int>("rateLogging", commonChannel.GetRateLogging()));
commonChannel.UpdatePortRangeMin(q.second.get<int>("portRangeMin", commonChannel.GetPortRangeMin()));
commonChannel.UpdatePortRangeMax(q.second.get<int>("portRangeMax", commonChannel.GetPortRangeMax()));
commonChannel.UpdateAutoBind(q.second.get<bool>("autoBind", commonChannel.GetAutoBind()));
// temporary FairMQChannel container // temporary FairMQChannel container
vector<FairMQChannel> channelList; vector<FairMQChannel> channelList;
if (numSockets > 0) if (numSockets > 0) {
{ LOG(trace) << "" << channelKey << ":";
LOG(debug) << "" << channelKey << ":"; LOG(trace) << "\tnumSockets of " << numSockets << " specified,";
LOG(debug) << "\tnumSockets of " << numSockets << " specified,"; LOG(trace) << "\tapplying common settings to each:";
LOG(debug) << "\tapplying common settings to each:";
LOG(debug) << "\ttype = " << commonChannel.GetType(); LOG(trace) << "\ttype = " << commonChannel.GetType();
LOG(debug) << "\tmethod = " << commonChannel.GetMethod(); LOG(trace) << "\tmethod = " << commonChannel.GetMethod();
LOG(debug) << "\taddress = " << commonChannel.GetAddress(); LOG(trace) << "\taddress = " << commonChannel.GetAddress();
LOG(debug) << "\ttransport = " << commonChannel.GetTransportName(); LOG(trace) << "\ttransport = " << commonChannel.GetTransportName();
LOG(debug) << "\tsndBufSize = " << commonChannel.GetSndBufSize(); LOG(trace) << "\tsndBufSize = " << commonChannel.GetSndBufSize();
LOG(debug) << "\trcvBufSize = " << commonChannel.GetRcvBufSize(); LOG(trace) << "\trcvBufSize = " << commonChannel.GetRcvBufSize();
LOG(debug) << "\tsndKernelSize = " << commonChannel.GetSndKernelSize(); LOG(trace) << "\tsndKernelSize = " << commonChannel.GetSndKernelSize();
LOG(debug) << "\trcvKernelSize = " << commonChannel.GetRcvKernelSize(); LOG(trace) << "\trcvKernelSize = " << commonChannel.GetRcvKernelSize();
LOG(debug) << "\trateLogging = " << commonChannel.GetRateLogging(); LOG(trace) << "\tlinger = " << commonChannel.GetLinger();
LOG(trace) << "\trateLogging = " << commonChannel.GetRateLogging();
LOG(trace) << "\tportRangeMin = " << commonChannel.GetPortRangeMin();
LOG(trace) << "\tportRangeMax = " << commonChannel.GetPortRangeMax();
LOG(trace) << "\tautoBind = " << commonChannel.GetAutoBind();
for (int i = 0; i < numSockets; ++i) for (int i = 0; i < numSockets; ++i) {
{
FairMQChannel channel(commonChannel); FairMQChannel channel(commonChannel);
channelList.push_back(channel); channelList.push_back(channel);
} }
} } else {
else
{
SocketParser(q.second.get_child(""), channelList, channelKey, commonChannel); SocketParser(q.second.get_child(""), channelList, channelKey, commonChannel);
} }
@@ -196,12 +182,9 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
// for each socket in channel // for each socket in channel
int socketCounter = 0; int socketCounter = 0;
for (const auto& p : tree) for (const auto& p : tree) {
{ if (p.first == "sockets") {
if (p.first == "sockets") for (const auto& q : p.second) {
{
for (const auto& q : p.second)
{
// create new channel and apply setting from the common channel // create new channel and apply setting from the common channel
FairMQChannel channel(commonChannel); FairMQChannel channel(commonChannel);
@@ -214,18 +197,26 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
channel.UpdateRcvBufSize(q.second.get<int>("rcvBufSize", channel.GetRcvBufSize())); channel.UpdateRcvBufSize(q.second.get<int>("rcvBufSize", channel.GetRcvBufSize()));
channel.UpdateSndKernelSize(q.second.get<int>("sndKernelSize", channel.GetSndKernelSize())); channel.UpdateSndKernelSize(q.second.get<int>("sndKernelSize", channel.GetSndKernelSize()));
channel.UpdateRcvKernelSize(q.second.get<int>("rcvKernelSize", channel.GetRcvKernelSize())); channel.UpdateRcvKernelSize(q.second.get<int>("rcvKernelSize", channel.GetRcvKernelSize()));
channel.UpdateLinger(q.second.get<int>("linger", channel.GetLinger()));
channel.UpdateRateLogging(q.second.get<int>("rateLogging", channel.GetRateLogging())); channel.UpdateRateLogging(q.second.get<int>("rateLogging", channel.GetRateLogging()));
channel.UpdatePortRangeMin(q.second.get<int>("portRangeMin", channel.GetPortRangeMin()));
channel.UpdatePortRangeMax(q.second.get<int>("portRangeMax", channel.GetPortRangeMax()));
channel.UpdateAutoBind(q.second.get<bool>("autoBind", channel.GetAutoBind()));
LOG(debug) << "" << channelName << "[" << socketCounter << "]:"; LOG(trace) << "" << channelName << "[" << socketCounter << "]:";
LOG(debug) << "\ttype = " << channel.GetType(); LOG(trace) << "\ttype = " << channel.GetType();
LOG(debug) << "\tmethod = " << channel.GetMethod(); LOG(trace) << "\tmethod = " << channel.GetMethod();
LOG(debug) << "\taddress = " << channel.GetAddress(); LOG(trace) << "\taddress = " << channel.GetAddress();
LOG(debug) << "\ttransport = " << channel.GetTransportName(); LOG(trace) << "\ttransport = " << channel.GetTransportName();
LOG(debug) << "\tsndBufSize = " << channel.GetSndBufSize(); LOG(trace) << "\tsndBufSize = " << channel.GetSndBufSize();
LOG(debug) << "\trcvBufSize = " << channel.GetRcvBufSize(); LOG(trace) << "\trcvBufSize = " << channel.GetRcvBufSize();
LOG(debug) << "\tsndKernelSize = " << channel.GetSndKernelSize(); LOG(trace) << "\tsndKernelSize = " << channel.GetSndKernelSize();
LOG(debug) << "\trcvKernelSize = " << channel.GetRcvKernelSize(); LOG(trace) << "\trcvKernelSize = " << channel.GetRcvKernelSize();
LOG(debug) << "\trateLogging = " << channel.GetRateLogging(); LOG(trace) << "\tlinger = " << channel.GetLinger();
LOG(trace) << "\trateLogging = " << channel.GetRateLogging();
LOG(trace) << "\tportRangeMin = " << channel.GetPortRangeMin();
LOG(trace) << "\tportRangeMax = " << channel.GetPortRangeMax();
LOG(trace) << "\tautoBind = " << channel.GetAutoBind();
channelList.push_back(channel); channelList.push_back(channel);
++socketCounter; ++socketCounter;
@@ -233,27 +224,28 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
} }
} // end socket loop } // end socket loop
if (socketCounter) if (socketCounter) {
{ LOG(trace) << "Found " << socketCounter << " socket(s) in channel.";
LOG(debug) << "Found " << socketCounter << " socket(s) in channel."; } else {
} LOG(trace) << "" << channelName << ":";
else LOG(trace) << "\tNo sockets specified,";
{ LOG(trace) << "\tapplying common settings to the channel:";
LOG(debug) << "" << channelName << ":";
LOG(debug) << "\tNo sockets specified,";
LOG(debug) << "\tapplying common settings to the channel:";
FairMQChannel channel(commonChannel); FairMQChannel channel(commonChannel);
LOG(debug) << "\ttype = " << channel.GetType(); LOG(trace) << "\ttype = " << channel.GetType();
LOG(debug) << "\tmethod = " << channel.GetMethod(); LOG(trace) << "\tmethod = " << channel.GetMethod();
LOG(debug) << "\taddress = " << channel.GetAddress(); LOG(trace) << "\taddress = " << channel.GetAddress();
LOG(debug) << "\ttransport = " << channel.GetTransportName(); LOG(trace) << "\ttransport = " << channel.GetTransportName();
LOG(debug) << "\tsndBufSize = " << channel.GetSndBufSize(); LOG(trace) << "\tsndBufSize = " << channel.GetSndBufSize();
LOG(debug) << "\trcvBufSize = " << channel.GetRcvBufSize(); LOG(trace) << "\trcvBufSize = " << channel.GetRcvBufSize();
LOG(debug) << "\tsndKernelSize = " << channel.GetSndKernelSize(); LOG(trace) << "\tsndKernelSize = " << channel.GetSndKernelSize();
LOG(debug) << "\trcvKernelSize = " << channel.GetRcvKernelSize(); LOG(trace) << "\trcvKernelSize = " << channel.GetRcvKernelSize();
LOG(debug) << "\trateLogging = " << channel.GetRateLogging(); LOG(trace) << "\tlinger = " << channel.GetLinger();
LOG(trace) << "\trateLogging = " << channel.GetRateLogging();
LOG(trace) << "\tportRangeMin = " << channel.GetPortRangeMin();
LOG(trace) << "\tportRangeMax = " << channel.GetPortRangeMax();
LOG(trace) << "\tautoBind = " << channel.GetAutoBind();
channelList.push_back(channel); channelList.push_back(channel);
} }

View File

@@ -19,10 +19,9 @@
#include "FairMQParser.h" #include "FairMQParser.h"
#include "FairMQSuboptParser.h" #include "FairMQSuboptParser.h"
#include "tools/Unique.h"
#include <boost/algorithm/string.hpp> // join/split #include <boost/algorithm/string.hpp> // join/split
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <algorithm> #include <algorithm>
#include <iomanip> #include <iomanip>
@@ -63,8 +62,6 @@ FairMQProgOptions::FairMQProgOptions()
("network-interface", po::value<string>()->default_value("default"), "Network interface to bind on (e.g. eth0, ib0..., default will try to detect the interface of the default route).") ("network-interface", po::value<string>()->default_value("default"), "Network interface to bind on (e.g. eth0, ib0..., default will try to detect the interface of the default route).")
("config-key", po::value<string>(), "Use provided value instead of device id for fetching the configuration from the config file.") ("config-key", po::value<string>(), "Use provided value instead of device id for fetching the configuration from the config file.")
("initialization-timeout", po::value<int >()->default_value(120), "Timeout for the initialization in seconds (when expecting dynamic initialization).") ("initialization-timeout", po::value<int >()->default_value(120), "Timeout for the initialization in seconds (when expecting dynamic initialization).")
("port-range-min", po::value<int >()->default_value(22000), "Start of the port range for dynamic initialization.")
("port-range-max", po::value<int >()->default_value(32000), "End of the port range for dynamic initialization.")
("print-channels", po::value<bool >()->implicit_value(true), "Print registered channel endpoints in a machine-readable format (<channel name>:<min num subchannels>:<max num subchannels>)") ("print-channels", po::value<bool >()->implicit_value(true), "Print registered channel endpoints in a machine-readable format (<channel name>:<min num subchannels>:<max num subchannels>)")
("shm-segment-size", po::value<size_t>()->default_value(2000000000), "Shared memory: size of the shared memory segment (in bytes).") ("shm-segment-size", po::value<size_t>()->default_value(2000000000), "Shared memory: size of the shared memory segment (in bytes).")
("shm-monitor", po::value<bool >()->default_value(true), "Shared memory: run monitor daemon.") ("shm-monitor", po::value<bool >()->default_value(true), "Shared memory: run monitor daemon.")
@@ -162,7 +159,7 @@ int FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool al
else if (fVarMap.count("channel-config")) else if (fVarMap.count("channel-config"))
{ {
LOG(debug) << "channel-config: Parsing channel configuration"; LOG(debug) << "channel-config: Parsing channel configuration";
UpdateChannelMap(parser::SUBOPT().UserParser(fVarMap.at("channel-config").as<vector<string>>(), idForParser)); ParseChannelsFromCmdLine();
} }
else else
{ {
@@ -171,7 +168,6 @@ int FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool al
{ {
LOG(warn) << "--" << p->canonical_display_name(); LOG(warn) << "--" << p->canonical_display_name();
} }
LOG(warn) << "No channels will be created (You can create them manually).";
} }
} }
catch (exception& e) catch (exception& e)
@@ -185,6 +181,23 @@ int FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool al
return 0; return 0;
} }
void FairMQProgOptions::ParseChannelsFromCmdLine()
{
string idForParser;
// check if config-key for config parser is provided
if (fVarMap.count("config-key"))
{
idForParser = fVarMap["config-key"].as<string>();
}
else if (fVarMap.count("id"))
{
idForParser = fVarMap["id"].as<string>();
}
UpdateChannelMap(parser::SUBOPT().UserParser(fVarMap.at("channel-config").as<vector<string>>(), idForParser));
}
void FairMQProgOptions::ParseCmdLine(const int argc, char const* const* argv, bool allowUnregistered) void FairMQProgOptions::ParseCmdLine(const int argc, char const* const* argv, bool allowUnregistered)
{ {
fVarMap.clear(); fVarMap.clear();
@@ -210,7 +223,7 @@ void FairMQProgOptions::ParseCmdLine(const int argc, char const* const* argv, bo
void FairMQProgOptions::ParseDefaults() void FairMQProgOptions::ParseDefaults()
{ {
vector<string> emptyArgs = {"dummy", "--id", boost::uuids::to_string(boost::uuids::random_generator()())}; vector<string> emptyArgs = {"dummy", "--id", tools::Uuid()};
vector<const char*> argv(emptyArgs.size()); vector<const char*> argv(emptyArgs.size());
@@ -254,12 +267,10 @@ void FairMQProgOptions::UpdateChannelInfo()
// create key for variable map as follow : channelName.index.memberName // create key for variable map as follow : channelName.index.memberName
void FairMQProgOptions::UpdateMQValues() void FairMQProgOptions::UpdateMQValues()
{ {
for (const auto& p : fFairMQChannelMap) for (const auto& p : fFairMQChannelMap) {
{
int index = 0; int index = 0;
for (const auto& channel : p.second) for (const auto& channel : p.second) {
{
string typeKey = "chans." + p.first + "." + to_string(index) + ".type"; string typeKey = "chans." + p.first + "." + to_string(index) + ".type";
string methodKey = "chans." + p.first + "." + to_string(index) + ".method"; string methodKey = "chans." + p.first + "." + to_string(index) + ".method";
string addressKey = "chans." + p.first + "." + to_string(index) + ".address"; string addressKey = "chans." + p.first + "." + to_string(index) + ".address";
@@ -268,7 +279,11 @@ void FairMQProgOptions::UpdateMQValues()
string rcvBufSizeKey = "chans." + p.first + "." + to_string(index) + ".rcvBufSize"; string rcvBufSizeKey = "chans." + p.first + "." + to_string(index) + ".rcvBufSize";
string sndKernelSizeKey = "chans." + p.first + "." + to_string(index) + ".sndKernelSize"; string sndKernelSizeKey = "chans." + p.first + "." + to_string(index) + ".sndKernelSize";
string rcvKernelSizeKey = "chans." + p.first + "." + to_string(index) + ".rcvKernelSize"; string rcvKernelSizeKey = "chans." + p.first + "." + to_string(index) + ".rcvKernelSize";
string lingerKey = "chans." + p.first + "." + to_string(index) + ".linger";
string rateLoggingKey = "chans." + p.first + "." + to_string(index) + ".rateLogging"; string rateLoggingKey = "chans." + p.first + "." + to_string(index) + ".rateLogging";
string portRangeMinKey = "chans." + p.first + "." + to_string(index) + ".portRangeMin";
string portRangeMaxKey = "chans." + p.first + "." + to_string(index) + ".portRangeMax";
string autoBindKey = "chans." + p.first + "." + to_string(index) + ".autoBind";
fChannelKeyMap[typeKey] = ChannelKey{p.first, index, "type"}; fChannelKeyMap[typeKey] = ChannelKey{p.first, index, "type"};
fChannelKeyMap[methodKey] = ChannelKey{p.first, index, "method"}; fChannelKeyMap[methodKey] = ChannelKey{p.first, index, "method"};
@@ -278,7 +293,11 @@ void FairMQProgOptions::UpdateMQValues()
fChannelKeyMap[rcvBufSizeKey] = ChannelKey{p.first, index, "rcvBufSize"}; fChannelKeyMap[rcvBufSizeKey] = ChannelKey{p.first, index, "rcvBufSize"};
fChannelKeyMap[sndKernelSizeKey] = ChannelKey{p.first, index, "sndKernelSize"}; fChannelKeyMap[sndKernelSizeKey] = ChannelKey{p.first, index, "sndKernelSize"};
fChannelKeyMap[rcvKernelSizeKey] = ChannelKey{p.first, index, "rcvkernelSize"}; fChannelKeyMap[rcvKernelSizeKey] = ChannelKey{p.first, index, "rcvkernelSize"};
fChannelKeyMap[lingerKey] = ChannelKey{p.first, index, "linger"};
fChannelKeyMap[rateLoggingKey] = ChannelKey{p.first, index, "rateLogging"}; fChannelKeyMap[rateLoggingKey] = ChannelKey{p.first, index, "rateLogging"};
fChannelKeyMap[portRangeMinKey] = ChannelKey{p.first, index, "portRangeMin"};
fChannelKeyMap[portRangeMaxKey] = ChannelKey{p.first, index, "portRangeMax"};
fChannelKeyMap[autoBindKey] = ChannelKey{p.first, index, "autoBind"};
UpdateVarMap<string>(typeKey, channel.GetType()); UpdateVarMap<string>(typeKey, channel.GetType());
UpdateVarMap<string>(methodKey, channel.GetMethod()); UpdateVarMap<string>(methodKey, channel.GetMethod());
@@ -288,69 +307,69 @@ void FairMQProgOptions::UpdateMQValues()
UpdateVarMap<int>(rcvBufSizeKey, channel.GetRcvBufSize()); UpdateVarMap<int>(rcvBufSizeKey, channel.GetRcvBufSize());
UpdateVarMap<int>(sndKernelSizeKey, channel.GetSndKernelSize()); UpdateVarMap<int>(sndKernelSizeKey, channel.GetSndKernelSize());
UpdateVarMap<int>(rcvKernelSizeKey, channel.GetRcvKernelSize()); UpdateVarMap<int>(rcvKernelSizeKey, channel.GetRcvKernelSize());
UpdateVarMap<int>(lingerKey, channel.GetLinger());
UpdateVarMap<int>(rateLoggingKey, channel.GetRateLogging()); UpdateVarMap<int>(rateLoggingKey, channel.GetRateLogging());
UpdateVarMap<int>(portRangeMinKey, channel.GetPortRangeMin());
UpdateVarMap<int>(portRangeMaxKey, channel.GetPortRangeMax());
UpdateVarMap<bool>(autoBindKey, channel.GetAutoBind());
index++; index++;
} }
UpdateVarMap<int>("chans." + p.first + ".numSockets", index); UpdateVarMap<int>("chans." + p.first + ".numSockets", index);
} }
} }
int FairMQProgOptions::UpdateChannelValue(const string& channelName, int index, const string& member, const string& val) int FairMQProgOptions::UpdateChannelValue(const string& channelName, int index, const string& member, const string& val)
{ {
if (member == "type") if (member == "type") {
{
fFairMQChannelMap.at(channelName).at(index).UpdateType(val); fFairMQChannelMap.at(channelName).at(index).UpdateType(val);
return 0; } else if (member == "method") {
}
if (member == "method")
{
fFairMQChannelMap.at(channelName).at(index).UpdateMethod(val); fFairMQChannelMap.at(channelName).at(index).UpdateMethod(val);
return 0; } else if (member == "address") {
}
if (member == "address")
{
fFairMQChannelMap.at(channelName).at(index).UpdateAddress(val); fFairMQChannelMap.at(channelName).at(index).UpdateAddress(val);
return 0; } else if (member == "transport") {
}
if (member == "transport")
{
fFairMQChannelMap.at(channelName).at(index).UpdateTransport(val); fFairMQChannelMap.at(channelName).at(index).UpdateTransport(val);
return 0; } else {
}
else
{
//if we get there it means something is wrong
LOG(error) << "update of FairMQChannel map failed for the following key: " << channelName << "." << index << "." << member; LOG(error) << "update of FairMQChannel map failed for the following key: " << channelName << "." << index << "." << member;
return 1; return 1;
} }
return 0;
} }
int FairMQProgOptions::UpdateChannelValue(const string& channelName, int index, const string& member, int val) int FairMQProgOptions::UpdateChannelValue(const string& channelName, int index, const string& member, int val)
{ {
if (member == "sndBufSize") if (member == "sndBufSize") {
{
fFairMQChannelMap.at(channelName).at(index).UpdateSndBufSize(val); fFairMQChannelMap.at(channelName).at(index).UpdateSndBufSize(val);
return 0; } else if (member == "rcvBufSize") {
}
if (member == "rcvBufSize")
{
fFairMQChannelMap.at(channelName).at(index).UpdateRcvBufSize(val); fFairMQChannelMap.at(channelName).at(index).UpdateRcvBufSize(val);
return 0; } else if (member == "sndKernelSize") {
fFairMQChannelMap.at(channelName).at(index).UpdateSndKernelSize(val);
} else if (member == "rcvKernelSize") {
fFairMQChannelMap.at(channelName).at(index).UpdateRcvKernelSize(val);
} else if (member == "linger") {
fFairMQChannelMap.at(channelName).at(index).UpdateLinger(val);
} else if (member == "rateLogging") {
fFairMQChannelMap.at(channelName).at(index).UpdateRateLogging(val);
} else if (member == "portRangeMin") {
fFairMQChannelMap.at(channelName).at(index).UpdatePortRangeMin(val);
} else if (member == "portRangeMax") {
fFairMQChannelMap.at(channelName).at(index).UpdatePortRangeMax(val);
} else {
LOG(error) << "update of FairMQChannel map failed for the following key: " << channelName << "." << index << "." << member;
return 1;
} }
if (member == "rateLogging") return 0;
{ }
fFairMQChannelMap.at(channelName).at(index).UpdateRateLogging(val);
int FairMQProgOptions::UpdateChannelValue(const string& channelName, int index, const string& member, bool val)
{
if (member == "autoBind") {
fFairMQChannelMap.at(channelName).at(index).UpdateAutoBind(val);
return 0; return 0;
} } else {
else
{
// if we get there it means something is wrong
LOG(error) << "update of FairMQChannel map failed for the following key: " << channelName << "." << index << "." << member; LOG(error) << "update of FairMQChannel map failed for the following key: " << channelName << "." << index << "." << member;
return 1; return 1;
} }

View File

@@ -59,13 +59,13 @@ class FairMQProgOptions
// update variable map // update variable map
UpdateVarMap<typename std::decay<T>::type>(key, val); UpdateVarMap<typename std::decay<T>::type>(key, val);
// update FairMQChannel map if the key is a channel key if (key == "channel-config")
if (std::is_same<T, int>::value || std::is_same<T, std::string>::value)
{ {
if (fChannelKeyMap.count(key)) ParseChannelsFromCmdLine();
{ }
UpdateChannelValue(fChannelKeyMap.at(key).channel, fChannelKeyMap.at(key).index, fChannelKeyMap.at(key).member, val); else if (fChannelKeyMap.count(key))
} {
UpdateChannelValue(fChannelKeyMap.at(key).channel, fChannelKeyMap.at(key).index, fChannelKeyMap.at(key).member, val);
} }
lock.unlock(); lock.unlock();
@@ -210,8 +210,15 @@ class FairMQProgOptions
} }
int UpdateChannelMap(const FairMQChannelMap& map); int UpdateChannelMap(const FairMQChannelMap& map);
template<typename T>
int UpdateChannelValue(const std::string&, int, const std::string&, T)
{
LOG(error) << "update of FairMQChannel map failed, because value type not supported";
return 1;
}
int UpdateChannelValue(const std::string& channelName, int index, const std::string& member, const std::string& val); int UpdateChannelValue(const std::string& channelName, int index, const std::string& member, const std::string& val);
int UpdateChannelValue(const std::string& channelName, int index, const std::string& member, int val); int UpdateChannelValue(const std::string& channelName, int index, const std::string& member, int val);
int UpdateChannelValue(const std::string& channelName, int index, const std::string& member, bool val);
void UpdateChannelInfo(); void UpdateChannelInfo();
@@ -223,6 +230,7 @@ class FairMQProgOptions
vm[key].value() = boost::any(val); vm[key].value() = boost::any(val);
} }
void ParseChannelsFromCmdLine();
}; };
#endif /* FAIRMQPROGOPTIONS_H */ #endif /* FAIRMQPROGOPTIONS_H */

View File

@@ -56,7 +56,11 @@ struct SUBOPT
RCVBUFSIZE, // size of the receive queue RCVBUFSIZE, // size of the receive queue
SNDKERNELSIZE, SNDKERNELSIZE,
RCVKERNELSIZE, RCVKERNELSIZE,
LINGER,
RATELOGGING, // logging rate RATELOGGING, // logging rate
PORTRANGEMIN,
PORTRANGEMAX,
AUTOBIND,
NUMSOCKETS, NUMSOCKETS,
lastsocketkey lastsocketkey
}; };
@@ -71,7 +75,11 @@ struct SUBOPT
/*[RCVBUFSIZE] = */ "rcvBufSize", /*[RCVBUFSIZE] = */ "rcvBufSize",
/*[SNDKERNELSIZE] = */ "sndKernelSize", /*[SNDKERNELSIZE] = */ "sndKernelSize",
/*[RCVKERNELSIZE] = */ "rcvKernelSize", /*[RCVKERNELSIZE] = */ "rcvKernelSize",
/*[LINGER] = */ "linger",
/*[RATELOGGING] = */ "rateLogging", /*[RATELOGGING] = */ "rateLogging",
/*[PORTRANGEMIN] = */ "portRangeMin",
/*[PORTRANGEMAX] = */ "portRangeMax",
/*[AUTOBIND] = */ "autoBind",
/*[NUMSOCKETS] = */ "numSockets", /*[NUMSOCKETS] = */ "numSockets",
nullptr nullptr
}; };

View File

@@ -48,26 +48,20 @@ DDS::DDS(const string& name, const Plugin::Version version, const string& mainta
, fDeviceTerminationRequested(false) , fDeviceTerminationRequested(false)
, fHeartbeatInterval{100} , fHeartbeatInterval{100}
{ {
try try {
{
TakeDeviceControl(); TakeDeviceControl();
fControllerThread = thread(&DDS::HandleControl, this); fControllerThread = thread(&DDS::HandleControl, this);
fHeartbeatThread = thread(&DDS::HeartbeatSender, this); fHeartbeatThread = thread(&DDS::HeartbeatSender, this);
} } catch (PluginServices::DeviceControlError& e) {
catch (PluginServices::DeviceControlError& e)
{
LOG(debug) << e.what(); LOG(debug) << e.what();
} } catch (exception& e) {
catch (exception& e)
{
LOG(error) << "Error in plugin initialization: " << e.what(); LOG(error) << "Error in plugin initialization: " << e.what();
} }
} }
auto DDS::HandleControl() -> void auto DDS::HandleControl() -> void
{ {
try try {
{
// subscribe for state changes from DDS (subscriptions start firing after fService.start() is called) // subscribe for state changes from DDS (subscriptions start firing after fService.start() is called)
SubscribeForCustomCommands(); SubscribeForCustomCommands();
@@ -80,23 +74,20 @@ auto DDS::HandleControl() -> void
SubscribeForConnectingChannels(); SubscribeForConnectingChannels();
// subscribe to device state changes, pushing new state chenges into the event queue // subscribe to device state changes, pushing new state chenges into the event queue
SubscribeToDeviceStateChange([&](DeviceState newState) SubscribeToDeviceStateChange([&](DeviceState newState) {
{
{ {
lock_guard<mutex> lock{fEventsMutex}; lock_guard<mutex> lock{fEventsMutex};
fEvents.push(newState); fEvents.push(newState);
} }
fNewEvent.notify_one(); fNewEvent.notify_one();
if (newState == DeviceState::Exiting) if (newState == DeviceState::Exiting) {
{
fDeviceTerminationRequested = true; fDeviceTerminationRequested = true;
} }
{ {
lock_guard<mutex> lock{fStateChangeSubscriberMutex}; lock_guard<mutex> lock{fStateChangeSubscriberMutex};
string id = GetProperty<string>("id"); string id = GetProperty<string>("id");
for (auto subscriberId : fStateChangeSubscribers) for (auto subscriberId : fStateChangeSubscribers) {
{
LOG(debug) << "Publishing state-change: " << newState << " to " << subscriberId; LOG(debug) << "Publishing state-change: " << newState << " to " << subscriberId;
fDDSCustomCmd.send("state-change: " + id + "," + ToStr(newState), to_string(subscriberId)); fDDSCustomCmd.send("state-change: " + id + "," + ToStr(newState), to_string(subscriberId));
} }
@@ -131,14 +122,11 @@ auto DDS::HandleControl() -> void
// wait until stop signal // wait until stop signal
unique_lock<mutex> lock(fStopMutex); unique_lock<mutex> lock(fStopMutex);
while (!fDeviceTerminationRequested) while (!fDeviceTerminationRequested) {
{
fStopCondition.wait_for(lock, chrono::seconds(1)); fStopCondition.wait_for(lock, chrono::seconds(1));
} }
LOG(debug) << "Stopping DDS control plugin"; LOG(debug) << "Stopping DDS control plugin";
} } catch (exception& e) {
catch (exception& e)
{
LOG(error) << "Error: " << e.what() << endl; LOG(error) << "Error: " << e.what() << endl;
return; return;
} }
@@ -146,13 +134,10 @@ auto DDS::HandleControl() -> void
fDDSKeyValue.unsubscribe(); fDDSKeyValue.unsubscribe();
fDDSCustomCmd.unsubscribe(); fDDSCustomCmd.unsubscribe();
try try {
{
UnsubscribeFromDeviceStateChange(); UnsubscribeFromDeviceStateChange();
ReleaseDeviceControl(); ReleaseDeviceControl();
} } catch (fair::mq::PluginServices::DeviceControlError& e) {
catch (fair::mq::PluginServices::DeviceControlError& e)
{
LOG(error) << e.what(); LOG(error) << e.what();
} }
} }
@@ -194,7 +179,7 @@ auto DDS::FillChannelContainers() -> void
for (const auto& vi : iValues) { for (const auto& vi : iValues) {
size_t pos = vi.find(":"); size_t pos = vi.find(":");
string chanName = vi.substr(0, pos ); string chanName = vi.substr(0, pos);
// check if provided name is a valid channel name // check if provided name is a valid channel name
if (fConnectingChans.find(chanName) == fConnectingChans.end()) { if (fConnectingChans.find(chanName) == fConnectingChans.end()) {
@@ -229,11 +214,9 @@ auto DDS::FillChannelContainers() -> void
auto DDS::SubscribeForConnectingChannels() -> void auto DDS::SubscribeForConnectingChannels() -> void
{ {
fDDSKeyValue.subscribe([&] (const string& propertyId, const string& key, const string& value) fDDSKeyValue.subscribe([&] (const string& propertyId, const string& value, uint64_t senderTaskID) {
{ try {
try LOG(debug) << "Received update for " << propertyId << ": value=" << value << ", senderTaskID=" << senderTaskID;
{
LOG(debug) << "Received update for " << propertyId << ": key=" << key << " value=" << value;
string val = value; string val = value;
// check if it is to handle as one out of multiple values // check if it is to handle as one out of multiple values
auto it = fIofN.find(propertyId); auto it = fIofN.find(propertyId);
@@ -254,20 +237,18 @@ auto DDS::SubscribeForConnectingChannels() -> void
auto it2 = fI.find(propertyId); auto it2 = fI.find(propertyId);
if (it2 != fI.end()) { if (it2 != fI.end()) {
LOG(debug) << "adding connecting channel " << propertyId << " : " << connectionStrings.at(it2->second); LOG(debug) << "adding connecting channel " << propertyId << " : " << connectionStrings.at(it2->second);
fConnectingChans.at(propertyId).fDDSValues.insert(make_pair<string, string>(key.c_str(), connectionStrings.at(it2->second).c_str())); fConnectingChans.at(propertyId).fDDSValues.insert({senderTaskID, connectionStrings.at(it2->second).c_str()});
} else { } else {
LOG(error) << "multiple bound channels received, but no task index specified, only assigning the first"; LOG(error) << "multiple bound channels received, but no task index specified, only assigning the first";
fConnectingChans.at(propertyId).fDDSValues.insert(make_pair<string, string>(key.c_str(), connectionStrings.at(0).c_str())); fConnectingChans.at(propertyId).fDDSValues.insert({senderTaskID, connectionStrings.at(0).c_str()});
} }
} else { // only one bound channel received } else { // only one bound channel received
fConnectingChans.at(propertyId).fDDSValues.insert(make_pair<string, string>(key.c_str(), val.c_str())); fConnectingChans.at(propertyId).fDDSValues.insert({senderTaskID, val.c_str()});
} }
// update channels and remove them from unfinished container // update channels and remove them from unfinished container
for (auto mi = fConnectingChans.begin(); mi != fConnectingChans.end(); /* no increment */) for (auto mi = fConnectingChans.begin(); mi != fConnectingChans.end(); /* no increment */) {
{ if (mi->second.fSubChannelAddresses.size() == mi->second.fDDSValues.size()) {
if (mi->second.fSubChannelAddresses.size() == mi->second.fDDSValues.size())
{
// when multiple subChannels are used, their order on every device should be the same, irregardless of arrival order from DDS. // when multiple subChannels are used, their order on every device should be the same, irregardless of arrival order from DDS.
sort(mi->second.fSubChannelAddresses.begin(), mi->second.fSubChannelAddresses.end()); sort(mi->second.fSubChannelAddresses.begin(), mi->second.fSubChannelAddresses.end());
auto it3 = mi->second.fDDSValues.begin(); auto it3 = mi->second.fDDSValues.begin();
@@ -277,24 +258,19 @@ auto DDS::SubscribeForConnectingChannels() -> void
++it3; ++it3;
} }
fConnectingChans.erase(mi++); fConnectingChans.erase(mi++);
} } else {
else
{
++mi; ++mi;
} }
} }
} } catch (const exception& e) {
catch (const exception& e) LOG(error) << "Error on handling DDS property update for " << propertyId << ": value=" << value << ", senderTaskID=" << senderTaskID << ": " << e.what();
{
LOG(error) << "Error on handling DDS property update for " << propertyId << ": key=" << key << " value=" << value << ": " << e.what();
} }
}); });
} }
auto DDS::PublishBoundChannels() -> void auto DDS::PublishBoundChannels() -> void
{ {
for (const auto& chan : fBindingChans) for (const auto& chan : fBindingChans) {
{
string joined = boost::algorithm::join(chan.second, ","); string joined = boost::algorithm::join(chan.second, ",");
LOG(debug) << "Publishing " << chan.first << " bound addresses (" << chan.second.size() << ") to DDS under '" << chan.first << "' property name."; LOG(debug) << "Publishing " << chan.first << " bound addresses (" << chan.second.size() << ") to DDS under '" << chan.first << "' property name.";
fDDSKeyValue.putValue(chan.first, joined); fDDSKeyValue.putValue(chan.first, joined);
@@ -306,13 +282,11 @@ auto DDS::HeartbeatSender() -> void
string id = GetProperty<string>("id"); string id = GetProperty<string>("id");
string pid(to_string(getpid())); string pid(to_string(getpid()));
while (!fDeviceTerminationRequested) while (!fDeviceTerminationRequested) {
{
{ {
lock_guard<mutex> lock{fHeartbeatSubscriberMutex}; lock_guard<mutex> lock{fHeartbeatSubscriberMutex};
for (const auto subscriberId : fHeartbeatSubscribers) for (const auto subscriberId : fHeartbeatSubscribers) {
{
fDDSCustomCmd.send("heartbeat: " + id + "," + pid, to_string(subscriberId)); fDDSCustomCmd.send("heartbeat: " + id + "," + pid, to_string(subscriberId));
} }
} }
@@ -326,58 +300,42 @@ auto DDS::SubscribeForCustomCommands() -> void
string id = GetProperty<string>("id"); string id = GetProperty<string>("id");
string pid(to_string(getpid())); string pid(to_string(getpid()));
fDDSCustomCmd.subscribe([id, pid, this](const string& cmd, const string& cond, uint64_t senderId) fDDSCustomCmd.subscribe([id, pid, this](const string& cmd, const string& cond, uint64_t senderId) {
{
LOG(info) << "Received command: " << cmd; LOG(info) << "Received command: " << cmd;
if (cmd == "check-state") if (cmd == "check-state") {
{
fDDSCustomCmd.send(id + ": " + ToStr(GetCurrentDeviceState()) + " (pid: " + pid + ")", to_string(senderId)); fDDSCustomCmd.send(id + ": " + ToStr(GetCurrentDeviceState()) + " (pid: " + pid + ")", to_string(senderId));
} } else if (fCommands.find(cmd) != fCommands.end()) {
else if (fCommands.find(cmd) != fCommands.end())
{
fDDSCustomCmd.send(id + ": attempting to " + cmd, to_string(senderId)); fDDSCustomCmd.send(id + ": attempting to " + cmd, to_string(senderId));
ChangeDeviceState(ToDeviceStateTransition(cmd)); ChangeDeviceState(ToDeviceStateTransition(cmd));
} } else if (cmd == "END") {
else if (cmd == "END")
{
fDDSCustomCmd.send(id + ": attempting to " + cmd, to_string(senderId)); fDDSCustomCmd.send(id + ": attempting to " + cmd, to_string(senderId));
ChangeDeviceState(ToDeviceStateTransition(cmd)); ChangeDeviceState(ToDeviceStateTransition(cmd));
fDDSCustomCmd.send(id + ": " + ToStr(GetCurrentDeviceState()), to_string(senderId)); fDDSCustomCmd.send(id + ": " + ToStr(GetCurrentDeviceState()), to_string(senderId));
if (ToStr(GetCurrentDeviceState()) == "EXITING") if (ToStr(GetCurrentDeviceState()) == "EXITING") {
{
unique_lock<mutex> lock(fStopMutex); unique_lock<mutex> lock(fStopMutex);
fStopCondition.notify_one(); fStopCondition.notify_one();
} }
} } else if (cmd == "dump-config") {
else if (cmd == "dump-config")
{
stringstream ss; stringstream ss;
for (const auto pKey: GetPropertyKeys()) for (const auto pKey: GetPropertyKeys()) {
{
ss << id << ": " << pKey << " -> " << GetPropertyAsString(pKey) << endl; ss << id << ": " << pKey << " -> " << GetPropertyAsString(pKey) << endl;
} }
fDDSCustomCmd.send(ss.str(), to_string(senderId)); fDDSCustomCmd.send(ss.str(), to_string(senderId));
} } else if (cmd == "subscribe-to-heartbeats") {
else if (cmd == "subscribe-to-heartbeats")
{
{ {
// auto size = fHeartbeatSubscribers.size(); // auto size = fHeartbeatSubscribers.size();
lock_guard<mutex> lock{fHeartbeatSubscriberMutex}; lock_guard<mutex> lock{fHeartbeatSubscriberMutex};
fHeartbeatSubscribers.insert(senderId); fHeartbeatSubscribers.insert(senderId);
} }
fDDSCustomCmd.send("heartbeat-subscription: " + id + ",OK", to_string(senderId)); fDDSCustomCmd.send("heartbeat-subscription: " + id + ",OK", to_string(senderId));
} } else if (cmd == "unsubscribe-from-heartbeats") {
else if (cmd == "unsubscribe-from-heartbeats")
{
{ {
lock_guard<mutex> lock{fHeartbeatSubscriberMutex}; lock_guard<mutex> lock{fHeartbeatSubscriberMutex};
fHeartbeatSubscribers.erase(senderId); fHeartbeatSubscribers.erase(senderId);
} }
fDDSCustomCmd.send("heartbeat-unsubscription: " + id + ",OK", to_string(senderId)); fDDSCustomCmd.send("heartbeat-unsubscription: " + id + ",OK", to_string(senderId));
} } else if (cmd == "subscribe-to-state-changes") {
else if (cmd == "subscribe-to-state-changes")
{
{ {
// auto size = fStateChangeSubscribers.size(); // auto size = fStateChangeSubscribers.size();
lock_guard<mutex> lock{fStateChangeSubscriberMutex}; lock_guard<mutex> lock{fStateChangeSubscriberMutex};
@@ -387,17 +345,13 @@ auto DDS::SubscribeForCustomCommands() -> void
auto state = GetCurrentDeviceState(); auto state = GetCurrentDeviceState();
LOG(debug) << "Publishing state-change: " << state << " to " << senderId; LOG(debug) << "Publishing state-change: " << state << " to " << senderId;
fDDSCustomCmd.send("state-change: " + id + "," + ToStr(state), to_string(senderId)); fDDSCustomCmd.send("state-change: " + id + "," + ToStr(state), to_string(senderId));
} } else if (cmd == "unsubscribe-from-state-changes") {
else if (cmd == "unsubscribe-from-state-changes")
{
{ {
lock_guard<mutex> lock{fStateChangeSubscriberMutex}; lock_guard<mutex> lock{fStateChangeSubscriberMutex};
fStateChangeSubscribers.erase(senderId); fStateChangeSubscribers.erase(senderId);
} }
fDDSCustomCmd.send("state-changes-unsubscription: " + id + ",OK", to_string(senderId)); fDDSCustomCmd.send("state-changes-unsubscription: " + id + ",OK", to_string(senderId));
} } else {
else
{
LOG(warn) << "Unknown command: " << cmd; LOG(warn) << "Unknown command: " << cmd;
LOG(warn) << "Origin: " << senderId; LOG(warn) << "Origin: " << senderId;
LOG(warn) << "Destination: " << cond; LOG(warn) << "Destination: " << cond;
@@ -408,8 +362,7 @@ auto DDS::SubscribeForCustomCommands() -> void
auto DDS::WaitForNextState() -> DeviceState auto DDS::WaitForNextState() -> DeviceState
{ {
unique_lock<mutex> lock{fEventsMutex}; unique_lock<mutex> lock{fEventsMutex};
while (fEvents.empty()) while (fEvents.empty()) {
{
fNewEvent.wait(lock); fNewEvent.wait(lock);
} }
@@ -420,13 +373,11 @@ auto DDS::WaitForNextState() -> DeviceState
DDS::~DDS() DDS::~DDS()
{ {
if (fControllerThread.joinable()) if (fControllerThread.joinable()) {
{
fControllerThread.join(); fControllerThread.join();
} }
if (fHeartbeatThread.joinable()) if (fHeartbeatThread.joinable()) {
{
fHeartbeatThread.join(); fHeartbeatThread.join();
} }
} }

View File

@@ -41,7 +41,7 @@ struct DDSConfig
// container of sub channel addresses // container of sub channel addresses
std::vector<std::string> fSubChannelAddresses; std::vector<std::string> fSubChannelAddresses;
// dds values for the channel // dds values for the channel
std::unordered_map<std::string, std::string> fDDSValues; std::unordered_map<uint64_t, std::string> fDDSValues;
}; };
struct IofN struct IofN

View File

@@ -16,7 +16,9 @@ void addCustomOptions(bpo::options_description& options)
options.add_options() options.add_options()
("out-channel", bpo::value<std::string>()->default_value("data"), "Name of the output channel") ("out-channel", bpo::value<std::string>()->default_value("data"), "Name of the output channel")
("same-msg", bpo::value<bool>()->default_value(false), "Re-send the same message, or recreate for each iteration") ("same-msg", bpo::value<bool>()->default_value(false), "Re-send the same message, or recreate for each iteration")
("msg-size", bpo::value<int>()->default_value(1000000), "Message size in bytes") ("multipart", bpo::value<bool>()->default_value(false), "Handle multipart payloads")
("num-parts", bpo::value<size_t>()->default_value(1), "Number of parts to send. 1 will send single messages, not parts")
("msg-size", bpo::value<size_t>()->default_value(1000000), "Message size in bytes")
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Number of run iterations (0 - infinite)") ("max-iterations", bpo::value<uint64_t>()->default_value(0), "Number of run iterations (0 - infinite)")
("msg-rate", bpo::value<float>()->default_value(0), "Msg rate limit in maximum number of messages per second"); ("msg-rate", bpo::value<float>()->default_value(0), "Msg rate limit in maximum number of messages per second");
} }

View File

@@ -16,7 +16,7 @@ void addCustomOptions(bpo::options_description& options)
options.add_options() options.add_options()
("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel") ("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel")
("out-channel", bpo::value<std::string>()->default_value("data-out"), "Name of the output channel") ("out-channel", bpo::value<std::string>()->default_value("data-out"), "Name of the output channel")
("multipart", bpo::value<int>()->default_value(1), "Handle multipart payloads"); ("multipart", bpo::value<bool>()->default_value(true), "Handle multipart payloads");
} }
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)

View File

@@ -16,7 +16,7 @@ void addCustomOptions(bpo::options_description& options)
options.add_options() options.add_options()
("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel") ("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel")
("out-channel", bpo::value<std::vector<std::string>>()->multitoken(), "Names of the output channels") ("out-channel", bpo::value<std::vector<std::string>>()->multitoken(), "Names of the output channels")
("multipart", bpo::value<int>()->default_value(1), "Handle multipart payloads"); ("multipart", bpo::value<bool>()->default_value(true), "Handle multipart payloads");
} }
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)

View File

@@ -16,7 +16,7 @@ void addCustomOptions(bpo::options_description& options)
options.add_options() options.add_options()
("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel") ("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel")
("out-channel", bpo::value<std::string>()->default_value("data-out"), "Name of the output channel") ("out-channel", bpo::value<std::string>()->default_value("data-out"), "Name of the output channel")
("multipart", bpo::value<int>()->default_value(1), "Handle multipart payloads"); ("multipart", bpo::value<bool>()->default_value(true), "Handle multipart payloads");
} }
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)

View File

@@ -15,7 +15,8 @@ void addCustomOptions(bpo::options_description& options)
{ {
options.add_options() options.add_options()
("in-channel", bpo::value<std::string>()->default_value("data"), "Name of the input channel") ("in-channel", bpo::value<std::string>()->default_value("data"), "Name of the input channel")
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Number of run iterations (0 - infinite)"); ("max-iterations", bpo::value<uint64_t>()->default_value(0), "Number of run iterations (0 - infinite)")
("multipart", bpo::value<bool>()->default_value(false), "Handle multipart payloads");
} }
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)

View File

@@ -16,7 +16,7 @@ void addCustomOptions(bpo::options_description& options)
options.add_options() options.add_options()
("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel") ("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel")
("out-channel", bpo::value<std::string>()->default_value("data-out"), "Name of the output channel") ("out-channel", bpo::value<std::string>()->default_value("data-out"), "Name of the output channel")
("multipart", bpo::value<int>()->default_value(1), "Handle multipart payloads"); ("multipart", bpo::value<bool>()->default_value(true), "Handle multipart payloads");
} }
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)

View File

@@ -5,7 +5,6 @@ export FAIRMQ_PATH=@FAIRMQ_BIN_DIR@
maxIterations="0" maxIterations="0"
msgSize="1000000" msgSize="1000000"
transport="zeromq" transport="zeromq"
sameMsg="true"
affinity="false" affinity="false"
affinitySamp="" affinitySamp=""
affinitySink="" affinitySink=""
@@ -24,11 +23,7 @@ if [[ $3 =~ ^[a-z]+$ ]]; then
fi fi
if [[ $4 =~ ^[a-z]+$ ]]; then if [[ $4 =~ ^[a-z]+$ ]]; then
sameMsg=$4 affinity=$4
fi
if [[ $5 =~ ^[a-z]+$ ]]; then
affinity=$5
fi fi
@@ -45,12 +40,6 @@ fi
echo "transport: $transport" echo "transport: $transport"
if [ $sameMsg = "true" ]; then
echo "resend same message: yes, using Copy() method to resend the same message"
else
echo "resend same message: no, allocating each message separately"
fi
if [ $affinity = "true" ]; then if [ $affinity = "true" ]; then
affinitySamp="taskset -c 0" affinitySamp="taskset -c 0"
affinitySink="taskset -c 1" affinitySink="taskset -c 1"
@@ -60,7 +49,7 @@ else
fi fi
echo "" echo ""
echo "Usage: startBenchmark [message size=1000000] [number of iterations=0] [transport=zeromq/nanomsg/shmem] [resend same message=true] [affinity=false]" echo "Usage: startBenchmark [message size=1000000] [number of iterations=0] [transport=zeromq/nanomsg/shmem] [affinity=false]"
SAMPLER="fairmq-bsampler" SAMPLER="fairmq-bsampler"
SAMPLER+=" --id bsampler1" SAMPLER+=" --id bsampler1"
@@ -69,7 +58,7 @@ SAMPLER+=" --id bsampler1"
SAMPLER+=" --transport $transport" SAMPLER+=" --transport $transport"
SAMPLER+=" --severity debug" SAMPLER+=" --severity debug"
SAMPLER+=" --msg-size $msgSize" SAMPLER+=" --msg-size $msgSize"
SAMPLER+=" --same-msg $sameMsg" SAMPLER+=" --num-parts 1"
# SAMPLER+=" --msg-rate 1000" # SAMPLER+=" --msg-rate 1000"
SAMPLER+=" --max-iterations $maxIterations" SAMPLER+=" --max-iterations $maxIterations"
SAMPLER+=" --channel-config name=data,type=push,method=bind,address=tcp://127.0.0.1:5555" SAMPLER+=" --channel-config name=data,type=push,method=bind,address=tcp://127.0.0.1:5555"
@@ -84,6 +73,7 @@ SINK+=" --id sink1"
#SINK+=" --control static" #SINK+=" --control static"
SINK+=" --transport $transport" SINK+=" --transport $transport"
SINK+=" --severity debug" SINK+=" --severity debug"
SINK+=" --multipart false"
SINK+=" --max-iterations $maxIterations" SINK+=" --max-iterations $maxIterations"
SINK+=" --channel-config name=data,type=pull,method=connect,address=tcp://127.0.0.1:5555" SINK+=" --channel-config name=data,type=pull,method=connect,address=tcp://127.0.0.1:5555"
xterm -geometry 90x50+550+0 -hold -e $affinitySink @CMAKE_CURRENT_BINARY_DIR@/$SINK & xterm -geometry 90x50+550+0 -hold -e $affinitySink @CMAKE_CURRENT_BINARY_DIR@/$SINK &

View File

@@ -25,8 +25,9 @@ namespace bpt = ::boost::posix_time;
atomic<bool> FairMQMessageSHM::fInterrupted(false); atomic<bool> FairMQMessageSHM::fInterrupted(false);
fair::mq::Transport FairMQMessageSHM::fTransportType = fair::mq::Transport::SHM; fair::mq::Transport FairMQMessageSHM::fTransportType = fair::mq::Transport::SHM;
FairMQMessageSHM::FairMQMessageSHM(Manager& manager) FairMQMessageSHM::FairMQMessageSHM(Manager& manager, FairMQTransportFactory* factory)
: fManager(manager) : FairMQMessage{factory}
, fManager(manager)
, fMessage() , fMessage()
, fQueued(false) , fQueued(false)
, fMetaCreated(false) , fMetaCreated(false)
@@ -44,8 +45,9 @@ FairMQMessageSHM::FairMQMessageSHM(Manager& manager)
fMetaCreated = true; fMetaCreated = true;
} }
FairMQMessageSHM::FairMQMessageSHM(Manager& manager, const size_t size) FairMQMessageSHM::FairMQMessageSHM(Manager& manager, const size_t size, FairMQTransportFactory* factory)
: fManager(manager) : FairMQMessage{factory}
, fManager(manager)
, fMessage() , fMessage()
, fQueued(false) , fQueued(false)
, fMetaCreated(false) , fMetaCreated(false)
@@ -59,8 +61,9 @@ FairMQMessageSHM::FairMQMessageSHM(Manager& manager, const size_t size)
InitializeChunk(size); InitializeChunk(size);
} }
FairMQMessageSHM::FairMQMessageSHM(Manager& manager, void* data, const size_t size, fairmq_free_fn* ffn, void* hint) FairMQMessageSHM::FairMQMessageSHM(Manager& manager, void* data, const size_t size, fairmq_free_fn* ffn, void* hint, FairMQTransportFactory* factory)
: fManager(manager) : FairMQMessage{factory}
, fManager(manager)
, fMessage() , fMessage()
, fQueued(false) , fQueued(false)
, fMetaCreated(false) , fMetaCreated(false)
@@ -85,8 +88,9 @@ FairMQMessageSHM::FairMQMessageSHM(Manager& manager, void* data, const size_t si
} }
} }
FairMQMessageSHM::FairMQMessageSHM(Manager& manager, FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint) FairMQMessageSHM::FairMQMessageSHM(Manager& manager, FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint, FairMQTransportFactory* factory)
: fManager(manager) : FairMQMessage{factory}
, fManager(manager)
, fMessage() , fMessage()
, fQueued(false) , fQueued(false)
, fMetaCreated(false) , fMetaCreated(false)
@@ -312,29 +316,6 @@ void FairMQMessageSHM::Copy(const FairMQMessage& msg)
} }
} }
void FairMQMessageSHM::Copy(const FairMQMessagePtr& msg)
{
if (fHandle < 0)
{
bipc::managed_shared_memory::handle_t otherHandle = static_cast<FairMQMessageSHM*>(msg.get())->fHandle;
if (otherHandle)
{
if (InitializeChunk(msg->GetSize()))
{
memcpy(GetData(), msg->GetData(), msg->GetSize());
}
}
else
{
LOG(error) << "copy fail: source message not initialized!";
}
}
else
{
LOG(error) << "copy fail: target message already initialized!";
}
}
void FairMQMessageSHM::CloseMessage() void FairMQMessageSHM::CloseMessage()
{ {
if (fHandle >= 0 && !fQueued) if (fHandle >= 0 && !fQueued)
@@ -342,7 +323,7 @@ void FairMQMessageSHM::CloseMessage()
if (fRegionId == 0) if (fRegionId == 0)
{ {
fManager.Segment().deallocate(fManager.Segment().get_address_from_handle(fHandle)); fManager.Segment().deallocate(fManager.Segment().get_address_from_handle(fHandle));
fHandle = 0; fHandle = -1;
} }
else else
{ {
@@ -398,6 +379,7 @@ void FairMQMessageSHM::CloseMessage()
{ {
LOG(error) << "failed closing message, reason: " << zmq_strerror(errno); LOG(error) << "failed closing message, reason: " << zmq_strerror(errno);
} }
fMetaCreated = false;
} }
} }

View File

@@ -22,15 +22,15 @@
class FairMQSocketSHM; class FairMQSocketSHM;
class FairMQMessageSHM : public FairMQMessage class FairMQMessageSHM final : public FairMQMessage
{ {
friend class FairMQSocketSHM; friend class FairMQSocketSHM;
public: public:
FairMQMessageSHM(fair::mq::shmem::Manager& manager); FairMQMessageSHM(fair::mq::shmem::Manager& manager, FairMQTransportFactory* factory = nullptr);
FairMQMessageSHM(fair::mq::shmem::Manager& manager, const size_t size); FairMQMessageSHM(fair::mq::shmem::Manager& manager, const size_t size, FairMQTransportFactory* factory = nullptr);
FairMQMessageSHM(fair::mq::shmem::Manager& manager, void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr); FairMQMessageSHM(fair::mq::shmem::Manager& manager, void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr, FairMQTransportFactory* factory = nullptr);
FairMQMessageSHM(fair::mq::shmem::Manager& manager, FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0); FairMQMessageSHM(fair::mq::shmem::Manager& manager, FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0, FairMQTransportFactory* factory = nullptr);
FairMQMessageSHM(const FairMQMessageSHM&) = delete; FairMQMessageSHM(const FairMQMessageSHM&) = delete;
FairMQMessageSHM operator=(const FairMQMessageSHM&) = delete; FairMQMessageSHM operator=(const FairMQMessageSHM&) = delete;
@@ -47,7 +47,6 @@ class FairMQMessageSHM : public FairMQMessage
fair::mq::Transport GetType() const override; fair::mq::Transport GetType() const override;
void Copy(const FairMQMessage& msg) override; void Copy(const FairMQMessage& msg) override;
void Copy(const FairMQMessagePtr& msg) override;
~FairMQMessageSHM() override; ~FairMQMessageSHM() override;

View File

@@ -13,6 +13,7 @@
*/ */
#include "FairMQPollerSHM.h" #include "FairMQPollerSHM.h"
#include "FairMQSocketSHM.h"
#include "FairMQLogger.h" #include "FairMQLogger.h"
#include <zmq.h> #include <zmq.h>
@@ -29,19 +30,19 @@ FairMQPollerSHM::FairMQPollerSHM(const vector<FairMQChannel>& channels)
for (int i = 0; i < fNumItems; ++i) for (int i = 0; i < fNumItems; ++i)
{ {
fItems[i].socket = channels.at(i).GetSocket().GetSocket(); fItems[i].socket = static_cast<const FairMQSocketSHM*>(&(channels.at(i).GetSocket()))->GetSocket();
fItems[i].fd = 0; fItems[i].fd = 0;
fItems[i].revents = 0; fItems[i].revents = 0;
int type = 0; int type = 0;
size_t size = sizeof(type); size_t size = sizeof(type);
zmq_getsockopt(channels.at(i).GetSocket().GetSocket(), ZMQ_TYPE, &type, &size); zmq_getsockopt(static_cast<const FairMQSocketSHM*>(&(channels.at(i).GetSocket()))->GetSocket(), ZMQ_TYPE, &type, &size);
SetItemEvents(fItems[i], type); SetItemEvents(fItems[i], type);
} }
} }
FairMQPollerSHM::FairMQPollerSHM(const vector<const FairMQChannel*>& channels) FairMQPollerSHM::FairMQPollerSHM(const vector<FairMQChannel*>& channels)
: fItems() : fItems()
, fNumItems(0) , fNumItems(0)
, fOffsetMap() , fOffsetMap()
@@ -51,13 +52,13 @@ FairMQPollerSHM::FairMQPollerSHM(const vector<const FairMQChannel*>& channels)
for (int i = 0; i < fNumItems; ++i) for (int i = 0; i < fNumItems; ++i)
{ {
fItems[i].socket = channels.at(i)->GetSocket().GetSocket(); fItems[i].socket = static_cast<const FairMQSocketSHM*>(&(channels.at(i)->GetSocket()))->GetSocket();
fItems[i].fd = 0; fItems[i].fd = 0;
fItems[i].revents = 0; fItems[i].revents = 0;
int type = 0; int type = 0;
size_t size = sizeof(type); size_t size = sizeof(type);
zmq_getsockopt(channels.at(i)->GetSocket().GetSocket(), ZMQ_TYPE, &type, &size); zmq_getsockopt(static_cast<const FairMQSocketSHM*>(&(channels.at(i)->GetSocket()))->GetSocket(), ZMQ_TYPE, &type, &size);
SetItemEvents(fItems[i], type); SetItemEvents(fItems[i], type);
} }
@@ -88,13 +89,13 @@ FairMQPollerSHM::FairMQPollerSHM(const unordered_map<string, vector<FairMQChanne
{ {
index = fOffsetMap[channel] + i; index = fOffsetMap[channel] + i;
fItems[index].socket = channelsMap.at(channel).at(i).GetSocket().GetSocket(); fItems[index].socket = static_cast<const FairMQSocketSHM*>(&(channelsMap.at(channel).at(i).GetSocket()))->GetSocket();
fItems[index].fd = 0; fItems[index].fd = 0;
fItems[index].revents = 0; fItems[index].revents = 0;
int type = 0; int type = 0;
size_t size = sizeof(type); size_t size = sizeof(type);
zmq_getsockopt(channelsMap.at(channel).at(i).GetSocket().GetSocket(), ZMQ_TYPE, &type, &size); zmq_getsockopt(static_cast<const FairMQSocketSHM*>(&(channelsMap.at(channel).at(i).GetSocket()))->GetSocket(), ZMQ_TYPE, &type, &size);
SetItemEvents(fItems[index], type); SetItemEvents(fItems[index], type);
} }
@@ -108,29 +109,6 @@ FairMQPollerSHM::FairMQPollerSHM(const unordered_map<string, vector<FairMQChanne
} }
} }
FairMQPollerSHM::FairMQPollerSHM(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket)
: fItems()
, fNumItems(2)
, fOffsetMap()
{
fItems = new zmq_pollitem_t[fNumItems];
fItems[0].socket = cmdSocket.GetSocket();
fItems[0].fd = 0;
fItems[0].events = ZMQ_POLLIN;
fItems[0].revents = 0;
fItems[1].socket = dataSocket.GetSocket();
fItems[1].fd = 0;
fItems[1].revents = 0;
int type = 0;
size_t size = sizeof(type);
zmq_getsockopt(dataSocket.GetSocket(), ZMQ_TYPE, &type, &size);
SetItemEvents(fItems[1], type);
}
void FairMQPollerSHM::SetItemEvents(zmq_pollitem_t& item, const int type) void FairMQPollerSHM::SetItemEvents(zmq_pollitem_t& item, const int type)
{ {
if (type == ZMQ_REQ || type == ZMQ_REP || type == ZMQ_PAIR || type == ZMQ_DEALER || type == ZMQ_ROUTER) if (type == ZMQ_REQ || type == ZMQ_REP || type == ZMQ_PAIR || type == ZMQ_DEALER || type == ZMQ_ROUTER)

View File

@@ -19,14 +19,14 @@
class FairMQChannel; class FairMQChannel;
class FairMQPollerSHM : public FairMQPoller class FairMQPollerSHM final : public FairMQPoller
{ {
friend class FairMQChannel; friend class FairMQChannel;
friend class FairMQTransportFactorySHM; friend class FairMQTransportFactorySHM;
public: public:
FairMQPollerSHM(const std::vector<FairMQChannel>& channels); FairMQPollerSHM(const std::vector<FairMQChannel>& channels);
FairMQPollerSHM(const std::vector<const FairMQChannel*>& channels); FairMQPollerSHM(const std::vector<FairMQChannel*>& channels);
FairMQPollerSHM(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList); FairMQPollerSHM(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList);
FairMQPollerSHM(const FairMQPollerSHM&) = delete; FairMQPollerSHM(const FairMQPollerSHM&) = delete;
@@ -43,8 +43,6 @@ class FairMQPollerSHM : public FairMQPoller
~FairMQPollerSHM() override; ~FairMQPollerSHM() override;
private: private:
FairMQPollerSHM(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket);
zmq_pollitem_t* fItems; zmq_pollitem_t* fItems;
int fNumItems; int fNumItems;

View File

@@ -11,6 +11,7 @@
#include "FairMQMessageSHM.h" #include "FairMQMessageSHM.h"
#include "FairMQUnmanagedRegionSHM.h" #include "FairMQUnmanagedRegionSHM.h"
#include "FairMQLogger.h" #include "FairMQLogger.h"
#include <fairmq/Tools.h>
#include <zmq.h> #include <zmq.h>
@@ -18,11 +19,13 @@
using namespace std; using namespace std;
using namespace fair::mq::shmem; using namespace fair::mq::shmem;
using namespace fair::mq;
atomic<bool> FairMQSocketSHM::fInterrupted(false); atomic<bool> FairMQSocketSHM::fInterrupted(false);
FairMQSocketSHM::FairMQSocketSHM(Manager& manager, const string& type, const string& name, const string& id /*= ""*/, void* context) FairMQSocketSHM::FairMQSocketSHM(Manager& manager, const string& type, const string& name, const string& id /*= ""*/, void* context, FairMQTransportFactory* fac /*=nullptr*/)
: fSocket(nullptr) : FairMQSocket{fac}
, fSocket(nullptr)
, fManager(manager) , fManager(manager)
, fId(id + "." + name + "." + type) , fId(id + "." + name + "." + type)
, fBytesTx(0) , fBytesTx(0)
@@ -78,7 +81,7 @@ FairMQSocketSHM::FairMQSocketSHM(Manager& manager, const string& type, const str
throw fair::mq::SocketError("PUB/SUB socket type is not supported for shared memory transport"); throw fair::mq::SocketError("PUB/SUB socket type is not supported for shared memory transport");
} }
// LOG(info) << "created socket " << fId; LOG(debug) << "Created socket " << GetId();
} }
bool FairMQSocketSHM::Bind(const string& address) bool FairMQSocketSHM::Bind(const string& address)
@@ -97,30 +100,26 @@ bool FairMQSocketSHM::Bind(const string& address)
return true; return true;
} }
void FairMQSocketSHM::Connect(const string& address) bool FairMQSocketSHM::Connect(const string& address)
{ {
// LOG(info) << "connect socket " << fId << " on " << address; // LOG(info) << "connect socket " << fId << " on " << address;
if (zmq_connect(fSocket, address.c_str()) != 0) if (zmq_connect(fSocket, address.c_str()) != 0)
{ {
LOG(error) << "Failed connecting socket " << fId << ", reason: " << zmq_strerror(errno); LOG(error) << "Failed connecting socket " << fId << ", reason: " << zmq_strerror(errno);
// error here means incorrect configuration. exit if it happens. return false;
exit(EXIT_FAILURE);
} }
return true;
} }
int FairMQSocketSHM::Send(FairMQMessagePtr& msg, const int timeout) { return SendImpl(msg, 0, timeout); } int FairMQSocketSHM::Send(FairMQMessagePtr& msg, const int timeout)
int FairMQSocketSHM::Receive(FairMQMessagePtr& msg, const int timeout) { return ReceiveImpl(msg, 0, timeout); }
int64_t FairMQSocketSHM::Send(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return SendImpl(msgVec, 0, timeout); }
int64_t FairMQSocketSHM::Receive(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return ReceiveImpl(msgVec, 0, timeout); }
int FairMQSocketSHM::TrySend(FairMQMessagePtr& msg) { return SendImpl(msg, ZMQ_DONTWAIT, 0); }
int FairMQSocketSHM::TryReceive(FairMQMessagePtr& msg) { return ReceiveImpl(msg, ZMQ_DONTWAIT, 0); }
int64_t FairMQSocketSHM::TrySend(vector<unique_ptr<FairMQMessage>>& msgVec) { return SendImpl(msgVec, ZMQ_DONTWAIT, 0); }
int64_t FairMQSocketSHM::TryReceive(vector<unique_ptr<FairMQMessage>>& msgVec) { return ReceiveImpl(msgVec, ZMQ_DONTWAIT, 0); }
int FairMQSocketSHM::SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout)
{ {
int flags = 0;
if (timeout == 0)
{
flags = ZMQ_DONTWAIT;
}
int elapsed = 0; int elapsed = 0;
while (true && !fInterrupted) while (true && !fInterrupted)
@@ -144,7 +143,7 @@ int FairMQSocketSHM::SendImpl(FairMQMessagePtr& msg, const int flags, const int
{ {
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0)) if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
{ {
if (timeout) if (timeout > 0)
{ {
elapsed += fSndTimeout; elapsed += fSndTimeout;
if (elapsed >= timeout) if (elapsed >= timeout)
@@ -174,8 +173,13 @@ int FairMQSocketSHM::SendImpl(FairMQMessagePtr& msg, const int flags, const int
return -1; return -1;
} }
int FairMQSocketSHM::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout) int FairMQSocketSHM::Receive(FairMQMessagePtr& msg, const int timeout)
{ {
int flags = 0;
if (timeout == 0)
{
flags = ZMQ_DONTWAIT;
}
int elapsed = 0; int elapsed = 0;
zmq_msg_t* msgPtr = static_cast<FairMQMessageSHM*>(msg.get())->GetMessage(); zmq_msg_t* msgPtr = static_cast<FairMQMessageSHM*>(msg.get())->GetMessage();
@@ -216,7 +220,7 @@ int FairMQSocketSHM::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const i
{ {
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0)) if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
{ {
if (timeout) if (timeout > 0)
{ {
elapsed += fRcvTimeout; elapsed += fRcvTimeout;
if (elapsed >= timeout) if (elapsed >= timeout)
@@ -244,13 +248,18 @@ int FairMQSocketSHM::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const i
} }
} }
int64_t FairMQSocketSHM::SendImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout) int64_t FairMQSocketSHM::Send(vector<FairMQMessagePtr>& msgVec, const int timeout)
{ {
int flags = 0;
if (timeout == 0)
{
flags = ZMQ_DONTWAIT;
}
const unsigned int vecSize = msgVec.size(); const unsigned int vecSize = msgVec.size();
int elapsed = 0; int elapsed = 0;
if (vecSize == 1) { if (vecSize == 1) {
return SendImpl(msgVec.back(), flags, timeout); return Send(msgVec.back(), timeout);
} }
// put it into zmq message // put it into zmq message
@@ -277,7 +286,7 @@ int64_t FairMQSocketSHM::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
} }
else if (nbytes > 0) else if (nbytes > 0)
{ {
assert(nbytes == (vecSize * sizeof(MetaHeader))); // all or nothing assert(static_cast<unsigned int>(nbytes) == (vecSize * sizeof(MetaHeader))); // all or nothing
for (auto& msg : msgVec) for (auto& msg : msgVec)
{ {
@@ -297,7 +306,7 @@ int64_t FairMQSocketSHM::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
{ {
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0)) if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
{ {
if (timeout) if (timeout > 0)
{ {
elapsed += fSndTimeout; elapsed += fSndTimeout;
if (elapsed >= timeout) if (elapsed >= timeout)
@@ -332,8 +341,13 @@ int64_t FairMQSocketSHM::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
return -1; return -1;
} }
int64_t FairMQSocketSHM::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout) int64_t FairMQSocketSHM::Receive(vector<FairMQMessagePtr>& msgVec, const int timeout)
{ {
int flags = 0;
if (timeout == 0)
{
flags = ZMQ_DONTWAIT;
}
int elapsed = 0; int elapsed = 0;
zmq_msg_t zmqMsg; zmq_msg_t zmqMsg;
@@ -364,7 +378,7 @@ int64_t FairMQSocketSHM::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int
MetaHeader metaHeader; MetaHeader metaHeader;
memcpy(&metaHeader, &hdrVec[m], sizeof(MetaHeader)); memcpy(&metaHeader, &hdrVec[m], sizeof(MetaHeader));
msgVec.emplace_back(fair::mq::tools::make_unique<FairMQMessageSHM>(fManager)); msgVec.emplace_back(fair::mq::tools::make_unique<FairMQMessageSHM>(fManager, GetTransport()));
FairMQMessageSHM* msg = static_cast<FairMQMessageSHM*>(msgVec.back().get()); FairMQMessageSHM* msg = static_cast<FairMQMessageSHM*>(msgVec.back().get());
MetaHeader* msgHdr = static_cast<MetaHeader*>(zmq_msg_data(msg->GetMessage())); MetaHeader* msgHdr = static_cast<MetaHeader*>(zmq_msg_data(msg->GetMessage()));
@@ -390,7 +404,7 @@ int64_t FairMQSocketSHM::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int
{ {
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0)) if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
{ {
if (timeout) if (timeout > 0)
{ {
elapsed += fRcvTimeout; elapsed += fRcvTimeout;
if (elapsed >= timeout) if (elapsed >= timeout)
@@ -455,12 +469,6 @@ void* FairMQSocketSHM::GetSocket() const
return fSocket; return fSocket;
} }
int FairMQSocketSHM::GetSocket(int) const
{
// dummy method to comply with the interface. functionality not possible in zeromq.
return -1;
}
void FairMQSocketSHM::SetOption(const string& option, const void* value, size_t valueSize) void FairMQSocketSHM::SetOption(const string& option, const void* value, size_t valueSize)
{ {
if (zmq_setsockopt(fSocket, GetConstant(option), value, valueSize) < 0) if (zmq_setsockopt(fSocket, GetConstant(option), value, valueSize) < 0)
@@ -477,6 +485,91 @@ void FairMQSocketSHM::GetOption(const string& option, void* value, size_t* value
} }
} }
void FairMQSocketSHM::SetLinger(const int value)
{
if (zmq_setsockopt(fSocket, ZMQ_LINGER, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed setting ZMQ_LINGER, reason: ", zmq_strerror(errno)));
}
}
int FairMQSocketSHM::GetLinger() const
{
int value = 0;
size_t valueSize = sizeof(value);
if (zmq_getsockopt(fSocket, ZMQ_LINGER, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_LINGER, reason: ", zmq_strerror(errno)));
}
return value;
}
void FairMQSocketSHM::SetSndBufSize(const int value)
{
if (zmq_setsockopt(fSocket, ZMQ_SNDHWM, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed setting ZMQ_SNDHWM, reason: ", zmq_strerror(errno)));
}
}
int FairMQSocketSHM::GetSndBufSize() const
{
int value = 0;
size_t valueSize = sizeof(value);
if (zmq_getsockopt(fSocket, ZMQ_SNDHWM, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_SNDHWM, reason: ", zmq_strerror(errno)));
}
return value;
}
void FairMQSocketSHM::SetRcvBufSize(const int value)
{
if (zmq_setsockopt(fSocket, ZMQ_RCVHWM, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed setting ZMQ_RCVHWM, reason: ", zmq_strerror(errno)));
}
}
int FairMQSocketSHM::GetRcvBufSize() const
{
int value = 0;
size_t valueSize = sizeof(value);
if (zmq_getsockopt(fSocket, ZMQ_RCVHWM, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_RCVHWM, reason: ", zmq_strerror(errno)));
}
return value;
}
void FairMQSocketSHM::SetSndKernelSize(const int value)
{
if (zmq_setsockopt(fSocket, ZMQ_SNDBUF, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_SNDBUF, reason: ", zmq_strerror(errno)));
}
}
int FairMQSocketSHM::GetSndKernelSize() const
{
int value = 0;
size_t valueSize = sizeof(value);
if (zmq_getsockopt(fSocket, ZMQ_SNDBUF, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_SNDBUF, reason: ", zmq_strerror(errno)));
}
return value;
}
void FairMQSocketSHM::SetRcvKernelSize(const int value)
{
if (zmq_setsockopt(fSocket, ZMQ_RCVBUF, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_RCVBUF, reason: ", zmq_strerror(errno)));
}
}
int FairMQSocketSHM::GetRcvKernelSize() const
{
int value = 0;
size_t valueSize = sizeof(value);
if (zmq_getsockopt(fSocket, ZMQ_RCVBUF, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_RCVBUF, reason: ", zmq_strerror(errno)));
}
return value;
}
unsigned long FairMQSocketSHM::GetBytesTx() const unsigned long FairMQSocketSHM::GetBytesTx() const
{ {
return fBytesTx; return fBytesTx;
@@ -497,112 +590,6 @@ unsigned long FairMQSocketSHM::GetMessagesRx() const
return fMessagesRx; return fMessagesRx;
} }
bool FairMQSocketSHM::SetSendTimeout(const int timeout, const string& address, const string& method)
{
fSndTimeout = timeout;
if (method == "bind")
{
if (zmq_unbind(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed unbinding socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_setsockopt(fSocket, ZMQ_SNDTIMEO, &fSndTimeout, sizeof(fSndTimeout)) != 0)
{
LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_bind(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed binding socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
}
else if (method == "connect")
{
if (zmq_disconnect(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed disconnecting socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_setsockopt(fSocket, ZMQ_SNDTIMEO, &fSndTimeout, sizeof(fSndTimeout)) != 0)
{
LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_connect(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed connecting socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
}
else
{
LOG(error) << "timeout failed - unknown method provided!";
return false;
}
return true;
}
int FairMQSocketSHM::GetSendTimeout() const
{
return fSndTimeout;
}
bool FairMQSocketSHM::SetReceiveTimeout(const int timeout, const string& address, const string& method)
{
fRcvTimeout = timeout;
if (method == "bind")
{
if (zmq_unbind(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed unbinding socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_setsockopt(fSocket, ZMQ_RCVTIMEO, &fRcvTimeout, sizeof(fRcvTimeout)) != 0)
{
LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_bind(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed binding socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
}
else if (method == "connect")
{
if (zmq_disconnect(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed disconnecting socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_setsockopt(fSocket, ZMQ_RCVTIMEO, &fRcvTimeout, sizeof(fRcvTimeout)) != 0)
{
LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_connect(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed connecting socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
}
else
{
LOG(error) << "timeout failed - unknown method provided!";
return false;
}
return true;
}
int FairMQSocketSHM::GetReceiveTimeout() const
{
return fRcvTimeout;
}
int FairMQSocketSHM::GetConstant(const string& constant) int FairMQSocketSHM::GetConstant(const string& constant)
{ {
if (constant == "") return 0; if (constant == "") return 0;

View File

@@ -15,31 +15,26 @@
#include <atomic> #include <atomic>
#include <memory> // unique_ptr #include <memory> // unique_ptr
class FairMQTransportFactory;
class FairMQSocketSHM : public FairMQSocket class FairMQSocketSHM final : public FairMQSocket
{ {
public: public:
FairMQSocketSHM(fair::mq::shmem::Manager& manager, const std::string& type, const std::string& name, const std::string& id = "", void* context = nullptr); FairMQSocketSHM(fair::mq::shmem::Manager& manager, const std::string& type, const std::string& name, const std::string& id = "", void* context = nullptr, FairMQTransportFactory* fac = nullptr);
FairMQSocketSHM(const FairMQSocketSHM&) = delete; FairMQSocketSHM(const FairMQSocketSHM&) = delete;
FairMQSocketSHM operator=(const FairMQSocketSHM&) = delete; FairMQSocketSHM operator=(const FairMQSocketSHM&) = delete;
std::string GetId() override { return fId; } std::string GetId() override { return fId; }
bool Bind(const std::string& address) override; bool Bind(const std::string& address) override;
void Connect(const std::string& address) override; bool Connect(const std::string& address) override;
int Send(FairMQMessagePtr& msg, const int timeout = 0) override; int Send(FairMQMessagePtr& msg, const int timeout = -1) override;
int Receive(FairMQMessagePtr& msg, const int timeout = 0) override; int Receive(FairMQMessagePtr& msg, const int timeout = -1) override;
int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override; int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override; int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
int TrySend(FairMQMessagePtr& msg) override; void* GetSocket() const;
int TryReceive(FairMQMessagePtr& msg) override;
int64_t TrySend(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
int64_t TryReceive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
void* GetSocket() const override;
int GetSocket(int nothing) const override;
void Close() override; void Close() override;
@@ -49,16 +44,22 @@ class FairMQSocketSHM : public FairMQSocket
void SetOption(const std::string& option, const void* value, size_t valueSize) override; void SetOption(const std::string& option, const void* value, size_t valueSize) override;
void GetOption(const std::string& option, void* value, size_t* valueSize) override; void GetOption(const std::string& option, void* value, size_t* valueSize) override;
void SetLinger(const int value) override;
int GetLinger() const override;
void SetSndBufSize(const int value) override;
int GetSndBufSize() const override;
void SetRcvBufSize(const int value) override;
int GetRcvBufSize() const override;
void SetSndKernelSize(const int value) override;
int GetSndKernelSize() const override;
void SetRcvKernelSize(const int value) override;
int GetRcvKernelSize() const override;
unsigned long GetBytesTx() const override; unsigned long GetBytesTx() const override;
unsigned long GetBytesRx() const override; unsigned long GetBytesRx() const override;
unsigned long GetMessagesTx() const override; unsigned long GetMessagesTx() const override;
unsigned long GetMessagesRx() const override; unsigned long GetMessagesRx() const override;
bool SetSendTimeout(const int timeout, const std::string& address, const std::string& method) override;
int GetSendTimeout() const override;
bool SetReceiveTimeout(const int timeout, const std::string& address, const std::string& method) override;
int GetReceiveTimeout() const override;
static int GetConstant(const std::string& constant); static int GetConstant(const std::string& constant);
~FairMQSocketSHM() override; ~FairMQSocketSHM() override;
@@ -76,12 +77,6 @@ class FairMQSocketSHM : public FairMQSocket
int fSndTimeout; int fSndTimeout;
int fRcvTimeout; int fRcvTimeout;
int SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
int ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
int64_t SendImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
int64_t ReceiveImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
}; };
#endif /* FAIRMQSOCKETSHM_H_ */ #endif /* FAIRMQSOCKETSHM_H_ */

View File

@@ -213,30 +213,30 @@ void FairMQTransportFactorySHM::SendHeartbeats()
} }
} }
FairMQMessagePtr FairMQTransportFactorySHM::CreateMessage() const FairMQMessagePtr FairMQTransportFactorySHM::CreateMessage()
{ {
return unique_ptr<FairMQMessage>(new FairMQMessageSHM(*fManager)); return unique_ptr<FairMQMessage>(new FairMQMessageSHM(*fManager, this));
} }
FairMQMessagePtr FairMQTransportFactorySHM::CreateMessage(const size_t size) const FairMQMessagePtr FairMQTransportFactorySHM::CreateMessage(const size_t size)
{ {
return unique_ptr<FairMQMessage>(new FairMQMessageSHM(*fManager, size)); return unique_ptr<FairMQMessage>(new FairMQMessageSHM(*fManager, size, this));
} }
FairMQMessagePtr FairMQTransportFactorySHM::CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint) const FairMQMessagePtr FairMQTransportFactorySHM::CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint)
{ {
return unique_ptr<FairMQMessage>(new FairMQMessageSHM(*fManager, data, size, ffn, hint)); return unique_ptr<FairMQMessage>(new FairMQMessageSHM(*fManager, data, size, ffn, hint, this));
} }
FairMQMessagePtr FairMQTransportFactorySHM::CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint) const FairMQMessagePtr FairMQTransportFactorySHM::CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint)
{ {
return unique_ptr<FairMQMessage>(new FairMQMessageSHM(*fManager, region, data, size, hint)); return unique_ptr<FairMQMessage>(new FairMQMessageSHM(*fManager, region, data, size, hint, this));
} }
FairMQSocketPtr FairMQTransportFactorySHM::CreateSocket(const string& type, const string& name) const FairMQSocketPtr FairMQTransportFactorySHM::CreateSocket(const string& type, const string& name)
{ {
assert(fContext); assert(fContext);
return unique_ptr<FairMQSocket>(new FairMQSocketSHM(*fManager, type, name, GetId(), fContext)); return unique_ptr<FairMQSocket>(new FairMQSocketSHM(*fManager, type, name, GetId(), fContext, this));
} }
FairMQPollerPtr FairMQTransportFactorySHM::CreatePoller(const vector<FairMQChannel>& channels) const FairMQPollerPtr FairMQTransportFactorySHM::CreatePoller(const vector<FairMQChannel>& channels) const
@@ -244,7 +244,7 @@ FairMQPollerPtr FairMQTransportFactorySHM::CreatePoller(const vector<FairMQChann
return unique_ptr<FairMQPoller>(new FairMQPollerSHM(channels)); return unique_ptr<FairMQPoller>(new FairMQPollerSHM(channels));
} }
FairMQPollerPtr FairMQTransportFactorySHM::CreatePoller(const vector<const FairMQChannel*>& channels) const FairMQPollerPtr FairMQTransportFactorySHM::CreatePoller(const vector<FairMQChannel*>& channels) const
{ {
return unique_ptr<FairMQPoller>(new FairMQPollerSHM(channels)); return unique_ptr<FairMQPoller>(new FairMQPollerSHM(channels));
} }
@@ -254,11 +254,6 @@ FairMQPollerPtr FairMQTransportFactorySHM::CreatePoller(const unordered_map<stri
return unique_ptr<FairMQPoller>(new FairMQPollerSHM(channelsMap, channelList)); return unique_ptr<FairMQPoller>(new FairMQPollerSHM(channelsMap, channelList));
} }
FairMQPollerPtr FairMQTransportFactorySHM::CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const
{
return unique_ptr<FairMQPoller>(new FairMQPollerSHM(cmdSocket, dataSocket));
}
FairMQUnmanagedRegionPtr FairMQTransportFactorySHM::CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const FairMQUnmanagedRegionPtr FairMQTransportFactorySHM::CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const
{ {
return unique_ptr<FairMQUnmanagedRegion>(new FairMQUnmanagedRegionSHM(*fManager, size, callback)); return unique_ptr<FairMQUnmanagedRegion>(new FairMQUnmanagedRegionSHM(*fManager, size, callback));

View File

@@ -26,24 +26,23 @@
#include <thread> #include <thread>
#include <atomic> #include <atomic>
class FairMQTransportFactorySHM : public FairMQTransportFactory class FairMQTransportFactorySHM final : public FairMQTransportFactory
{ {
public: public:
FairMQTransportFactorySHM(const std::string& id = "", const FairMQProgOptions* config = nullptr); FairMQTransportFactorySHM(const std::string& id = "", const FairMQProgOptions* config = nullptr);
FairMQTransportFactorySHM(const FairMQTransportFactorySHM&) = delete; FairMQTransportFactorySHM(const FairMQTransportFactorySHM&) = delete;
FairMQTransportFactorySHM operator=(const FairMQTransportFactorySHM&) = delete; FairMQTransportFactorySHM operator=(const FairMQTransportFactorySHM&) = delete;
FairMQMessagePtr CreateMessage() const override; FairMQMessagePtr CreateMessage() override;
FairMQMessagePtr CreateMessage(const size_t size) const override; FairMQMessagePtr CreateMessage(const size_t size) override;
FairMQMessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) const override; FairMQMessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) override;
FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0) const override; FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0) override;
FairMQSocketPtr CreateSocket(const std::string& type, const std::string& name) const override; FairMQSocketPtr CreateSocket(const std::string& type, const std::string& name) override;
FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel>& channels) const override; FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel>& channels) const override;
FairMQPollerPtr CreatePoller(const std::vector<const FairMQChannel*>& channels) const override; FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel*>& channels) const override;
FairMQPollerPtr CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const override; FairMQPollerPtr CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const override;
FairMQPollerPtr CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const override;
FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback = nullptr) const override; FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback = nullptr) const override;
@@ -51,6 +50,7 @@ class FairMQTransportFactorySHM : public FairMQTransportFactory
void Interrupt() override { FairMQSocketSHM::Interrupt(); } void Interrupt() override { FairMQSocketSHM::Interrupt(); }
void Resume() override { FairMQSocketSHM::Resume(); } void Resume() override { FairMQSocketSHM::Resume(); }
void Reset() override {}
~FairMQTransportFactorySHM() override; ~FairMQTransportFactorySHM() override;

View File

@@ -19,7 +19,7 @@
#include <cstddef> // size_t #include <cstddef> // size_t
class FairMQUnmanagedRegionSHM : public FairMQUnmanagedRegion class FairMQUnmanagedRegionSHM final : public FairMQUnmanagedRegion
{ {
friend class FairMQSocketSHM; friend class FairMQSocketSHM;
friend class FairMQMessageSHM; friend class FairMQMessageSHM;

View File

@@ -443,9 +443,9 @@ void Monitor::PrintQueues()
{ {
cout << "found " << queues->size() << " queue(s):" << endl; cout << "found " << queues->size() << " queue(s):" << endl;
for (unsigned int i = 0; i < queues->size(); ++i) for (const auto& queue : *queues)
{ {
string name(queues->at(i).c_str()); string name(queue.c_str());
cout << '\t' << name << " : "; cout << '\t' << name << " : ";
atomic<int>* queueSize = segment.find<atomic<int>>(name.c_str()).first; atomic<int>* queueSize = segment.find<atomic<int>>(name.c_str()).first;
if (queueSize) if (queueSize)

View File

@@ -28,6 +28,7 @@
#include <iostream> #include <iostream>
#include <array> #include <array>
#include <exception> #include <exception>
#include <stdexcept>
#include <algorithm> #include <algorithm>
using namespace std; using namespace std;
@@ -40,54 +41,52 @@ namespace tools
{ {
// returns a map with network interface names as keys and their IP addresses as values // returns a map with network interface names as keys and their IP addresses as values
int getHostIPs(map<string, string>& addressMap) map<string, string> getHostIPs()
{ {
map<string, string> addressMap;
struct ifaddrs *ifaddr, *ifa; struct ifaddrs *ifaddr, *ifa;
int s; int s;
char host[NI_MAXHOST]; char host[NI_MAXHOST];
if (getifaddrs(&ifaddr) == -1) if (getifaddrs(&ifaddr) == -1) {
{
perror("getifaddrs"); perror("getifaddrs");
return -1; throw runtime_error("getifaddrs failed");
} }
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) {
{ if (ifa->ifa_addr == nullptr) {
if (ifa->ifa_addr == NULL)
{
continue; continue;
} }
if (ifa->ifa_addr->sa_family == AF_INET) if (ifa->ifa_addr->sa_family == AF_INET) {
{ s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, nullptr, 0, NI_NUMERICHOST);
s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); if (s != 0) {
if (s != 0)
{
cout << "getnameinfo() failed: " << gai_strerror(s) << endl; cout << "getnameinfo() failed: " << gai_strerror(s) << endl;
return -1; throw runtime_error("getnameinfo() failed");
} }
addressMap.insert(pair<string, string>(ifa->ifa_name, host)); addressMap.insert(pair<string, string>(ifa->ifa_name, host));
} }
} }
freeifaddrs(ifaddr); freeifaddrs(ifaddr);
return 0; return addressMap;
} }
// get IP address of a given interface name // get IP address of a given interface name
string getInterfaceIP(const string& interface) string getInterfaceIP(const string& interface)
{ {
map<string, string> IPs; try {
getHostIPs(IPs); auto IPs = getHostIPs();
if (IPs.count(interface)) if (IPs.count(interface)) {
{ return IPs[interface];
return IPs[interface]; } else {
} LOG(error) << "Could not find provided network interface: \"" << interface << "\"!, exiting.";
else return "";
{ }
LOG(error) << "Could not find provided network interface: \"" << interface << "\"!, exiting."; } catch (runtime_error& re) {
cout << "could not get interface IP: " << re.what();
return ""; return "";
} }
} }
@@ -104,28 +103,22 @@ string getDefaultRouteNetworkInterface()
unique_ptr<FILE, decltype(pclose) *> file(popen("ip route | grep default | cut -d \" \" -f 5 | head -n 1", "r"), pclose); unique_ptr<FILE, decltype(pclose) *> file(popen("ip route | grep default | cut -d \" \" -f 5 | head -n 1", "r"), pclose);
#endif #endif
if (!file) if (!file) {
{
LOG(error) << "Could not detect default route network interface name - popen() failed!"; LOG(error) << "Could not detect default route network interface name - popen() failed!";
return ""; return "";
} }
while (!feof(file.get())) while (!feof(file.get())) {
{ if (fgets(buffer.data(), 128, file.get()) != nullptr) {
if (fgets(buffer.data(), 128, file.get()) != NULL)
{
interfaceName += buffer.data(); interfaceName += buffer.data();
} }
} }
boost::algorithm::trim(interfaceName); boost::algorithm::trim(interfaceName);
if (interfaceName == "") if (interfaceName == "") {
{
LOG(error) << "Could not detect default route network interface name"; LOG(error) << "Could not detect default route network interface name";
} } else {
else
{
LOG(debug) << "Detected network interface name for the default route: " << interfaceName; LOG(debug) << "Detected network interface name for the default route: " << interfaceName;
} }
@@ -134,30 +127,8 @@ string getDefaultRouteNetworkInterface()
string getIpFromHostname(const string& hostname) string getIpFromHostname(const string& hostname)
{ {
try { boost::asio::io_service ios;
namespace bai = boost::asio::ip; return getIpFromHostname(hostname, ios);
boost::asio::io_service ios;
bai::tcp::resolver resolver(ios);
bai::tcp::resolver::query query(hostname, "");
bai::tcp::resolver::iterator end;
auto it = find_if(static_cast<bai::basic_resolver_iterator<bai::tcp>>(resolver.resolve(query)), end, [](const bai::tcp::endpoint& ep) {
return ep.address().is_v4();
});
if (it != end) {
stringstream ss;
ss << static_cast<bai::tcp::endpoint>(*it).address();
return ss.str();
}
LOG(warn) << "could not find ipv4 address for hostname '" << hostname << "'";
return "";
} catch (exception& e) {
LOG(error) << "could not resolve hostname '" << hostname << "', reason: " << e.what();
return "";
}
} }
string getIpFromHostname(const string& hostname, boost::asio::io_service& ios) string getIpFromHostname(const string& hostname, boost::asio::io_service& ios)

View File

@@ -32,7 +32,7 @@ namespace tools
{ {
// returns a map with network interface names as keys and their IP addresses as values // returns a map with network interface names as keys and their IP addresses as values
int getHostIPs(std::map<std::string, std::string>& addressMap); std::map<std::string, std::string> getHostIPs();
// get IP address of a given interface name // get IP address of a given interface name
std::string getInterfaceIP(const std::string& interface); std::string getInterfaceIP(const std::string& interface);

View File

@@ -13,8 +13,10 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <thread> #include <thread>
#include <stdexcept>
using namespace std; using namespace std;
namespace bp = boost::process;
namespace fair namespace fair
{ {
@@ -44,10 +46,17 @@ execute_result execute(const string& cmd, const string& prefix, const string& in
out << prefix << cmd << endl; out << prefix << cmd << endl;
// Execute command and capture stdout, add prefix line by line // Execute command and capture stdout, add prefix line by line
boost::process::ipstream c_stdout; bp::ipstream c_stdout;
boost::process::opstream c_stdin; bp::opstream c_stdin;
boost::process::child c( bp::child c(cmd, bp::std_out > c_stdout, bp::std_in < c_stdin);
cmd, boost::process::std_out > c_stdout, boost::process::std_in < c_stdin);
while (c.valid() && !c.running()) {
;
}
if (!c.valid()) {
throw runtime_error("Can't execute the given process.");
}
// Optionally, write to stdin of the child // Optionally, write to stdin of the child
if (input != "") { if (input != "") {
@@ -57,8 +66,7 @@ execute_result execute(const string& cmd, const string& prefix, const string& in
} }
string line; string line;
while (getline(c_stdout, line)) while (c.running() && getline(c_stdout, line)) {
{
// print full line thread-safe // print full line thread-safe
stringstream printLine; stringstream printLine;
printLine << prefix << line << "\n"; printLine << prefix << line << "\n";

View File

@@ -8,6 +8,10 @@
#include <fairmq/tools/Unique.h> #include <fairmq/tools/Unique.h>
// We have to force boost::uuids to rely on /dev/*random instead of getrandom(2) or getentropy(3)
// otherwise on some systems we'd get boost::uuids::entropy_error
#define BOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX
#include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp> #include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp> #include <boost/uuid/uuid_io.hpp>

View File

@@ -17,6 +17,7 @@
#include "FairMQLogger.h" #include "FairMQLogger.h"
#include <fairmq/Tools.h> #include <fairmq/Tools.h>
#include "FairMQUnmanagedRegionZMQ.h" #include "FairMQUnmanagedRegionZMQ.h"
#include <FairMQTransportFactory.h>
#include <cstring> #include <cstring>
@@ -24,8 +25,9 @@ using namespace std;
fair::mq::Transport FairMQMessageZMQ::fTransportType = fair::mq::Transport::ZMQ; fair::mq::Transport FairMQMessageZMQ::fTransportType = fair::mq::Transport::ZMQ;
FairMQMessageZMQ::FairMQMessageZMQ() FairMQMessageZMQ::FairMQMessageZMQ(FairMQTransportFactory* factory)
: fUsedSizeModified(false) : FairMQMessage{factory}
, fUsedSizeModified(false)
, fUsedSize() , fUsedSize()
, fMsg(fair::mq::tools::make_unique<zmq_msg_t>()) , fMsg(fair::mq::tools::make_unique<zmq_msg_t>())
, fViewMsg(nullptr) , fViewMsg(nullptr)
@@ -36,8 +38,9 @@ FairMQMessageZMQ::FairMQMessageZMQ()
} }
} }
FairMQMessageZMQ::FairMQMessageZMQ(const size_t size) FairMQMessageZMQ::FairMQMessageZMQ(const size_t size, FairMQTransportFactory* factory)
: fUsedSizeModified(false) : FairMQMessage{factory}
, fUsedSizeModified(false)
, fUsedSize(size) , fUsedSize(size)
, fMsg(fair::mq::tools::make_unique<zmq_msg_t>()) , fMsg(fair::mq::tools::make_unique<zmq_msg_t>())
, fViewMsg(nullptr) , fViewMsg(nullptr)
@@ -48,8 +51,9 @@ FairMQMessageZMQ::FairMQMessageZMQ(const size_t size)
} }
} }
FairMQMessageZMQ::FairMQMessageZMQ(void* data, const size_t size, fairmq_free_fn* ffn, void* hint) FairMQMessageZMQ::FairMQMessageZMQ(void* data, const size_t size, fairmq_free_fn* ffn, void* hint, FairMQTransportFactory* factory)
: fUsedSizeModified(false) : FairMQMessage{factory}
, fUsedSizeModified(false)
, fUsedSize() , fUsedSize()
, fMsg(fair::mq::tools::make_unique<zmq_msg_t>()) , fMsg(fair::mq::tools::make_unique<zmq_msg_t>())
, fViewMsg(nullptr) , fViewMsg(nullptr)
@@ -60,8 +64,9 @@ FairMQMessageZMQ::FairMQMessageZMQ(void* data, const size_t size, fairmq_free_fn
} }
} }
FairMQMessageZMQ::FairMQMessageZMQ(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint) FairMQMessageZMQ::FairMQMessageZMQ(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint, FairMQTransportFactory* factory)
: fUsedSizeModified(false) : FairMQMessage{factory}
, fUsedSizeModified(false)
, fUsedSize() , fUsedSize()
, fMsg(fair::mq::tools::make_unique<zmq_msg_t>()) , fMsg(fair::mq::tools::make_unique<zmq_msg_t>())
, fViewMsg(nullptr) , fViewMsg(nullptr)
@@ -215,24 +220,6 @@ void FairMQMessageZMQ::Copy(const FairMQMessage& msg)
} }
} }
void FairMQMessageZMQ::Copy(const FairMQMessagePtr& msg)
{
FairMQMessageZMQ* msgPtr = static_cast<FairMQMessageZMQ*>(msg.get());
// Shares the message buffer between msg and this fMsg.
if (zmq_msg_copy(fMsg.get(), msgPtr->GetMessage()) != 0)
{
LOG(error) << "failed copying message, reason: " << zmq_strerror(errno);
return;
}
// if the target message has been resized, apply same to this message also
if (msgPtr->fUsedSizeModified)
{
fUsedSizeModified = true;
fUsedSize = msgPtr->fUsedSize;
}
}
void FairMQMessageZMQ::CloseMessage() void FairMQMessageZMQ::CloseMessage()
{ {
if (!fViewMsg) if (!fViewMsg)

View File

@@ -23,18 +23,19 @@
#include "FairMQMessage.h" #include "FairMQMessage.h"
#include "FairMQUnmanagedRegion.h" #include "FairMQUnmanagedRegion.h"
class FairMQTransportFactory;
class FairMQSocketZMQ; class FairMQSocketZMQ;
class FairMQMessageZMQ : public FairMQMessage class FairMQMessageZMQ final : public FairMQMessage
{ {
friend class FairMQSocketZMQ; friend class FairMQSocketZMQ;
public: public:
FairMQMessageZMQ(); FairMQMessageZMQ(FairMQTransportFactory* = nullptr);
FairMQMessageZMQ(const size_t size); FairMQMessageZMQ(const size_t size, FairMQTransportFactory* = nullptr);
FairMQMessageZMQ(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr); FairMQMessageZMQ(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr, FairMQTransportFactory* = nullptr);
FairMQMessageZMQ(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0); FairMQMessageZMQ(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0, FairMQTransportFactory* = nullptr);
void Rebuild() override; void Rebuild() override;
void Rebuild(const size_t size) override; void Rebuild(const size_t size) override;
@@ -48,7 +49,6 @@ class FairMQMessageZMQ : public FairMQMessage
fair::mq::Transport GetType() const override; fair::mq::Transport GetType() const override;
void Copy(const FairMQMessagePtr& msg) override;
void Copy(const FairMQMessage& msg) override; void Copy(const FairMQMessage& msg) override;
~FairMQMessageZMQ() override; ~FairMQMessageZMQ() override;

View File

@@ -15,6 +15,7 @@
#include <zmq.h> #include <zmq.h>
#include "FairMQPollerZMQ.h" #include "FairMQPollerZMQ.h"
#include "FairMQSocketZMQ.h"
#include "FairMQLogger.h" #include "FairMQLogger.h"
using namespace std; using namespace std;
@@ -29,20 +30,20 @@ FairMQPollerZMQ::FairMQPollerZMQ(const vector<FairMQChannel>& channels)
for (int i = 0; i < fNumItems; ++i) for (int i = 0; i < fNumItems; ++i)
{ {
fItems[i].socket = channels.at(i).GetSocket().GetSocket(); fItems[i].socket = static_cast<const FairMQSocketZMQ*>(&(channels.at(i).GetSocket()))->GetSocket();
fItems[i].fd = 0; fItems[i].fd = 0;
fItems[i].revents = 0; fItems[i].revents = 0;
int type = 0; int type = 0;
size_t size = sizeof(type); size_t size = sizeof(type);
zmq_getsockopt(channels.at(i).GetSocket().GetSocket(), ZMQ_TYPE, &type, &size); zmq_getsockopt(static_cast<const FairMQSocketZMQ*>(&(channels.at(i).GetSocket()))->GetSocket(), ZMQ_TYPE, &type, &size);
SetItemEvents(fItems[i], type); SetItemEvents(fItems[i], type);
} }
} }
FairMQPollerZMQ::FairMQPollerZMQ(const std::vector<const FairMQChannel*>& channels) FairMQPollerZMQ::FairMQPollerZMQ(const std::vector<FairMQChannel*>& channels)
: fItems() : fItems()
, fNumItems(0) , fNumItems(0)
, fOffsetMap() , fOffsetMap()
@@ -52,13 +53,13 @@ FairMQPollerZMQ::FairMQPollerZMQ(const std::vector<const FairMQChannel*>& channe
for (int i = 0; i < fNumItems; ++i) for (int i = 0; i < fNumItems; ++i)
{ {
fItems[i].socket = channels.at(i)->GetSocket().GetSocket(); fItems[i].socket = static_cast<const FairMQSocketZMQ*>(&(channels.at(i)->GetSocket()))->GetSocket();
fItems[i].fd = 0; fItems[i].fd = 0;
fItems[i].revents = 0; fItems[i].revents = 0;
int type = 0; int type = 0;
size_t size = sizeof(type); size_t size = sizeof(type);
zmq_getsockopt(channels.at(i)->GetSocket().GetSocket(), ZMQ_TYPE, &type, &size); zmq_getsockopt(static_cast<const FairMQSocketZMQ*>(&(channels.at(i)->GetSocket()))->GetSocket(), ZMQ_TYPE, &type, &size);
SetItemEvents(fItems[i], type); SetItemEvents(fItems[i], type);
} }
@@ -89,13 +90,13 @@ FairMQPollerZMQ::FairMQPollerZMQ(const unordered_map<string, vector<FairMQChanne
{ {
index = fOffsetMap[channel] + i; index = fOffsetMap[channel] + i;
fItems[index].socket = channelsMap.at(channel).at(i).GetSocket().GetSocket(); fItems[index].socket = static_cast<const FairMQSocketZMQ*>(&(channelsMap.at(channel).at(i).GetSocket()))->GetSocket();
fItems[index].fd = 0; fItems[index].fd = 0;
fItems[index].revents = 0; fItems[index].revents = 0;
int type = 0; int type = 0;
size_t size = sizeof(type); size_t size = sizeof(type);
zmq_getsockopt(channelsMap.at(channel).at(i).GetSocket().GetSocket(), ZMQ_TYPE, &type, &size); zmq_getsockopt(static_cast<const FairMQSocketZMQ*>(&(channelsMap.at(channel).at(i).GetSocket()))->GetSocket(), ZMQ_TYPE, &type, &size);
SetItemEvents(fItems[index], type); SetItemEvents(fItems[index], type);
} }
@@ -109,29 +110,6 @@ FairMQPollerZMQ::FairMQPollerZMQ(const unordered_map<string, vector<FairMQChanne
} }
} }
FairMQPollerZMQ::FairMQPollerZMQ(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket)
: fItems()
, fNumItems(2)
, fOffsetMap()
{
fItems = new zmq_pollitem_t[fNumItems];
fItems[0].socket = cmdSocket.GetSocket();
fItems[0].fd = 0;
fItems[0].events = ZMQ_POLLIN;
fItems[0].revents = 0;
fItems[1].socket = dataSocket.GetSocket();
fItems[1].fd = 0;
fItems[1].revents = 0;
int type = 0;
size_t size = sizeof(type);
zmq_getsockopt(dataSocket.GetSocket(), ZMQ_TYPE, &type, &size);
SetItemEvents(fItems[1], type);
}
void FairMQPollerZMQ::SetItemEvents(zmq_pollitem_t& item, const int type) void FairMQPollerZMQ::SetItemEvents(zmq_pollitem_t& item, const int type)
{ {
if (type == ZMQ_REQ || type == ZMQ_REP || type == ZMQ_PAIR || type == ZMQ_DEALER || type == ZMQ_ROUTER) if (type == ZMQ_REQ || type == ZMQ_REP || type == ZMQ_PAIR || type == ZMQ_DEALER || type == ZMQ_ROUTER)

View File

@@ -27,14 +27,14 @@
class FairMQChannel; class FairMQChannel;
class FairMQPollerZMQ : public FairMQPoller class FairMQPollerZMQ final : public FairMQPoller
{ {
friend class FairMQChannel; friend class FairMQChannel;
friend class FairMQTransportFactoryZMQ; friend class FairMQTransportFactoryZMQ;
public: public:
FairMQPollerZMQ(const std::vector<FairMQChannel>& channels); FairMQPollerZMQ(const std::vector<FairMQChannel>& channels);
FairMQPollerZMQ(const std::vector<const FairMQChannel*>& channels); FairMQPollerZMQ(const std::vector<FairMQChannel*>& channels);
FairMQPollerZMQ(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList); FairMQPollerZMQ(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList);
FairMQPollerZMQ(const FairMQPollerZMQ&) = delete; FairMQPollerZMQ(const FairMQPollerZMQ&) = delete;
@@ -42,17 +42,15 @@ class FairMQPollerZMQ : public FairMQPoller
void SetItemEvents(zmq_pollitem_t& item, const int type); void SetItemEvents(zmq_pollitem_t& item, const int type);
virtual void Poll(const int timeout); void Poll(const int timeout) override;
virtual bool CheckInput(const int index); bool CheckInput(const int index) override;
virtual bool CheckOutput(const int index); bool CheckOutput(const int index) override;
virtual bool CheckInput(const std::string& channelKey, const int index); bool CheckInput(const std::string& channelKey, const int index) override;
virtual bool CheckOutput(const std::string& channelKey, const int index); bool CheckOutput(const std::string& channelKey, const int index) override;
virtual ~FairMQPollerZMQ(); ~FairMQPollerZMQ() override;
private: private:
FairMQPollerZMQ(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket);
zmq_pollitem_t* fItems; zmq_pollitem_t* fItems;
int fNumItems; int fNumItems;

View File

@@ -9,17 +9,20 @@
#include "FairMQSocketZMQ.h" #include "FairMQSocketZMQ.h"
#include "FairMQMessageZMQ.h" #include "FairMQMessageZMQ.h"
#include "FairMQLogger.h" #include "FairMQLogger.h"
#include <fairmq/Tools.h>
#include <zmq.h> #include <zmq.h>
#include <cassert> #include <cassert>
using namespace std; using namespace std;
using namespace fair::mq;
atomic<bool> FairMQSocketZMQ::fInterrupted(false); atomic<bool> FairMQSocketZMQ::fInterrupted(false);
FairMQSocketZMQ::FairMQSocketZMQ(const string& type, const string& name, const string& id /*= ""*/, void* context) FairMQSocketZMQ::FairMQSocketZMQ(const string& type, const string& name, const string& id /*= ""*/, void* context, FairMQTransportFactory* fac)
: fSocket(nullptr) : FairMQSocket{fac}
, fSocket(nullptr)
, fId(id + "." + name + "." + type) , fId(id + "." + name + "." + type)
, fBytesTx(0) , fBytesTx(0)
, fBytesRx(0) , fBytesRx(0)
@@ -68,7 +71,7 @@ FairMQSocketZMQ::FairMQSocketZMQ(const string& type, const string& name, const s
} }
} }
// LOG(info) << "created socket " << fId; LOG(debug) << "Created socket " << GetId();
} }
string FairMQSocketZMQ::GetId() string FairMQSocketZMQ::GetId()
@@ -89,33 +92,30 @@ bool FairMQSocketZMQ::Bind(const string& address)
LOG(error) << "Failed binding socket " << fId << ", reason: " << zmq_strerror(errno); LOG(error) << "Failed binding socket " << fId << ", reason: " << zmq_strerror(errno);
return false; return false;
} }
return true; return true;
} }
void FairMQSocketZMQ::Connect(const string& address) bool FairMQSocketZMQ::Connect(const string& address)
{ {
// LOG(info) << "connect socket " << fId << " on " << address; // LOG(info) << "connect socket " << fId << " on " << address;
if (zmq_connect(fSocket, address.c_str()) != 0) if (zmq_connect(fSocket, address.c_str()) != 0)
{ {
LOG(error) << "Failed connecting socket " << fId << ", reason: " << zmq_strerror(errno); LOG(error) << "Failed connecting socket " << fId << ", reason: " << zmq_strerror(errno);
// error here means incorrect configuration. exit if it happens. return false;
exit(EXIT_FAILURE);
} }
return true;
} }
int FairMQSocketZMQ::Send(FairMQMessagePtr& msg, const int timeout) { return SendImpl(msg, 0, timeout); } int FairMQSocketZMQ::Send(FairMQMessagePtr& msg, const int timeout)
int FairMQSocketZMQ::Receive(FairMQMessagePtr& msg, const int timeout) { return ReceiveImpl(msg, 0, timeout); }
int64_t FairMQSocketZMQ::Send(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return SendImpl(msgVec, 0, timeout); }
int64_t FairMQSocketZMQ::Receive(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return ReceiveImpl(msgVec, 0, timeout); }
int FairMQSocketZMQ::TrySend(FairMQMessagePtr& msg) { return SendImpl(msg, ZMQ_DONTWAIT, 0); }
int FairMQSocketZMQ::TryReceive(FairMQMessagePtr& msg) { return ReceiveImpl(msg, ZMQ_DONTWAIT, 0); }
int64_t FairMQSocketZMQ::TrySend(vector<unique_ptr<FairMQMessage>>& msgVec) { return SendImpl(msgVec, ZMQ_DONTWAIT, 0); }
int64_t FairMQSocketZMQ::TryReceive(vector<unique_ptr<FairMQMessage>>& msgVec) { return ReceiveImpl(msgVec, ZMQ_DONTWAIT, 0); }
int FairMQSocketZMQ::SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout)
{ {
int flags = 0;
if (timeout == 0)
{
flags = ZMQ_DONTWAIT;
}
int elapsed = 0; int elapsed = 0;
static_cast<FairMQMessageZMQ*>(msg.get())->ApplyUsedSize(); static_cast<FairMQMessageZMQ*>(msg.get())->ApplyUsedSize();
@@ -134,7 +134,7 @@ int FairMQSocketZMQ::SendImpl(FairMQMessagePtr& msg, const int flags, const int
{ {
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0)) if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
{ {
if (timeout) if (timeout > 0)
{ {
elapsed += fSndTimeout; elapsed += fSndTimeout;
if (elapsed >= timeout) if (elapsed >= timeout)
@@ -162,14 +162,18 @@ int FairMQSocketZMQ::SendImpl(FairMQMessagePtr& msg, const int flags, const int
} }
} }
int FairMQSocketZMQ::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout) int FairMQSocketZMQ::Receive(FairMQMessagePtr& msg, const int timeout)
{ {
int nbytes = -1; int flags = 0;
if (timeout == 0)
{
flags = ZMQ_DONTWAIT;
}
int elapsed = 0; int elapsed = 0;
while (true) while (true)
{ {
nbytes = zmq_msg_recv(static_cast<FairMQMessageZMQ*>(msg.get())->GetMessage(), fSocket, flags); int nbytes = zmq_msg_recv(static_cast<FairMQMessageZMQ*>(msg.get())->GetMessage(), fSocket, flags);
if (nbytes >= 0) if (nbytes >= 0)
{ {
fBytesRx += nbytes; fBytesRx += nbytes;
@@ -180,7 +184,7 @@ int FairMQSocketZMQ::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const i
{ {
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0)) if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
{ {
if (timeout) if (timeout > 0)
{ {
elapsed += fRcvTimeout; elapsed += fRcvTimeout;
if (elapsed >= timeout) if (elapsed >= timeout)
@@ -208,14 +212,21 @@ int FairMQSocketZMQ::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const i
} }
} }
int64_t FairMQSocketZMQ::SendImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout) int64_t FairMQSocketZMQ::Send(vector<FairMQMessagePtr>& msgVec, const int timeout)
{ {
int flags = 0;
if (timeout == 0)
{
flags = ZMQ_DONTWAIT;
}
const unsigned int vecSize = msgVec.size(); const unsigned int vecSize = msgVec.size();
// Sending vector typicaly handles more then one part // Sending vector typicaly handles more then one part
if (vecSize > 1) if (vecSize > 1)
{ {
int elapsed = 0; int elapsed = 0;
while (true) while (true)
{ {
int64_t totalSize = 0; int64_t totalSize = 0;
@@ -239,7 +250,7 @@ int64_t FairMQSocketZMQ::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
{ {
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0)) if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
{ {
if (timeout) if (timeout > 0)
{ {
elapsed += fSndTimeout; elapsed += fSndTimeout;
if (elapsed >= timeout) if (elapsed >= timeout)
@@ -278,7 +289,7 @@ int64_t FairMQSocketZMQ::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
} // If there's only one part, send it as a regular message } // If there's only one part, send it as a regular message
else if (vecSize == 1) else if (vecSize == 1)
{ {
return SendImpl(msgVec.back(), flags, timeout); return Send(msgVec.back(), timeout);
} }
else // if the vector is empty, something might be wrong else // if the vector is empty, something might be wrong
{ {
@@ -287,8 +298,13 @@ int64_t FairMQSocketZMQ::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
} }
} }
int64_t FairMQSocketZMQ::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout) int64_t FairMQSocketZMQ::Receive(vector<FairMQMessagePtr>& msgVec, const int timeout)
{ {
int flags = 0;
if (timeout == 0)
{
flags = ZMQ_DONTWAIT;
}
int elapsed = 0; int elapsed = 0;
while (true) while (true)
@@ -299,7 +315,7 @@ int64_t FairMQSocketZMQ::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int
do do
{ {
unique_ptr<FairMQMessage> part(new FairMQMessageZMQ()); unique_ptr<FairMQMessage> part(new FairMQMessageZMQ(GetTransport()));
int nbytes = zmq_msg_recv(static_cast<FairMQMessageZMQ*>(part.get())->GetMessage(), fSocket, flags); int nbytes = zmq_msg_recv(static_cast<FairMQMessageZMQ*>(part.get())->GetMessage(), fSocket, flags);
if (nbytes >= 0) if (nbytes >= 0)
@@ -311,7 +327,7 @@ int64_t FairMQSocketZMQ::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int
{ {
if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0)) if (!fInterrupted && ((flags & ZMQ_DONTWAIT) == 0))
{ {
if (timeout) if (timeout > 0)
{ {
elapsed += fRcvTimeout; elapsed += fRcvTimeout;
if (elapsed >= timeout) if (elapsed >= timeout)
@@ -381,12 +397,6 @@ void* FairMQSocketZMQ::GetSocket() const
return fSocket; return fSocket;
} }
int FairMQSocketZMQ::GetSocket(int) const
{
// dummy method to comply with the interface. functionality not possible in zeromq.
return -1;
}
void FairMQSocketZMQ::SetOption(const string& option, const void* value, size_t valueSize) void FairMQSocketZMQ::SetOption(const string& option, const void* value, size_t valueSize)
{ {
if (zmq_setsockopt(fSocket, GetConstant(option), value, valueSize) < 0) if (zmq_setsockopt(fSocket, GetConstant(option), value, valueSize) < 0)
@@ -403,6 +413,91 @@ void FairMQSocketZMQ::GetOption(const string& option, void* value, size_t* value
} }
} }
void FairMQSocketZMQ::SetLinger(const int value)
{
if (zmq_setsockopt(fSocket, ZMQ_LINGER, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed setting ZMQ_LINGER, reason: ", zmq_strerror(errno)));
}
}
int FairMQSocketZMQ::GetLinger() const
{
int value = 0;
size_t valueSize = sizeof(value);
if (zmq_getsockopt(fSocket, ZMQ_LINGER, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_LINGER, reason: ", zmq_strerror(errno)));
}
return value;
}
void FairMQSocketZMQ::SetSndBufSize(const int value)
{
if (zmq_setsockopt(fSocket, ZMQ_SNDHWM, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed setting ZMQ_SNDHWM, reason: ", zmq_strerror(errno)));
}
}
int FairMQSocketZMQ::GetSndBufSize() const
{
int value = 0;
size_t valueSize = sizeof(value);
if (zmq_getsockopt(fSocket, ZMQ_SNDHWM, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_SNDHWM, reason: ", zmq_strerror(errno)));
}
return value;
}
void FairMQSocketZMQ::SetRcvBufSize(const int value)
{
if (zmq_setsockopt(fSocket, ZMQ_RCVHWM, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed setting ZMQ_RCVHWM, reason: ", zmq_strerror(errno)));
}
}
int FairMQSocketZMQ::GetRcvBufSize() const
{
int value = 0;
size_t valueSize = sizeof(value);
if (zmq_getsockopt(fSocket, ZMQ_RCVHWM, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_RCVHWM, reason: ", zmq_strerror(errno)));
}
return value;
}
void FairMQSocketZMQ::SetSndKernelSize(const int value)
{
if (zmq_setsockopt(fSocket, ZMQ_SNDBUF, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_SNDBUF, reason: ", zmq_strerror(errno)));
}
}
int FairMQSocketZMQ::GetSndKernelSize() const
{
int value = 0;
size_t valueSize = sizeof(value);
if (zmq_getsockopt(fSocket, ZMQ_SNDBUF, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_SNDBUF, reason: ", zmq_strerror(errno)));
}
return value;
}
void FairMQSocketZMQ::SetRcvKernelSize(const int value)
{
if (zmq_setsockopt(fSocket, ZMQ_RCVBUF, &value, sizeof(value)) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_RCVBUF, reason: ", zmq_strerror(errno)));
}
}
int FairMQSocketZMQ::GetRcvKernelSize() const
{
int value = 0;
size_t valueSize = sizeof(value);
if (zmq_getsockopt(fSocket, ZMQ_RCVBUF, &value, &valueSize) < 0) {
throw SocketError(tools::ToString("failed getting ZMQ_RCVBUF, reason: ", zmq_strerror(errno)));
}
return value;
}
unsigned long FairMQSocketZMQ::GetBytesTx() const unsigned long FairMQSocketZMQ::GetBytesTx() const
{ {
return fBytesTx; return fBytesTx;
@@ -423,112 +518,6 @@ unsigned long FairMQSocketZMQ::GetMessagesRx() const
return fMessagesRx; return fMessagesRx;
} }
bool FairMQSocketZMQ::SetSendTimeout(const int timeout, const string& address, const string& method)
{
fSndTimeout = timeout;
if (method == "bind")
{
if (zmq_unbind(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed unbinding socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_setsockopt(fSocket, ZMQ_SNDTIMEO, &fSndTimeout, sizeof(fSndTimeout)) != 0)
{
LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_bind(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed binding socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
}
else if (method == "connect")
{
if (zmq_disconnect(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed disconnecting socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_setsockopt(fSocket, ZMQ_SNDTIMEO, &fSndTimeout, sizeof(fSndTimeout)) != 0)
{
LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_connect(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed connecting socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
}
else
{
LOG(error) << "timeout failed - unknown method provided!";
return false;
}
return true;
}
int FairMQSocketZMQ::GetSendTimeout() const
{
return fSndTimeout;
}
bool FairMQSocketZMQ::SetReceiveTimeout(const int timeout, const string& address, const string& method)
{
fRcvTimeout = timeout;
if (method == "bind")
{
if (zmq_unbind(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed unbinding socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_setsockopt(fSocket, ZMQ_RCVTIMEO, &fRcvTimeout, sizeof(fRcvTimeout)) != 0)
{
LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_bind(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed binding socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
}
else if (method == "connect")
{
if (zmq_disconnect(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed disconnecting socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_setsockopt(fSocket, ZMQ_RCVTIMEO, &fRcvTimeout, sizeof(fRcvTimeout)) != 0)
{
LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
if (zmq_connect(fSocket, address.c_str()) != 0)
{
LOG(error) << "Failed connecting socket " << fId << ", reason: " << zmq_strerror(errno);
return false;
}
}
else
{
LOG(error) << "timeout failed - unknown method provided!";
return false;
}
return true;
}
int FairMQSocketZMQ::GetReceiveTimeout() const
{
return fRcvTimeout;
}
int FairMQSocketZMQ::GetConstant(const string& constant) int FairMQSocketZMQ::GetConstant(const string& constant)
{ {
if (constant == "") return 0; if (constant == "") return 0;

View File

@@ -15,31 +15,26 @@
#include "FairMQSocket.h" #include "FairMQSocket.h"
#include "FairMQMessage.h" #include "FairMQMessage.h"
class FairMQTransportFactory;
class FairMQSocketZMQ : public FairMQSocket class FairMQSocketZMQ final : public FairMQSocket
{ {
public: public:
FairMQSocketZMQ(const std::string& type, const std::string& name, const std::string& id = "", void* context = nullptr); FairMQSocketZMQ(const std::string& type, const std::string& name, const std::string& id = "", void* context = nullptr, FairMQTransportFactory* factory = nullptr);
FairMQSocketZMQ(const FairMQSocketZMQ&) = delete; FairMQSocketZMQ(const FairMQSocketZMQ&) = delete;
FairMQSocketZMQ operator=(const FairMQSocketZMQ&) = delete; FairMQSocketZMQ operator=(const FairMQSocketZMQ&) = delete;
std::string GetId() override; std::string GetId() override;
bool Bind(const std::string& address) override; bool Bind(const std::string& address) override;
void Connect(const std::string& address) override; bool Connect(const std::string& address) override;
int Send(FairMQMessagePtr& msg, const int timeout = 0) override; int Send(FairMQMessagePtr& msg, const int timeout = -1) override;
int Receive(FairMQMessagePtr& msg, const int timeout = 0) override; int Receive(FairMQMessagePtr& msg, const int timeout = -1) override;
int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override; int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override; int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
int TrySend(FairMQMessagePtr& msg) override; void* GetSocket() const;
int TryReceive(FairMQMessagePtr& msg) override;
int64_t TrySend(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
int64_t TryReceive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
void* GetSocket() const override;
int GetSocket(int nothing) const override;
void Close() override; void Close() override;
@@ -49,16 +44,22 @@ class FairMQSocketZMQ : public FairMQSocket
void SetOption(const std::string& option, const void* value, size_t valueSize) override; void SetOption(const std::string& option, const void* value, size_t valueSize) override;
void GetOption(const std::string& option, void* value, size_t* valueSize) override; void GetOption(const std::string& option, void* value, size_t* valueSize) override;
void SetLinger(const int value) override;
int GetLinger() const override;
void SetSndBufSize(const int value) override;
int GetSndBufSize() const override;
void SetRcvBufSize(const int value) override;
int GetRcvBufSize() const override;
void SetSndKernelSize(const int value) override;
int GetSndKernelSize() const override;
void SetRcvKernelSize(const int value) override;
int GetRcvKernelSize() const override;
unsigned long GetBytesTx() const override; unsigned long GetBytesTx() const override;
unsigned long GetBytesRx() const override; unsigned long GetBytesRx() const override;
unsigned long GetMessagesTx() const override; unsigned long GetMessagesTx() const override;
unsigned long GetMessagesRx() const override; unsigned long GetMessagesRx() const override;
bool SetSendTimeout(const int timeout, const std::string& address, const std::string& method) override;
int GetSendTimeout() const override;
bool SetReceiveTimeout(const int timeout, const std::string& address, const std::string& method) override;
int GetReceiveTimeout() const override;
static int GetConstant(const std::string& constant); static int GetConstant(const std::string& constant);
~FairMQSocketZMQ() override; ~FairMQSocketZMQ() override;
@@ -75,12 +76,6 @@ class FairMQSocketZMQ : public FairMQSocket
int fSndTimeout; int fSndTimeout;
int fRcvTimeout; int fRcvTimeout;
int SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
int ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
int64_t SendImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
int64_t ReceiveImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
}; };
#endif /* FAIRMQSOCKETZMQ_H_ */ #endif /* FAIRMQSOCKETZMQ_H_ */

View File

@@ -49,30 +49,30 @@ FairMQTransportFactoryZMQ::FairMQTransportFactoryZMQ(const string& id, const Fai
} }
FairMQMessagePtr FairMQTransportFactoryZMQ::CreateMessage() const FairMQMessagePtr FairMQTransportFactoryZMQ::CreateMessage()
{ {
return unique_ptr<FairMQMessage>(new FairMQMessageZMQ()); return unique_ptr<FairMQMessage>(new FairMQMessageZMQ(this));
} }
FairMQMessagePtr FairMQTransportFactoryZMQ::CreateMessage(const size_t size) const FairMQMessagePtr FairMQTransportFactoryZMQ::CreateMessage(const size_t size)
{ {
return unique_ptr<FairMQMessage>(new FairMQMessageZMQ(size)); return unique_ptr<FairMQMessage>(new FairMQMessageZMQ(size, this));
} }
FairMQMessagePtr FairMQTransportFactoryZMQ::CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint) const FairMQMessagePtr FairMQTransportFactoryZMQ::CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint)
{ {
return unique_ptr<FairMQMessage>(new FairMQMessageZMQ(data, size, ffn, hint)); return unique_ptr<FairMQMessage>(new FairMQMessageZMQ(data, size, ffn, hint, this));
} }
FairMQMessagePtr FairMQTransportFactoryZMQ::CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint) const FairMQMessagePtr FairMQTransportFactoryZMQ::CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint)
{ {
return unique_ptr<FairMQMessage>(new FairMQMessageZMQ(region, data, size, hint)); return unique_ptr<FairMQMessage>(new FairMQMessageZMQ(region, data, size, hint, this));
} }
FairMQSocketPtr FairMQTransportFactoryZMQ::CreateSocket(const string& type, const string& name) const FairMQSocketPtr FairMQTransportFactoryZMQ::CreateSocket(const string& type, const string& name)
{ {
assert(fContext); assert(fContext);
return unique_ptr<FairMQSocket>(new FairMQSocketZMQ(type, name, GetId(), fContext)); return unique_ptr<FairMQSocket>(new FairMQSocketZMQ(type, name, GetId(), fContext, this));
} }
FairMQPollerPtr FairMQTransportFactoryZMQ::CreatePoller(const vector<FairMQChannel>& channels) const FairMQPollerPtr FairMQTransportFactoryZMQ::CreatePoller(const vector<FairMQChannel>& channels) const
@@ -80,7 +80,7 @@ FairMQPollerPtr FairMQTransportFactoryZMQ::CreatePoller(const vector<FairMQChann
return unique_ptr<FairMQPoller>(new FairMQPollerZMQ(channels)); return unique_ptr<FairMQPoller>(new FairMQPollerZMQ(channels));
} }
FairMQPollerPtr FairMQTransportFactoryZMQ::CreatePoller(const std::vector<const FairMQChannel*>& channels) const FairMQPollerPtr FairMQTransportFactoryZMQ::CreatePoller(const std::vector<FairMQChannel*>& channels) const
{ {
return unique_ptr<FairMQPoller>(new FairMQPollerZMQ(channels)); return unique_ptr<FairMQPoller>(new FairMQPollerZMQ(channels));
} }
@@ -90,11 +90,6 @@ FairMQPollerPtr FairMQTransportFactoryZMQ::CreatePoller(const unordered_map<stri
return unique_ptr<FairMQPoller>(new FairMQPollerZMQ(channelsMap, channelList)); return unique_ptr<FairMQPoller>(new FairMQPollerZMQ(channelsMap, channelList));
} }
FairMQPollerPtr FairMQTransportFactoryZMQ::CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const
{
return unique_ptr<FairMQPoller>(new FairMQPollerZMQ(cmdSocket, dataSocket));
}
FairMQUnmanagedRegionPtr FairMQTransportFactoryZMQ::CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const FairMQUnmanagedRegionPtr FairMQTransportFactoryZMQ::CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const
{ {
return unique_ptr<FairMQUnmanagedRegion>(new FairMQUnmanagedRegionZMQ(size, callback)); return unique_ptr<FairMQUnmanagedRegion>(new FairMQUnmanagedRegionZMQ(size, callback));

View File

@@ -25,7 +25,7 @@
#include "FairMQUnmanagedRegionZMQ.h" #include "FairMQUnmanagedRegionZMQ.h"
#include <options/FairMQProgOptions.h> #include <options/FairMQProgOptions.h>
class FairMQTransportFactoryZMQ : public FairMQTransportFactory class FairMQTransportFactoryZMQ final : public FairMQTransportFactory
{ {
public: public:
FairMQTransportFactoryZMQ(const std::string& id = "", const FairMQProgOptions* config = nullptr); FairMQTransportFactoryZMQ(const std::string& id = "", const FairMQProgOptions* config = nullptr);
@@ -34,17 +34,16 @@ class FairMQTransportFactoryZMQ : public FairMQTransportFactory
~FairMQTransportFactoryZMQ() override; ~FairMQTransportFactoryZMQ() override;
FairMQMessagePtr CreateMessage() const override; FairMQMessagePtr CreateMessage() override;
FairMQMessagePtr CreateMessage(const size_t size) const override; FairMQMessagePtr CreateMessage(const size_t size) override;
FairMQMessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) const override; FairMQMessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) override;
FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0) const override; FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0) override;
FairMQSocketPtr CreateSocket(const std::string& type, const std::string& name) const override; FairMQSocketPtr CreateSocket(const std::string& type, const std::string& name) override;
FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel>& channels) const override; FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel>& channels) const override;
FairMQPollerPtr CreatePoller(const std::vector<const FairMQChannel*>& channels) const override; FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel*>& channels) const override;
FairMQPollerPtr CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const override; FairMQPollerPtr CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const override;
FairMQPollerPtr CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const override;
FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const override; FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const override;
@@ -52,6 +51,7 @@ class FairMQTransportFactoryZMQ : public FairMQTransportFactory
void Interrupt() override { FairMQSocketZMQ::Interrupt(); } void Interrupt() override { FairMQSocketZMQ::Interrupt(); }
void Resume() override { FairMQSocketZMQ::Resume(); } void Resume() override { FairMQSocketZMQ::Resume(); }
void Reset() override {}
private: private:
static fair::mq::Transport fTransportType; static fair::mq::Transport fTransportType;

View File

@@ -13,7 +13,7 @@
#include <cstddef> // size_t #include <cstddef> // size_t
class FairMQUnmanagedRegionZMQ : public FairMQUnmanagedRegion class FairMQUnmanagedRegionZMQ final : public FairMQUnmanagedRegion
{ {
friend class FairMQSocketZMQ; friend class FairMQSocketZMQ;
friend class FairMQMessageZMQ; friend class FairMQMessageZMQ;

View File

@@ -15,19 +15,19 @@ include(GTestHelper)
add_testhelper(runTestDevice add_testhelper(runTestDevice
SOURCES SOURCES
helper/runTestDevice.cxx helper/runTestDevice.cxx
helper/devices/TestPairLeft.cxx helper/devices/TestPairLeft.h
helper/devices/TestPairRight.cxx helper/devices/TestPairRight.h
helper/devices/TestPollIn.cxx helper/devices/TestPollIn.h
helper/devices/TestPollOut.cxx helper/devices/TestPollOut.h
helper/devices/TestPub.cxx helper/devices/TestPub.h
helper/devices/TestPull.cxx helper/devices/TestPull.h
helper/devices/TestPush.cxx helper/devices/TestPush.h
helper/devices/TestRep.cxx helper/devices/TestRep.h
helper/devices/TestReq.cxx helper/devices/TestReq.h
helper/devices/TestSub.cxx helper/devices/TestSub.h
helper/devices/TestTransferTimeout.cxx helper/devices/TestTransferTimeout.h
helper/devices/TestWaitFor.cxx helper/devices/TestWaitFor.h
helper/devices/TestExceptions.cxx helper/devices/TestExceptions.h
LINKS FairMQ LINKS FairMQ
) )
@@ -74,14 +74,14 @@ add_testsuite(FairMQ.Parts
TIMEOUT 5 TIMEOUT 5
) )
add_testsuite(FairMQ.MessageResize add_testsuite(FairMQ.Message
SOURCES SOURCES
${CMAKE_CURRENT_BINARY_DIR}/runner.cxx ${CMAKE_CURRENT_BINARY_DIR}/runner.cxx
message_resize/_message_resize.cxx message/_message.cxx
LINKS FairMQ LINKS FairMQ
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/message_resize ${CMAKE_CURRENT_SOURCE_DIR}/message
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
TIMEOUT 5 TIMEOUT 5
${definitions} ${definitions}
@@ -198,10 +198,10 @@ add_testsuite(FairMQ.StateMachine
TIMEOUT 10 TIMEOUT 10
) )
add_testsuite(FairMQ.Transport add_testsuite(FairMQ.Tools
SOURCES SOURCES
${CMAKE_CURRENT_BINARY_DIR}/runner.cxx ${CMAKE_CURRENT_BINARY_DIR}/runner.cxx
transport/_transfer_timeout.cxx tools/_network.cxx
LINKS FairMQ LINKS FairMQ
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
@@ -209,6 +209,30 @@ add_testsuite(FairMQ.Transport
TIMEOUT 10 TIMEOUT 10
) )
add_testsuite(FairMQ.Channel
SOURCES
${CMAKE_CURRENT_BINARY_DIR}/runner.cxx
channel/_channel.cxx
LINKS FairMQ
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
TIMEOUT 10
)
add_testsuite(FairMQ.Transport
SOURCES
${CMAKE_CURRENT_BINARY_DIR}/runner.cxx
transport/_transfer_timeout.cxx
transport/_options.cxx
LINKS FairMQ
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
TIMEOUT 10
${definitions}
)
add_testsuite(FairMQ.Poller add_testsuite(FairMQ.Poller
SOURCES SOURCES
${CMAKE_CURRENT_BINARY_DIR}/runner.cxx ${CMAKE_CURRENT_BINARY_DIR}/runner.cxx
@@ -218,4 +242,16 @@ add_testsuite(FairMQ.Poller
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
TIMEOUT 10 TIMEOUT 10
${definitions}
) )
add_testsuite(FairMQ.MemoryResources
SOURCES
memory_resources/runner.cxx
memory_resources/_memory_resources.cxx
LINKS FairMQ
INCLUDES ${CMAKE_CURRENT_BINARY_DIR}
TIMEOUT 10
)

96
test/channel/_channel.cxx Normal file
View File

@@ -0,0 +1,96 @@
/********************************************************************************
* Copyright (C) 2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <FairMQChannel.h>
#include <gtest/gtest.h>
#include <string>
namespace
{
using namespace std;
using namespace fair::mq;
TEST(Channel, Validation)
{
FairMQChannel channel;
ASSERT_THROW(channel.Validate(), FairMQChannel::ChannelConfigurationError);
channel.UpdateType("pair");
ASSERT_EQ(channel.Validate(), false);
ASSERT_EQ(channel.IsValid(), false);
channel.UpdateAddress("bla");
ASSERT_THROW(channel.Validate(), FairMQChannel::ChannelConfigurationError);
channel.UpdateMethod("connect");
ASSERT_EQ(channel.Validate(), false);
ASSERT_EQ(channel.IsValid(), false);
channel.UpdateAddress("ipc://");
ASSERT_EQ(channel.Validate(), false);
ASSERT_EQ(channel.IsValid(), false);
channel.UpdateAddress("verbs://");
ASSERT_EQ(channel.Validate(), false);
ASSERT_EQ(channel.IsValid(), false);
channel.UpdateAddress("inproc://");
ASSERT_EQ(channel.Validate(), false);
ASSERT_EQ(channel.IsValid(), false);
channel.UpdateAddress("tcp://");
ASSERT_EQ(channel.Validate(), false);
ASSERT_EQ(channel.IsValid(), false);
channel.UpdateAddress("tcp://localhost:5555");
ASSERT_EQ(channel.Validate(), true);
ASSERT_EQ(channel.IsValid(), true);
channel.UpdateSndBufSize(-1);
ASSERT_THROW(channel.Validate(), FairMQChannel::ChannelConfigurationError);
channel.UpdateSndBufSize(1000);
ASSERT_NO_THROW(channel.Validate());
channel.UpdateRcvBufSize(-1);
ASSERT_THROW(channel.Validate(), FairMQChannel::ChannelConfigurationError);
channel.UpdateRcvBufSize(1000);
ASSERT_NO_THROW(channel.Validate());
channel.UpdateSndKernelSize(-1);
ASSERT_THROW(channel.Validate(), FairMQChannel::ChannelConfigurationError);
channel.UpdateSndKernelSize(1000);
ASSERT_NO_THROW(channel.Validate());
channel.UpdateRcvKernelSize(-1);
ASSERT_THROW(channel.Validate(), FairMQChannel::ChannelConfigurationError);
channel.UpdateRcvKernelSize(1000);
ASSERT_NO_THROW(channel.Validate());
channel.UpdateRateLogging(-1);
ASSERT_THROW(channel.Validate(), FairMQChannel::ChannelConfigurationError);
channel.UpdateRateLogging(1);
ASSERT_NO_THROW(channel.Validate());
FairMQChannel channel2 = channel;
ASSERT_NO_THROW(channel2.Validate());
ASSERT_EQ(channel2.Validate(), true);
ASSERT_EQ(channel2.IsValid(), true);
ASSERT_EQ(channel2.Validate(), true);
channel2.UpdateChannelName("Kanal");
ASSERT_EQ(channel2.GetChannelName(), "Kanal");
channel2.ResetChannel();
ASSERT_EQ(channel2.IsValid(), false);
ASSERT_EQ(channel2.Validate(), true);
}
} /* namespace */

View File

@@ -35,11 +35,6 @@ class Receiver : public FairMQDevice
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
} }
auto Reset() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
auto Run() -> void override auto Run() -> void override
{ {
auto msg = FairMQMessagePtr{NewMessage()}; auto msg = FairMQMessagePtr{NewMessage()};

View File

@@ -35,11 +35,6 @@ class Sender : public FairMQDevice
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
} }
auto Reset() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
auto Run() -> void override auto Run() -> void override
{ {
auto msg = FairMQMessagePtr{NewMessage()}; auto msg = FairMQMessagePtr{NewMessage()};

View File

@@ -6,6 +6,9 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#ifndef FAIR_MQ_TEST_EXCEPTIONS_H
#define FAIR_MQ_TEST_EXCEPTIONS_H
#include <FairMQDevice.h> #include <FairMQDevice.h>
#include <FairMQLogger.h> #include <FairMQLogger.h>
@@ -19,7 +22,7 @@ namespace mq
namespace test namespace test
{ {
class TestExceptions : public FairMQDevice class Exceptions : public FairMQDevice
{ {
public: public:
auto Init() -> void override auto Init() -> void override
@@ -82,3 +85,5 @@ class TestExceptions : public FairMQDevice
} // namespace test } // namespace test
} // namespace mq } // namespace mq
} // namespace fair } // namespace fair
#endif /* FAIR_MQ_TEST_EXCEPTIONS_H */

View File

@@ -6,6 +6,9 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#ifndef FAIR_MQ_TEST_PAIRLEFT_H
#define FAIR_MQ_TEST_PAIRLEFT_H
#include <FairMQDevice.h> #include <FairMQDevice.h>
#include <cstddef> #include <cstddef>
@@ -26,11 +29,6 @@ class PairLeft : public FairMQDevice
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
} }
auto Reset() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
auto Run() -> void override auto Run() -> void override
{ {
int counter{0}; int counter{0};
@@ -65,3 +63,5 @@ class PairLeft : public FairMQDevice
} // namespace test } // namespace test
} // namespace mq } // namespace mq
} // namespace fair } // namespace fair
#endif /* FAIR_MQ_TEST_PAIRLEFT_H */

View File

@@ -6,6 +6,9 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#ifndef FAIR_MQ_TEST_PAIRRIGHT_H
#define FAIR_MQ_TEST_PAIRRIGHT_H
#include <FairMQDevice.h> #include <FairMQDevice.h>
#include <cstddef> #include <cstddef>
#include <string> #include <string>
@@ -26,11 +29,6 @@ class PairRight : public FairMQDevice
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
} }
auto Reset() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
auto Run() -> void override auto Run() -> void override
{ {
int counter{0}; int counter{0};
@@ -66,3 +64,5 @@ class PairRight : public FairMQDevice
} // namespace test } // namespace test
} // namespace mq } // namespace mq
} // namespace fair } // namespace fair
#endif /* FAIR_MQ_TEST_PAIRRIGHT_H */

View File

@@ -6,6 +6,9 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#ifndef FAIR_MQ_TEST_POLLIN_H
#define FAIR_MQ_TEST_POLLIN_H
#include <FairMQDevice.h> #include <FairMQDevice.h>
#include <FairMQLogger.h> #include <FairMQLogger.h>
#include <options/FairMQProgOptions.h> #include <options/FairMQProgOptions.h>
@@ -33,11 +36,6 @@ class PollIn : public FairMQDevice
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
} }
auto Reset() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
auto InitTask() -> void override auto InitTask() -> void override
{ {
fPollType = fConfig->GetValue<int>("poll-type"); fPollType = fConfig->GetValue<int>("poll-type");
@@ -45,7 +43,7 @@ class PollIn : public FairMQDevice
auto Run() -> void override auto Run() -> void override
{ {
vector<const FairMQChannel*> chans; vector<FairMQChannel*> chans;
chans.push_back(&fChannels.at("data1").at(0)); chans.push_back(&fChannels.at("data1").at(0));
chans.push_back(&fChannels.at("data2").at(0)); chans.push_back(&fChannels.at("data2").at(0));
@@ -132,3 +130,5 @@ class PollIn : public FairMQDevice
} // namespace test } // namespace test
} // namespace mq } // namespace mq
} // namespace fair } // namespace fair
#endif /* FAIR_MQ_TEST_POLLIN_H */

View File

@@ -6,6 +6,9 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#ifndef FAIR_MQ_TEST_POLLOUT_H
#define FAIR_MQ_TEST_POLLOUT_H
#include <FairMQDevice.h> #include <FairMQDevice.h>
#include <thread> #include <thread>
@@ -24,11 +27,6 @@ class PollOut : public FairMQDevice
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
} }
auto Reset() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
auto Run() -> void override auto Run() -> void override
{ {
auto msg1 = FairMQMessagePtr{NewMessage()}; auto msg1 = FairMQMessagePtr{NewMessage()};
@@ -41,3 +39,5 @@ class PollOut : public FairMQDevice
} // namespace test } // namespace test
} // namespace mq } // namespace mq
} // namespace fair } // namespace fair
#endif /* FAIR_MQ_TEST_POLLOUT_H */

View File

@@ -6,6 +6,9 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#ifndef FAIR_MQ_TEST_PUB_H
#define FAIR_MQ_TEST_PUB_H
#include <FairMQDevice.h> #include <FairMQDevice.h>
#include <FairMQLogger.h> #include <FairMQLogger.h>
#include <chrono> #include <chrono>
@@ -26,11 +29,6 @@ class Pub : public FairMQDevice
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
} }
auto Reset() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
auto Run() -> void override auto Run() -> void override
{ {
auto ready1 = FairMQMessagePtr{NewMessage()}; auto ready1 = FairMQMessagePtr{NewMessage()};
@@ -75,3 +73,5 @@ class Pub : public FairMQDevice
} // namespace test } // namespace test
} // namespace mq } // namespace mq
} // namespace fair } // namespace fair
#endif /* FAIR_MQ_TEST_PUB_H */

View File

@@ -6,6 +6,9 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#ifndef FAIR_MQ_TEST_PULL_H
#define FAIR_MQ_TEST_PULL_H
#include <FairMQDevice.h> #include <FairMQDevice.h>
#include <FairMQLogger.h> #include <FairMQLogger.h>
#include <thread> #include <thread>
@@ -27,11 +30,6 @@ class Pull : public FairMQDevice
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));
} }
auto Reset() -> void override
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
auto Run() -> void override auto Run() -> void override
{ {
auto msg = FairMQMessagePtr{NewMessage()}; auto msg = FairMQMessagePtr{NewMessage()};
@@ -46,3 +44,5 @@ class Pull : public FairMQDevice
} // namespace test } // namespace test
} // namespace mq } // namespace mq
} // namespace fair } // namespace fair
#endif /* FAIR_MQ_TEST_PULL_H */

Some files were not shown because too many files have changed in this diff Show More