mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-19 03:21:46 +00:00
Compare commits
39 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
5e4876c947 | ||
|
3b5b2b501f | ||
|
3561255cf9 | ||
|
cbab7649be | ||
|
6ac94b7bc7 | ||
|
f9658f69a4 | ||
|
34286ef75e | ||
|
1a07137dda | ||
|
1f42f49ae5 | ||
|
d40bbfe208 | ||
|
310b9647b5 | ||
|
919193a1ad | ||
|
0cfa9192d7 | ||
|
c40bd7d6a9 | ||
|
4951433330 | ||
|
1b53538d8c | ||
|
d4a4ea14d2 | ||
|
ffab4ac78c | ||
|
ce4062f3a0 | ||
|
f8824335a5 | ||
|
2e7005225e | ||
|
dfa1b68867 | ||
|
00800f16f1 | ||
|
44acd4997d | ||
|
cfb727181f | ||
|
e090967645 | ||
|
1d45095d75 | ||
|
1fdf510ae7 | ||
|
78acb954cd | ||
|
3a1b769937 | ||
|
9f325451e5 | ||
|
a78d35d90d | ||
|
cb199e7283 | ||
|
e39316c866 | ||
|
bde12f58b2 | ||
|
45354f268b | ||
|
1aab354a5d | ||
|
e1f555bc05 | ||
|
985150437a |
@@ -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)
|
||||||
|
@@ -19,7 +19,7 @@ Set(BUILD_COMMAND "make")
|
|||||||
Set(CTEST_BUILD_COMMAND "${BUILD_COMMAND} -j$ENV{number_of_processors}")
|
Set(CTEST_BUILD_COMMAND "${BUILD_COMMAND} -j$ENV{number_of_processors}")
|
||||||
|
|
||||||
String(TOUPPER $ENV{ctest_model} _Model)
|
String(TOUPPER $ENV{ctest_model} _Model)
|
||||||
Set(configure_options "-DCMAKE_BUILD_TYPE=${_Model}")
|
Set(configure_options "-DCMAKE_BUILD_TYPE=$ENV{ctest_model}")
|
||||||
|
|
||||||
Set(CTEST_USE_LAUNCHERS 1)
|
Set(CTEST_USE_LAUNCHERS 1)
|
||||||
Set(configure_options "${configure_options};-DCTEST_USE_LAUNCHERS=${CTEST_USE_LAUNCHERS}")
|
Set(configure_options "${configure_options};-DCTEST_USE_LAUNCHERS=${CTEST_USE_LAUNCHERS}")
|
||||||
|
@@ -164,12 +164,13 @@ macro(set_fairmq_defaults)
|
|||||||
set(PROJECT_EXPORT_SET ${PROJECT_NAME}Targets)
|
set(PROJECT_EXPORT_SET ${PROJECT_NAME}Targets)
|
||||||
|
|
||||||
# Configure build types
|
# Configure build types
|
||||||
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release" "RelWithDebInfo" "Nightly" "Profile" "AdressSan" "ThreadSan")
|
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release" "RelWithDebInfo" "Nightly" "Profile" "Experimental" "AdressSan" "ThreadSan")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wshadow -Wall -Wextra")
|
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wshadow -Wall -Wextra")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -Wshadow -Wall -Wextra -DNDEBUG")
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -Wshadow -Wall -Wextra -DNDEBUG")
|
||||||
set(CMAKE_CXX_FLAGS_NIGHTLY "-O2 -g -Wshadow -Wall -Wextra")
|
set(CMAKE_CXX_FLAGS_NIGHTLY "-O2 -g -Wshadow -Wall -Wextra")
|
||||||
set(CMAKE_CXX_FLAGS_PROFILE "-g3 -Wshadow -Wall -Wextra -fno-inline -ftest-coverage -fprofile-arcs")
|
set(CMAKE_CXX_FLAGS_PROFILE "-g3 -Wshadow -Wall -Wextra -fno-inline -ftest-coverage -fprofile-arcs")
|
||||||
|
set(CMAKE_CXX_FLAGS_EXPERIMENTAL "-O2 -g -Wshadow -Wall -Wextra -DNDEBUG")
|
||||||
set(CMAKE_CXX_FLAGS_ADRESSSAN "-O2 -g -Wshadow -Wall -Wextra -fsanitize=address -fno-omit-frame-pointer")
|
set(CMAKE_CXX_FLAGS_ADRESSSAN "-O2 -g -Wshadow -Wall -Wextra -fsanitize=address -fno-omit-frame-pointer")
|
||||||
set(CMAKE_CXX_FLAGS_THREADSAN "-O2 -g -Wshadow -Wall -Wextra -fsanitize=thread")
|
set(CMAKE_CXX_FLAGS_THREADSAN "-O2 -g -Wshadow -Wall -Wextra -fsanitize=thread")
|
||||||
|
|
||||||
|
@@ -8,6 +8,8 @@ if [[ $1 =~ ^[a-z]+$ ]]; then
|
|||||||
transport=$1
|
transport=$1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
SESSION="$(@CMAKE_BINARY_DIR@/fairmq/fairmq-uuid-gen -h)"
|
||||||
|
|
||||||
# setup a trap to kill everything if the test fails/timeouts
|
# setup a trap to kill everything if the test fails/timeouts
|
||||||
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK_PID; wait $SAMPLER_PID; wait $SINK_PID;' TERM
|
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK_PID; wait $SAMPLER_PID; wait $SINK_PID;' TERM
|
||||||
|
|
||||||
@@ -16,6 +18,7 @@ SAMPLER+=" --id sampler1"
|
|||||||
SAMPLER+=" --rate 1"
|
SAMPLER+=" --rate 1"
|
||||||
SAMPLER+=" --transport $transport"
|
SAMPLER+=" --transport $transport"
|
||||||
SAMPLER+=" --verbosity veryhigh"
|
SAMPLER+=" --verbosity veryhigh"
|
||||||
|
SAMPLER+=" --session $SESSION"
|
||||||
SAMPLER+=" --control static --color false"
|
SAMPLER+=" --control static --color false"
|
||||||
SAMPLER+=" --max-iterations 1"
|
SAMPLER+=" --max-iterations 1"
|
||||||
SAMPLER+=" --channel-config name=data,type=push,method=bind,address=tcp://*:5555,rateLogging=0"
|
SAMPLER+=" --channel-config name=data,type=push,method=bind,address=tcp://*:5555,rateLogging=0"
|
||||||
@@ -26,6 +29,7 @@ SINK="fairmq-ex-1-1-sink"
|
|||||||
SINK+=" --id sink1"
|
SINK+=" --id sink1"
|
||||||
SINK+=" --transport $transport"
|
SINK+=" --transport $transport"
|
||||||
SINK+=" --verbosity veryhigh"
|
SINK+=" --verbosity veryhigh"
|
||||||
|
SINK+=" --session $SESSION"
|
||||||
SINK+=" --control static --color false"
|
SINK+=" --control static --color false"
|
||||||
SINK+=" --max-iterations 1"
|
SINK+=" --max-iterations 1"
|
||||||
SINK+=" --channel-config name=data,type=pull,method=connect,address=tcp://localhost:5555,rateLogging=0"
|
SINK+=" --channel-config name=data,type=pull,method=connect,address=tcp://localhost:5555,rateLogging=0"
|
||||||
|
@@ -9,6 +9,7 @@ if [[ $1 =~ ^[a-z]+$ ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
ex2config="@CMAKE_CURRENT_BINARY_DIR@/ex-1-n-1.json"
|
ex2config="@CMAKE_CURRENT_BINARY_DIR@/ex-1-n-1.json"
|
||||||
|
SESSION="$(@CMAKE_BINARY_DIR@/fairmq/fairmq-uuid-gen -h)"
|
||||||
|
|
||||||
# setup a trap to kill everything if the test fails/timeouts
|
# setup a trap to kill everything if the test fails/timeouts
|
||||||
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK_PID; kill -TERM $PROCESSOR1_PID; kill -TERM $PROCESSOR2_PID; wait $SAMPLER_PID; wait $SINK_PID; wait $PROCESSOR1_PID; wait $PROCESSOR2_PID;' TERM
|
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK_PID; kill -TERM $PROCESSOR1_PID; kill -TERM $PROCESSOR2_PID; wait $SAMPLER_PID; wait $SINK_PID; wait $PROCESSOR1_PID; wait $PROCESSOR2_PID;' TERM
|
||||||
@@ -17,6 +18,7 @@ SAMPLER="fairmq-ex-1-n-1-sampler"
|
|||||||
SAMPLER+=" --id sampler1"
|
SAMPLER+=" --id sampler1"
|
||||||
SAMPLER+=" --transport $transport"
|
SAMPLER+=" --transport $transport"
|
||||||
SAMPLER+=" --verbosity veryhigh"
|
SAMPLER+=" --verbosity veryhigh"
|
||||||
|
SAMPLER+=" --session $SESSION"
|
||||||
SAMPLER+=" --control static --color false"
|
SAMPLER+=" --control static --color false"
|
||||||
SAMPLER+=" --max-iterations 2"
|
SAMPLER+=" --max-iterations 2"
|
||||||
SAMPLER+=" --mq-config $ex2config"
|
SAMPLER+=" --mq-config $ex2config"
|
||||||
@@ -27,6 +29,7 @@ PROCESSOR1="fairmq-ex-1-n-1-processor"
|
|||||||
PROCESSOR1+=" --id processor1"
|
PROCESSOR1+=" --id processor1"
|
||||||
PROCESSOR1+=" --transport $transport"
|
PROCESSOR1+=" --transport $transport"
|
||||||
PROCESSOR1+=" --verbosity veryhigh"
|
PROCESSOR1+=" --verbosity veryhigh"
|
||||||
|
PROCESSOR1+=" --session $SESSION"
|
||||||
PROCESSOR1+=" --control static --color false"
|
PROCESSOR1+=" --control static --color false"
|
||||||
PROCESSOR1+=" --mq-config $ex2config"
|
PROCESSOR1+=" --mq-config $ex2config"
|
||||||
PROCESSOR1+=" --config-key processor"
|
PROCESSOR1+=" --config-key processor"
|
||||||
@@ -37,6 +40,7 @@ PROCESSOR2="fairmq-ex-1-n-1-processor"
|
|||||||
PROCESSOR2+=" --id processor2"
|
PROCESSOR2+=" --id processor2"
|
||||||
PROCESSOR2+=" --transport $transport"
|
PROCESSOR2+=" --transport $transport"
|
||||||
PROCESSOR2+=" --verbosity veryhigh"
|
PROCESSOR2+=" --verbosity veryhigh"
|
||||||
|
PROCESSOR2+=" --session $SESSION"
|
||||||
PROCESSOR2+=" --control static --color false"
|
PROCESSOR2+=" --control static --color false"
|
||||||
PROCESSOR2+=" --mq-config $ex2config"
|
PROCESSOR2+=" --mq-config $ex2config"
|
||||||
PROCESSOR2+=" --config-key processor"
|
PROCESSOR2+=" --config-key processor"
|
||||||
@@ -47,6 +51,7 @@ SINK="fairmq-ex-1-n-1-sink"
|
|||||||
SINK+=" --id sink1"
|
SINK+=" --id sink1"
|
||||||
SINK+=" --transport $transport"
|
SINK+=" --transport $transport"
|
||||||
SINK+=" --verbosity veryhigh"
|
SINK+=" --verbosity veryhigh"
|
||||||
|
SINK+=" --session $SESSION"
|
||||||
SINK+=" --control static --color false"
|
SINK+=" --control static --color false"
|
||||||
SINK+=" --max-iterations 2"
|
SINK+=" --max-iterations 2"
|
||||||
SINK+=" --mq-config $ex2config"
|
SINK+=" --mq-config $ex2config"
|
||||||
|
@@ -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)
|
||||||
|
50
examples/builtin-devices/CMakeLists.txt
Normal file
50
examples/builtin-devices/CMakeLists.txt
Normal 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
|
||||||
|
)
|
4
examples/builtin-devices/README.md
Normal file
4
examples/builtin-devices/README.md
Normal 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.
|
93
examples/builtin-devices/fairmq-start-ex-builtin-devices.sh.in
Executable file
93
examples/builtin-devices/fairmq-start-ex-builtin-devices.sh.in
Executable 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 &
|
148
examples/builtin-devices/test-ex-builtin-devices.sh.in
Executable file
148
examples/builtin-devices/test-ex-builtin-devices.sh.in
Executable 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
|
@@ -8,6 +8,8 @@ if [[ $1 =~ ^[a-z]+$ ]]; then
|
|||||||
transport=$1
|
transport=$1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
SESSION="$(@CMAKE_BINARY_DIR@/fairmq/fairmq-uuid-gen -h)"
|
||||||
|
|
||||||
# setup a trap to kill everything if the test fails/timeouts
|
# setup a trap to kill everything if the test fails/timeouts
|
||||||
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK1_PID; kill -TERM $SINK2_PID; wait $SAMPLER_PID; wait $SINK1_PID; wait $SINK2_PID;' TERM
|
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK1_PID; kill -TERM $SINK2_PID; wait $SAMPLER_PID; wait $SINK1_PID; wait $SINK2_PID;' TERM
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ SAMPLER="fairmq-ex-copypush-sampler"
|
|||||||
SAMPLER+=" --id sampler1"
|
SAMPLER+=" --id sampler1"
|
||||||
SAMPLER+=" --transport $transport"
|
SAMPLER+=" --transport $transport"
|
||||||
SAMPLER+=" --verbosity veryhigh"
|
SAMPLER+=" --verbosity veryhigh"
|
||||||
|
SAMPLER+=" --session $SESSION"
|
||||||
SAMPLER+=" --control static --color false"
|
SAMPLER+=" --control static --color false"
|
||||||
SAMPLER+=" --max-iterations 1"
|
SAMPLER+=" --max-iterations 1"
|
||||||
SAMPLER+=" --channel-config name=data,type=push,method=bind,rateLogging=0,address=tcp://*:5555,address=tcp://*:5556"
|
SAMPLER+=" --channel-config name=data,type=push,method=bind,rateLogging=0,address=tcp://*:5555,address=tcp://*:5556"
|
||||||
@@ -25,6 +28,7 @@ SINK1="fairmq-ex-copypush-sink"
|
|||||||
SINK1+=" --id sink1"
|
SINK1+=" --id sink1"
|
||||||
SINK1+=" --transport $transport"
|
SINK1+=" --transport $transport"
|
||||||
SINK1+=" --verbosity veryhigh"
|
SINK1+=" --verbosity veryhigh"
|
||||||
|
SINK1+=" --session $SESSION"
|
||||||
SINK1+=" --control static --color false"
|
SINK1+=" --control static --color false"
|
||||||
SINK1+=" --max-iterations 1"
|
SINK1+=" --max-iterations 1"
|
||||||
SINK1+=" --channel-config name=data,type=pull,method=connect,rateLogging=0,address=tcp://localhost:5555"
|
SINK1+=" --channel-config name=data,type=pull,method=connect,rateLogging=0,address=tcp://localhost:5555"
|
||||||
@@ -35,6 +39,7 @@ SINK2="fairmq-ex-copypush-sink"
|
|||||||
SINK2+=" --id sink2"
|
SINK2+=" --id sink2"
|
||||||
SINK2+=" --transport $transport"
|
SINK2+=" --transport $transport"
|
||||||
SINK2+=" --verbosity veryhigh"
|
SINK2+=" --verbosity veryhigh"
|
||||||
|
SINK2+=" --session $SESSION"
|
||||||
SINK2+=" --control static --color false"
|
SINK2+=" --control static --color false"
|
||||||
SINK2+=" --max-iterations 1"
|
SINK2+=" --max-iterations 1"
|
||||||
SINK2+=" --channel-config name=data,type=pull,method=connect,rateLogging=0,address=tcp://localhost:5556"
|
SINK2+=" --channel-config name=data,type=pull,method=connect,rateLogging=0,address=tcp://localhost:5556"
|
||||||
|
@@ -8,6 +8,8 @@ if [[ $1 =~ ^[a-z]+$ ]]; then
|
|||||||
transport=$1
|
transport=$1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
SESSION="$(@CMAKE_BINARY_DIR@/fairmq/fairmq-uuid-gen -h)"
|
||||||
|
|
||||||
# setup a trap to kill everything if the test fails/timeouts
|
# setup a trap to kill everything if the test fails/timeouts
|
||||||
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK_PID; wait $SAMPLER_PID; wait $SINK_PID;' TERM
|
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK_PID; wait $SAMPLER_PID; wait $SINK_PID;' TERM
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ SAMPLER="fairmq-ex-multipart-sampler"
|
|||||||
SAMPLER+=" --id sampler1"
|
SAMPLER+=" --id sampler1"
|
||||||
SAMPLER+=" --transport $transport"
|
SAMPLER+=" --transport $transport"
|
||||||
SAMPLER+=" --verbosity veryhigh"
|
SAMPLER+=" --verbosity veryhigh"
|
||||||
|
SAMPLER+=" --session $SESSION"
|
||||||
SAMPLER+=" --max-iterations 1"
|
SAMPLER+=" --max-iterations 1"
|
||||||
SAMPLER+=" --control static --color false"
|
SAMPLER+=" --control static --color false"
|
||||||
SAMPLER+=" --channel-config name=data,type=push,method=connect,rateLogging=0,address=tcp://127.0.0.1:5555"
|
SAMPLER+=" --channel-config name=data,type=push,method=connect,rateLogging=0,address=tcp://127.0.0.1:5555"
|
||||||
@@ -25,6 +28,7 @@ SINK="fairmq-ex-multipart-sink"
|
|||||||
SINK+=" --id sink1"
|
SINK+=" --id sink1"
|
||||||
SINK+=" --transport $transport"
|
SINK+=" --transport $transport"
|
||||||
SINK+=" --verbosity veryhigh"
|
SINK+=" --verbosity veryhigh"
|
||||||
|
SINK+=" --session $SESSION"
|
||||||
SINK+=" --control static --color false"
|
SINK+=" --control static --color false"
|
||||||
SINK+=" --channel-config name=data,type=pull,method=bind,rateLogging=0,address=tcp://127.0.0.1:5555"
|
SINK+=" --channel-config name=data,type=pull,method=bind,rateLogging=0,address=tcp://127.0.0.1:5555"
|
||||||
@CMAKE_CURRENT_BINARY_DIR@/$SINK &
|
@CMAKE_CURRENT_BINARY_DIR@/$SINK &
|
||||||
|
@@ -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 &
|
||||||
|
@@ -8,6 +8,8 @@ if [[ $1 =~ ^[a-z]+$ ]]; then
|
|||||||
transport=$1
|
transport=$1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
SESSION="$(@CMAKE_BINARY_DIR@/fairmq/fairmq-uuid-gen -h)"
|
||||||
|
|
||||||
# setup a trap to kill everything if the test fails/timeouts
|
# setup a trap to kill everything if the test fails/timeouts
|
||||||
trap 'kill -TERM $CLIENT_PID; kill -TERM $SERVER_PID; wait $CLIENT_PID; wait $SERVER_PID;' TERM
|
trap 'kill -TERM $CLIENT_PID; kill -TERM $SERVER_PID; wait $CLIENT_PID; wait $SERVER_PID;' TERM
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ CLIENT="fairmq-ex-req-rep-client"
|
|||||||
CLIENT+=" --id client"
|
CLIENT+=" --id client"
|
||||||
CLIENT+=" --transport $transport"
|
CLIENT+=" --transport $transport"
|
||||||
CLIENT+=" --verbosity veryhigh"
|
CLIENT+=" --verbosity veryhigh"
|
||||||
|
CLIENT+=" --session $SESSION"
|
||||||
CLIENT+=" --control static --color false"
|
CLIENT+=" --control static --color false"
|
||||||
CLIENT+=" --max-iterations 1"
|
CLIENT+=" --max-iterations 1"
|
||||||
CLIENT+=" --channel-config name=data,type=req,method=connect,rateLogging=0,address=tcp://127.0.0.1:5005"
|
CLIENT+=" --channel-config name=data,type=req,method=connect,rateLogging=0,address=tcp://127.0.0.1:5005"
|
||||||
@@ -25,6 +28,7 @@ SERVER="fairmq-ex-req-rep-server"
|
|||||||
SERVER+=" --id server"
|
SERVER+=" --id server"
|
||||||
SERVER+=" --transport $transport"
|
SERVER+=" --transport $transport"
|
||||||
SERVER+=" --verbosity veryhigh"
|
SERVER+=" --verbosity veryhigh"
|
||||||
|
SERVER+=" --session $SESSION"
|
||||||
SERVER+=" --control static --color false"
|
SERVER+=" --control static --color false"
|
||||||
SERVER+=" --max-iterations 1"
|
SERVER+=" --max-iterations 1"
|
||||||
SERVER+=" --channel-config name=data,type=rep,method=bind,rateLogging=0,address=tcp://127.0.0.1:5005"
|
SERVER+=" --channel-config name=data,type=rep,method=bind,rateLogging=0,address=tcp://127.0.0.1:5005"
|
||||||
|
@@ -28,7 +28,6 @@ endif()
|
|||||||
##################
|
##################
|
||||||
# subdirectories #
|
# subdirectories #
|
||||||
##################
|
##################
|
||||||
# add_subdirectory(shmem/prototype)
|
|
||||||
if(BUILD_OFI_TRANSPORT)
|
if(BUILD_OFI_TRANSPORT)
|
||||||
add_subdirectory(ofi)
|
add_subdirectory(ofi)
|
||||||
endif()
|
endif()
|
||||||
@@ -50,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
|
||||||
@@ -156,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)
|
||||||
@@ -233,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
|
||||||
|
@@ -111,12 +111,10 @@ auto DeviceRunner::RunWithExceptionHandlers() -> int
|
|||||||
try {
|
try {
|
||||||
return Run();
|
return Run();
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
LOG(error) << "Unhandled exception reached the top of main: " << e.what()
|
LOG(error) << "Uncaught exception reached the top of DeviceRunner: " << e.what();
|
||||||
<< ", application will now exit";
|
|
||||||
return 1;
|
return 1;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
LOG(error) << "Non-exception instance being thrown. Please make sure you use "
|
LOG(error) << "Uncaught exception reached the top of DeviceRunner.";
|
||||||
"std::runtime_exception() instead. Application will now exit.";
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "FairMQChannel.h"
|
#include "FairMQChannel.h"
|
||||||
|
#include <fairmq/Tools.h>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp> // join/split
|
#include <boost/algorithm/string.hpp> // join/split
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@ FairMQChannel::FairMQChannel()
|
|||||||
, fRcvBufSize(1000)
|
, fRcvBufSize(1000)
|
||||||
, fSndKernelSize(0)
|
, fSndKernelSize(0)
|
||||||
, fRcvKernelSize(0)
|
, fRcvKernelSize(0)
|
||||||
|
, fLinger(500)
|
||||||
, fRateLogging(1)
|
, fRateLogging(1)
|
||||||
, fName("")
|
, fName("")
|
||||||
, fIsValid(false)
|
, fIsValid(false)
|
||||||
@@ -53,6 +55,7 @@ FairMQChannel::FairMQChannel(const string& type, const string& method, const str
|
|||||||
, fRcvBufSize(1000)
|
, fRcvBufSize(1000)
|
||||||
, fSndKernelSize(0)
|
, fSndKernelSize(0)
|
||||||
, fRcvKernelSize(0)
|
, fRcvKernelSize(0)
|
||||||
|
, fLinger(500)
|
||||||
, fRateLogging(1)
|
, fRateLogging(1)
|
||||||
, fName("")
|
, fName("")
|
||||||
, fIsValid(false)
|
, fIsValid(false)
|
||||||
@@ -63,7 +66,7 @@ FairMQChannel::FairMQChannel(const string& type, const string& method, const str
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FairMQChannel::FairMQChannel(const string& name, const string& type, std::shared_ptr<FairMQTransportFactory> factory)
|
FairMQChannel::FairMQChannel(const string& name, const string& type, shared_ptr<FairMQTransportFactory> factory)
|
||||||
: fSocket(factory->CreateSocket(type, name))
|
: fSocket(factory->CreateSocket(type, name))
|
||||||
, fType(type)
|
, fType(type)
|
||||||
, fMethod("unspecified")
|
, fMethod("unspecified")
|
||||||
@@ -73,6 +76,7 @@ FairMQChannel::FairMQChannel(const string& name, const string& type, std::shared
|
|||||||
, fRcvBufSize(1000)
|
, fRcvBufSize(1000)
|
||||||
, fSndKernelSize(0)
|
, fSndKernelSize(0)
|
||||||
, fRcvKernelSize(0)
|
, fRcvKernelSize(0)
|
||||||
|
, fLinger(500)
|
||||||
, fRateLogging(1)
|
, fRateLogging(1)
|
||||||
, fName(name)
|
, fName(name)
|
||||||
, fIsValid(false)
|
, fIsValid(false)
|
||||||
@@ -93,6 +97,7 @@ FairMQChannel::FairMQChannel(const FairMQChannel& chan)
|
|||||||
, fRcvBufSize(chan.fRcvBufSize)
|
, fRcvBufSize(chan.fRcvBufSize)
|
||||||
, fSndKernelSize(chan.fSndKernelSize)
|
, fSndKernelSize(chan.fSndKernelSize)
|
||||||
, fRcvKernelSize(chan.fRcvKernelSize)
|
, fRcvKernelSize(chan.fRcvKernelSize)
|
||||||
|
, fLinger(chan.fLinger)
|
||||||
, fRateLogging(chan.fRateLogging)
|
, fRateLogging(chan.fRateLogging)
|
||||||
, fName(chan.fName)
|
, fName(chan.fName)
|
||||||
, fIsValid(false)
|
, fIsValid(false)
|
||||||
@@ -104,24 +109,28 @@ FairMQChannel::FairMQChannel(const FairMQChannel& chan)
|
|||||||
|
|
||||||
FairMQChannel& FairMQChannel::operator=(const FairMQChannel& chan)
|
FairMQChannel& FairMQChannel::operator=(const FairMQChannel& chan)
|
||||||
{
|
{
|
||||||
|
fSocket = nullptr;
|
||||||
fType = chan.fType;
|
fType = chan.fType;
|
||||||
fMethod = chan.fMethod;
|
fMethod = chan.fMethod;
|
||||||
fAddress = chan.fAddress;
|
fAddress = chan.fAddress;
|
||||||
|
fTransportType = chan.fTransportType;
|
||||||
fSndBufSize = chan.fSndBufSize;
|
fSndBufSize = chan.fSndBufSize;
|
||||||
fRcvBufSize = chan.fRcvBufSize;
|
fRcvBufSize = chan.fRcvBufSize;
|
||||||
fSndKernelSize = chan.fSndKernelSize;
|
fSndKernelSize = chan.fSndKernelSize;
|
||||||
fRcvKernelSize = chan.fRcvKernelSize;
|
fRcvKernelSize = chan.fRcvKernelSize;
|
||||||
|
fLinger = chan.fLinger;
|
||||||
fRateLogging = chan.fRateLogging;
|
fRateLogging = chan.fRateLogging;
|
||||||
fSocket = nullptr;
|
|
||||||
fName = chan.fName;
|
fName = chan.fName;
|
||||||
fIsValid = false;
|
fIsValid = false;
|
||||||
fTransportType = chan.fTransportType;
|
|
||||||
fTransportFactory = nullptr;
|
fTransportFactory = nullptr;
|
||||||
|
fMultipart = chan.fMultipart;
|
||||||
|
fModified = chan.fModified;
|
||||||
|
fReset = false;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
FairMQSocket const & FairMQChannel::GetSocket() const
|
FairMQSocket & FairMQChannel::GetSocket() const
|
||||||
{
|
{
|
||||||
assert(fSocket);
|
assert(fSocket);
|
||||||
return *fSocket;
|
return *fSocket;
|
||||||
@@ -135,340 +144,252 @@ string FairMQChannel::GetChannelName() const
|
|||||||
string FairMQChannel::GetChannelPrefix() const
|
string FairMQChannel::GetChannelPrefix() const
|
||||||
{
|
{
|
||||||
string prefix = fName;
|
string prefix = fName;
|
||||||
prefix = prefix.erase(fName.rfind("["));
|
prefix = prefix.erase(fName.rfind('['));
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
string FairMQChannel::GetChannelIndex() const
|
string FairMQChannel::GetChannelIndex() const
|
||||||
{
|
{
|
||||||
string indexStr = fName;
|
string indexStr = fName;
|
||||||
indexStr.erase(indexStr.rfind("]"));
|
indexStr.erase(indexStr.rfind(']'));
|
||||||
indexStr.erase(0, indexStr.rfind("[") + 1);
|
indexStr.erase(0, indexStr.rfind('[') + 1);
|
||||||
return indexStr;
|
return indexStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
string FairMQChannel::GetType() const
|
string FairMQChannel::GetType() const
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
return fType;
|
return fType;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::GetType: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::GetType: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string FairMQChannel::GetMethod() const
|
string FairMQChannel::GetMethod() const
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
return fMethod;
|
return fMethod;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::GetMethod: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::GetMethod: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string FairMQChannel::GetAddress() const
|
string FairMQChannel::GetAddress() const
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
return fAddress;
|
return fAddress;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::GetAddress: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::GetAddress: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string FairMQChannel::GetTransportName() const
|
string FairMQChannel::GetTransportName() const
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
return fair::mq::TransportNames.at(fTransportType);
|
return fair::mq::TransportNames.at(fTransportType);
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::GetTransportName: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::GetTransportName: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQChannel::GetSndBufSize() const
|
int FairMQChannel::GetSndBufSize() const
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
return fSndBufSize;
|
return fSndBufSize;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::GetSndBufSize: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::GetSndBufSize: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQChannel::GetRcvBufSize() const
|
int FairMQChannel::GetRcvBufSize() const
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
return fRcvBufSize;
|
return fRcvBufSize;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::GetRcvBufSize: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::GetRcvBufSize: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQChannel::GetSndKernelSize() const
|
int FairMQChannel::GetSndKernelSize() const
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
return fSndKernelSize;
|
return fSndKernelSize;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::GetSndKernelSize: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::GetSndKernelSize: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQChannel::GetRcvKernelSize() const
|
int FairMQChannel::GetRcvKernelSize() const
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
return fRcvKernelSize;
|
return fRcvKernelSize;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::GetRcvKernelSize: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::GetRcvKernelSize: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FairMQChannel::GetLinger() const
|
||||||
|
try {
|
||||||
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
|
return fLinger;
|
||||||
|
} catch (exception& e) {
|
||||||
|
LOG(error) << "Exception caught in FairMQChannel::GetLinger: " << e.what();
|
||||||
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQChannel::GetRateLogging() const
|
int FairMQChannel::GetRateLogging() const
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
return fRateLogging;
|
return fRateLogging;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::GetRateLogging: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::GetRateLogging: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::UpdateType(const string& type)
|
void FairMQChannel::UpdateType(const string& type)
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
fIsValid = false;
|
fIsValid = false;
|
||||||
fType = type;
|
fType = type;
|
||||||
fModified = true;
|
fModified = true;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::UpdateType: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::UpdateType: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::UpdateMethod(const string& method)
|
void FairMQChannel::UpdateMethod(const string& method)
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
fIsValid = false;
|
fIsValid = false;
|
||||||
fMethod = method;
|
fMethod = method;
|
||||||
fModified = true;
|
fModified = true;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::UpdateMethod: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::UpdateMethod: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::UpdateAddress(const string& address)
|
void FairMQChannel::UpdateAddress(const string& address)
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
fIsValid = false;
|
fIsValid = false;
|
||||||
fAddress = address;
|
fAddress = address;
|
||||||
fModified = true;
|
fModified = true;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::UpdateAddress: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::UpdateAddress: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::UpdateTransport(const string& transport)
|
void FairMQChannel::UpdateTransport(const string& transport)
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
fIsValid = false;
|
fIsValid = false;
|
||||||
fTransportType = fair::mq::TransportTypes.at(transport);
|
fTransportType = fair::mq::TransportTypes.at(transport);
|
||||||
fModified = true;
|
fModified = true;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::UpdateTransport: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::UpdateTransport: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::UpdateSndBufSize(const int sndBufSize)
|
void FairMQChannel::UpdateSndBufSize(const int sndBufSize)
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
fIsValid = false;
|
fIsValid = false;
|
||||||
fSndBufSize = sndBufSize;
|
fSndBufSize = sndBufSize;
|
||||||
fModified = true;
|
fModified = true;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::UpdateSndBufSize: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::UpdateSndBufSize: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::UpdateRcvBufSize(const int rcvBufSize)
|
void FairMQChannel::UpdateRcvBufSize(const int rcvBufSize)
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
fIsValid = false;
|
fIsValid = false;
|
||||||
fRcvBufSize = rcvBufSize;
|
fRcvBufSize = rcvBufSize;
|
||||||
fModified = true;
|
fModified = true;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::UpdateRcvBufSize: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::UpdateRcvBufSize: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::UpdateSndKernelSize(const int sndKernelSize)
|
void FairMQChannel::UpdateSndKernelSize(const int sndKernelSize)
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
fIsValid = false;
|
fIsValid = false;
|
||||||
fSndKernelSize = sndKernelSize;
|
fSndKernelSize = sndKernelSize;
|
||||||
fModified = true;
|
fModified = true;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::UpdateSndKernelSize: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::UpdateSndKernelSize: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::UpdateRcvKernelSize(const int rcvKernelSize)
|
void FairMQChannel::UpdateRcvKernelSize(const int rcvKernelSize)
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
fIsValid = false;
|
fIsValid = false;
|
||||||
fRcvKernelSize = rcvKernelSize;
|
fRcvKernelSize = rcvKernelSize;
|
||||||
fModified = true;
|
fModified = true;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::UpdateRcvKernelSize: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::UpdateRcvKernelSize: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FairMQChannel::UpdateLinger(const int duration)
|
||||||
|
try {
|
||||||
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
|
fIsValid = false;
|
||||||
|
fLinger = duration;
|
||||||
|
fModified = true;
|
||||||
|
} catch (exception& e) {
|
||||||
|
LOG(error) << "Exception caught in FairMQChannel::UpdateLinger: " << e.what();
|
||||||
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::UpdateRateLogging(const int rateLogging)
|
void FairMQChannel::UpdateRateLogging(const int rateLogging)
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
fIsValid = false;
|
fIsValid = false;
|
||||||
fRateLogging = rateLogging;
|
fRateLogging = rateLogging;
|
||||||
fModified = true;
|
fModified = true;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::UpdateRateLogging: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::UpdateRateLogging: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FairMQChannel::SetModified(const bool modified) -> void
|
auto FairMQChannel::SetModified(const bool modified) -> void
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
fModified = modified;
|
fModified = modified;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::SetModified: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::SetModified: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::UpdateChannelName(const string& name)
|
void FairMQChannel::UpdateChannelName(const string& name)
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
fIsValid = false;
|
fIsValid = false;
|
||||||
fName = name;
|
fName = name;
|
||||||
fModified = true;
|
fModified = true;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::UpdateChannelName: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::UpdateChannelName: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FairMQChannel::IsValid() const
|
bool FairMQChannel::IsValid() const
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
return fIsValid;
|
return fIsValid;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::IsValid: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::IsValid: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("failed to acquire lock: ", e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FairMQChannel::ValidateChannel()
|
bool FairMQChannel::ValidateChannel()
|
||||||
{
|
try {
|
||||||
try
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
{
|
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
|
||||||
|
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
ss << "Validating channel \"" << fName << "\"... ";
|
ss << "Validating channel '" << fName << "'... ";
|
||||||
|
|
||||||
if (fIsValid)
|
if (fIsValid)
|
||||||
{
|
{
|
||||||
@@ -484,8 +405,8 @@ bool FairMQChannel::ValidateChannel()
|
|||||||
{
|
{
|
||||||
ss << "INVALID";
|
ss << "INVALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
LOG(error) << "Invalid channel type: \"" << fType << "\"";
|
LOG(error) << "Invalid channel type: '" << fType << "'";
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("Invalid channel type: '", fType, "'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate socket address
|
// validate socket address
|
||||||
@@ -493,7 +414,7 @@ bool FairMQChannel::ValidateChannel()
|
|||||||
{
|
{
|
||||||
ss << "INVALID";
|
ss << "INVALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
LOG(debug) << "invalid channel address: \"" << fAddress << "\"";
|
LOG(debug) << "invalid channel address: '" << fAddress << "'";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -516,8 +437,8 @@ bool FairMQChannel::ValidateChannel()
|
|||||||
{
|
{
|
||||||
ss << "INVALID";
|
ss << "INVALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
LOG(error) << "Invalid endpoint connection method: \"" << fMethod << "\" for " << endpoint;
|
LOG(error) << "Invalid endpoint connection method: '" << fMethod << "' for " << endpoint;
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("Invalid endpoint connection method: '", fMethod, "' for ", endpoint));
|
||||||
}
|
}
|
||||||
address = endpoint;
|
address = endpoint;
|
||||||
}
|
}
|
||||||
@@ -526,11 +447,11 @@ bool FairMQChannel::ValidateChannel()
|
|||||||
{
|
{
|
||||||
// check if TCP address contains port delimiter
|
// check if TCP address contains port delimiter
|
||||||
string addressString = address.substr(6);
|
string addressString = address.substr(6);
|
||||||
if (addressString.find(":") == string::npos)
|
if (addressString.find(':') == string::npos)
|
||||||
{
|
{
|
||||||
ss << "INVALID";
|
ss << "INVALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
LOG(error) << "invalid channel address: \"" << address << "\" (missing port?)";
|
LOG(error) << "invalid channel address: '" << address << "' (missing port?)";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -542,7 +463,7 @@ bool FairMQChannel::ValidateChannel()
|
|||||||
{
|
{
|
||||||
ss << "INVALID";
|
ss << "INVALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
LOG(error) << "invalid channel address: \"" << address << "\" (empty IPC address?)";
|
LOG(error) << "invalid channel address: '" << address << "' (empty IPC address?)";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -554,7 +475,7 @@ bool FairMQChannel::ValidateChannel()
|
|||||||
{
|
{
|
||||||
ss << "INVALID";
|
ss << "INVALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
LOG(error) << "invalid channel address: \"" << address << "\" (empty inproc address?)";
|
LOG(error) << "invalid channel address: '" << address << "' (empty inproc address?)";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -566,7 +487,7 @@ bool FairMQChannel::ValidateChannel()
|
|||||||
{
|
{
|
||||||
ss << "INVALID";
|
ss << "INVALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
LOG(error) << "invalid channel address: \"" << address << "\" (empty verbs address?)";
|
LOG(error) << "invalid channel address: '" << address << "' (empty verbs address?)";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -575,7 +496,7 @@ bool FairMQChannel::ValidateChannel()
|
|||||||
// if neither TCP or IPC is specified, return invalid
|
// if neither TCP or IPC is specified, return invalid
|
||||||
ss << "INVALID";
|
ss << "INVALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
LOG(error) << "invalid channel address: \"" << address << "\" (missing protocol specifier?)";
|
LOG(error) << "invalid channel address: '" << address << "' (missing protocol specifier?)";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -586,8 +507,8 @@ bool FairMQChannel::ValidateChannel()
|
|||||||
{
|
{
|
||||||
ss << "INVALID";
|
ss << "INVALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
LOG(error) << "invalid channel send buffer size (cannot be negative): \"" << fSndBufSize << "\"";
|
LOG(error) << "invalid channel send buffer size (cannot be negative): '" << fSndBufSize << "'";
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("invalid channel send buffer size (cannot be negative): '", fSndBufSize, "'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate socket buffer size for receiving
|
// validate socket buffer size for receiving
|
||||||
@@ -595,8 +516,8 @@ bool FairMQChannel::ValidateChannel()
|
|||||||
{
|
{
|
||||||
ss << "INVALID";
|
ss << "INVALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
LOG(error) << "invalid channel receive buffer size (cannot be negative): \"" << fRcvBufSize << "\"";
|
LOG(error) << "invalid channel receive buffer size (cannot be negative): '" << fRcvBufSize << "'";
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("invalid channel receive buffer size (cannot be negative): '", fRcvBufSize, "'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate socket kernel transmit size for sending
|
// validate socket kernel transmit size for sending
|
||||||
@@ -604,8 +525,8 @@ bool FairMQChannel::ValidateChannel()
|
|||||||
{
|
{
|
||||||
ss << "INVALID";
|
ss << "INVALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
LOG(error) << "invalid channel send kernel transmit size (cannot be negative): \"" << fSndKernelSize << "\"";
|
LOG(error) << "invalid channel send kernel transmit size (cannot be negative): '" << fSndKernelSize << "'";
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("invalid channel send kernel transmit size (cannot be negative): '", fSndKernelSize, "'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate socket kernel transmit size for receiving
|
// validate socket kernel transmit size for receiving
|
||||||
@@ -613,8 +534,8 @@ bool FairMQChannel::ValidateChannel()
|
|||||||
{
|
{
|
||||||
ss << "INVALID";
|
ss << "INVALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
LOG(error) << "invalid channel receive kernel transmit size (cannot be negative): \"" << fRcvKernelSize << "\"";
|
LOG(error) << "invalid channel receive kernel transmit size (cannot be negative): '" << fRcvKernelSize << "'";
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("invalid channel receive kernel transmit size (cannot be negative): '", fRcvKernelSize, "'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate socket rate logging interval
|
// validate socket rate logging interval
|
||||||
@@ -622,20 +543,17 @@ bool FairMQChannel::ValidateChannel()
|
|||||||
{
|
{
|
||||||
ss << "INVALID";
|
ss << "INVALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
LOG(error) << "invalid socket rate logging interval (cannot be negative): \"" << fRateLogging << "\"";
|
LOG(error) << "invalid socket rate logging interval (cannot be negative): '" << fRateLogging << "'";
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString("invalid socket rate logging interval (cannot be negative): '", fRateLogging, "'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
fIsValid = true;
|
fIsValid = true;
|
||||||
ss << "VALID";
|
ss << "VALID";
|
||||||
LOG(debug) << ss.str();
|
LOG(debug) << ss.str();
|
||||||
return true;
|
return true;
|
||||||
}
|
} catch (exception& e) {
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception caught in FairMQChannel::ValidateChannel: " << e.what();
|
LOG(error) << "Exception caught in FairMQChannel::ValidateChannel: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
throw ChannelConfigurationError(fair::mq::tools::ToString(e.what()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::InitTransport(shared_ptr<FairMQTransportFactory> factory)
|
void FairMQChannel::InitTransport(shared_ptr<FairMQTransportFactory> factory)
|
||||||
@@ -646,82 +564,57 @@ void FairMQChannel::InitTransport(shared_ptr<FairMQTransportFactory> factory)
|
|||||||
|
|
||||||
void FairMQChannel::ResetChannel()
|
void FairMQChannel::ResetChannel()
|
||||||
{
|
{
|
||||||
unique_lock<mutex> lock(fChannelMutex);
|
lock_guard<mutex> lock(fChannelMutex);
|
||||||
fIsValid = false;
|
fIsValid = false;
|
||||||
// TODO: implement channel resetting
|
// TODO: implement channel resetting
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQChannel::Send(unique_ptr<FairMQMessage>& msg) const
|
int FairMQChannel::Send(unique_ptr<FairMQMessage>& msg, int sndTimeoutInMs)
|
||||||
{
|
{
|
||||||
CheckSendCompatibility(msg);
|
CheckSendCompatibility(msg);
|
||||||
return fSocket->Send(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
int FairMQChannel::Receive(unique_ptr<FairMQMessage>& msg) const
|
|
||||||
{
|
|
||||||
CheckReceiveCompatibility(msg);
|
|
||||||
return fSocket->Receive(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
int FairMQChannel::Send(unique_ptr<FairMQMessage>& msg, int sndTimeoutInMs) const
|
|
||||||
{
|
|
||||||
return fSocket->Send(msg, sndTimeoutInMs);
|
return fSocket->Send(msg, sndTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQChannel::Receive(unique_ptr<FairMQMessage>& msg, int rcvTimeoutInMs) const
|
int FairMQChannel::Receive(unique_ptr<FairMQMessage>& msg, int rcvTimeoutInMs)
|
||||||
{
|
{
|
||||||
|
CheckReceiveCompatibility(msg);
|
||||||
return fSocket->Receive(msg, rcvTimeoutInMs);
|
return fSocket->Receive(msg, rcvTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQChannel::SendAsync(unique_ptr<FairMQMessage>& msg) const
|
int FairMQChannel::SendAsync(unique_ptr<FairMQMessage>& msg)
|
||||||
{
|
{
|
||||||
CheckSendCompatibility(msg);
|
CheckSendCompatibility(msg);
|
||||||
return fSocket->TrySend(msg);
|
return fSocket->Send(msg, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FairMQChannel::ReceiveAsync(unique_ptr<FairMQMessage>& msg) const
|
int FairMQChannel::ReceiveAsync(unique_ptr<FairMQMessage>& msg)
|
||||||
{
|
{
|
||||||
CheckReceiveCompatibility(msg);
|
CheckReceiveCompatibility(msg);
|
||||||
return fSocket->TryReceive(msg);
|
return fSocket->Receive(msg, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FairMQChannel::Send(vector<unique_ptr<FairMQMessage>>& msgVec) const
|
int64_t FairMQChannel::Send(vector<unique_ptr<FairMQMessage>>& msgVec, int sndTimeoutInMs)
|
||||||
{
|
{
|
||||||
CheckSendCompatibility(msgVec);
|
CheckSendCompatibility(msgVec);
|
||||||
return fSocket->Send(msgVec);
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t FairMQChannel::Receive(vector<unique_ptr<FairMQMessage>>& msgVec) const
|
|
||||||
{
|
|
||||||
CheckReceiveCompatibility(msgVec);
|
|
||||||
return fSocket->Receive(msgVec);
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t FairMQChannel::Send(vector<unique_ptr<FairMQMessage>>& msgVec, int sndTimeoutInMs) const
|
|
||||||
{
|
|
||||||
return fSocket->Send(msgVec, sndTimeoutInMs);
|
return fSocket->Send(msgVec, sndTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FairMQChannel::Receive(vector<unique_ptr<FairMQMessage>>& msgVec, int rcvTimeoutInMs) const
|
int64_t FairMQChannel::Receive(vector<unique_ptr<FairMQMessage>>& msgVec, int rcvTimeoutInMs)
|
||||||
{
|
{
|
||||||
|
CheckReceiveCompatibility(msgVec);
|
||||||
return fSocket->Receive(msgVec, rcvTimeoutInMs);
|
return fSocket->Receive(msgVec, rcvTimeoutInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FairMQChannel::SendAsync(vector<unique_ptr<FairMQMessage>>& msgVec) const
|
int64_t FairMQChannel::SendAsync(vector<unique_ptr<FairMQMessage>>& msgVec)
|
||||||
{
|
{
|
||||||
CheckSendCompatibility(msgVec);
|
CheckSendCompatibility(msgVec);
|
||||||
return fSocket->TrySend(msgVec);
|
return fSocket->Send(msgVec, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Receives a vector of messages in non-blocking mode.
|
int64_t FairMQChannel::ReceiveAsync(vector<unique_ptr<FairMQMessage>>& msgVec)
|
||||||
///
|
|
||||||
/// @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 FairMQChannel::ReceiveAsync(vector<unique_ptr<FairMQMessage>>& msgVec) const
|
|
||||||
{
|
{
|
||||||
CheckReceiveCompatibility(msgVec);
|
CheckReceiveCompatibility(msgVec);
|
||||||
return fSocket->TryReceive(msgVec);
|
return fSocket->Receive(msgVec, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
FairMQChannel::~FairMQChannel()
|
FairMQChannel::~FairMQChannel()
|
||||||
@@ -748,7 +641,7 @@ unsigned long FairMQChannel::GetMessagesRx() const
|
|||||||
return fSocket->GetMessagesRx();
|
return fSocket->GetMessagesRx();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::CheckSendCompatibility(FairMQMessagePtr& msg) const
|
void FairMQChannel::CheckSendCompatibility(FairMQMessagePtr& msg)
|
||||||
{
|
{
|
||||||
if (fTransportType != msg->GetType())
|
if (fTransportType != msg->GetType())
|
||||||
{
|
{
|
||||||
@@ -763,7 +656,7 @@ void FairMQChannel::CheckSendCompatibility(FairMQMessagePtr& msg) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::CheckSendCompatibility(vector<FairMQMessagePtr>& msgVec) const
|
void FairMQChannel::CheckSendCompatibility(vector<FairMQMessagePtr>& msgVec)
|
||||||
{
|
{
|
||||||
for (auto& msg : msgVec)
|
for (auto& msg : msgVec)
|
||||||
{
|
{
|
||||||
@@ -781,7 +674,7 @@ void FairMQChannel::CheckSendCompatibility(vector<FairMQMessagePtr>& msgVec) con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::CheckReceiveCompatibility(FairMQMessagePtr& msg) const
|
void FairMQChannel::CheckReceiveCompatibility(FairMQMessagePtr& msg)
|
||||||
{
|
{
|
||||||
if (fTransportType != msg->GetType())
|
if (fTransportType != msg->GetType())
|
||||||
{
|
{
|
||||||
@@ -791,7 +684,7 @@ void FairMQChannel::CheckReceiveCompatibility(FairMQMessagePtr& msg) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQChannel::CheckReceiveCompatibility(vector<FairMQMessagePtr>& msgVec) const
|
void FairMQChannel::CheckReceiveCompatibility(vector<FairMQMessagePtr>& msgVec)
|
||||||
{
|
{
|
||||||
for (auto& msg : msgVec)
|
for (auto& msg : msgVec)
|
||||||
{
|
{
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <FairMQTransportFactory.h>
|
#include <FairMQTransportFactory.h>
|
||||||
#include <FairMQSocket.h>
|
#include <FairMQSocket.h>
|
||||||
@@ -51,7 +52,9 @@ class FairMQChannel
|
|||||||
/// Default destructor
|
/// Default destructor
|
||||||
virtual ~FairMQChannel();
|
virtual ~FairMQChannel();
|
||||||
|
|
||||||
FairMQSocket const & GetSocket() const;
|
struct ChannelConfigurationError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||||
|
|
||||||
|
FairMQSocket& GetSocket() const;
|
||||||
|
|
||||||
auto Bind(const std::string& address) -> bool
|
auto Bind(const std::string& address) -> bool
|
||||||
{
|
{
|
||||||
@@ -111,6 +114,10 @@ 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;
|
||||||
@@ -147,6 +154,10 @@ 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);
|
||||||
@@ -166,106 +177,62 @@ class FairMQChannel
|
|||||||
/// 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);
|
||||||
|
|
||||||
/// 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);
|
||||||
|
|
||||||
/// 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
|
int ReceiveAsync(FairMQMessagePtr& msg) __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(msg, timeout);")));
|
||||||
/// putting it in the queue.
|
|
||||||
///
|
|
||||||
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
|
||||||
/// @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.
|
|
||||||
int SendAsync(FairMQMessagePtr& msg) const;
|
|
||||||
|
|
||||||
/// 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);
|
||||||
|
|
||||||
/// 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.
|
int64_t SendAsync(std::vector<FairMQMessagePtr>& msgVec) __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(msgVec, timeout);")));
|
||||||
/// @details SendAsync method attempts to send a vector of messages without blocking by
|
int64_t ReceiveAsync(std::vector<FairMQMessagePtr>& msgVec) __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(msgVec, timeout);")));
|
||||||
/// 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.
|
/// Send FairMQParts
|
||||||
///
|
/// @param parts FairMQParts reference
|
||||||
/// @param msgVec message vector 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 received. If queue is empty, returns -2.
|
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out. -1 if there was an error.
|
||||||
/// In case of errors, returns -1.
|
int64_t Send(FairMQParts& parts, int sndTimeoutInMs = -1)
|
||||||
int64_t ReceiveAsync(std::vector<FairMQMessagePtr>& msgVec) const;
|
|
||||||
|
|
||||||
int64_t Send(FairMQParts& parts) const
|
|
||||||
{
|
|
||||||
return Send(parts.fParts);
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t Receive(FairMQParts& parts) const
|
|
||||||
{
|
|
||||||
return Receive(parts.fParts);
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t Send(FairMQParts& parts, int sndTimeoutInMs) const
|
|
||||||
{
|
{
|
||||||
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;
|
||||||
@@ -273,25 +240,25 @@ class FairMQChannel
|
|||||||
unsigned long GetMessagesTx() const;
|
unsigned long GetMessagesTx() const;
|
||||||
unsigned long GetMessagesRx() const;
|
unsigned long GetMessagesRx() const;
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -307,6 +274,7 @@ class FairMQChannel
|
|||||||
int fRcvBufSize;
|
int fRcvBufSize;
|
||||||
int fSndKernelSize;
|
int fSndKernelSize;
|
||||||
int fRcvKernelSize;
|
int fRcvKernelSize;
|
||||||
|
int fLinger;
|
||||||
int fRateLogging;
|
int fRateLogging;
|
||||||
|
|
||||||
std::string fName;
|
std::string fName;
|
||||||
@@ -314,10 +282,10 @@ class FairMQChannel
|
|||||||
|
|
||||||
std::shared_ptr<FairMQTransportFactory> fTransportFactory;
|
std::shared_ptr<FairMQTransportFactory> fTransportFactory;
|
||||||
|
|
||||||
void CheckSendCompatibility(FairMQMessagePtr& msg) const;
|
void CheckSendCompatibility(FairMQMessagePtr& msg);
|
||||||
void CheckSendCompatibility(std::vector<FairMQMessagePtr>& msgVec) const;
|
void CheckSendCompatibility(std::vector<FairMQMessagePtr>& msgVec);
|
||||||
void CheckReceiveCompatibility(FairMQMessagePtr& msg) const;
|
void CheckReceiveCompatibility(FairMQMessagePtr& msg);
|
||||||
void CheckReceiveCompatibility(std::vector<FairMQMessagePtr>& msgVec) const;
|
void CheckReceiveCompatibility(std::vector<FairMQMessagePtr>& msgVec);
|
||||||
|
|
||||||
void InitTransport(std::shared_ptr<FairMQTransportFactory> factory);
|
void InitTransport(std::shared_ptr<FairMQTransportFactory> factory);
|
||||||
|
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <stdexcept>
|
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@@ -24,6 +23,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <future>
|
||||||
#include <algorithm> // std::max
|
#include <algorithm> // std::max
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -55,9 +55,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)
|
, fPortRangeMin(22000)
|
||||||
, fPortRangeMax(32000)
|
, fPortRangeMax(32000)
|
||||||
, fDefaultTransportType(fair::mq::Transport::DEFAULT)
|
, fDefaultTransportType(fair::mq::Transport::DEFAULT)
|
||||||
@@ -75,6 +72,7 @@ FairMQDevice::FairMQDevice(FairMQProgOptions* config, const fair::mq::tools::Ver
|
|||||||
, fInterrupted(false)
|
, fInterrupted(false)
|
||||||
, fInterruptedCV()
|
, fInterruptedCV()
|
||||||
, fInterruptedMtx()
|
, fInterruptedMtx()
|
||||||
|
, fRateLogging(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,13 +83,12 @@ void FairMQDevice::InitWrapper()
|
|||||||
fPortRangeMin = fConfig->GetValue<int>("port-range-min");
|
fPortRangeMin = fConfig->GetValue<int>("port-range-min");
|
||||||
fPortRangeMax = fConfig->GetValue<int>("port-range-max");
|
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())
|
||||||
@@ -158,9 +155,8 @@ void FairMQDevice::InitWrapper()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG(error) << "Cannot update configuration. Socket method (bind/connect) not specified.";
|
LOG(error) << "Cannot update configuration. Socket method (bind/connect) for channel '" << vi->fName << "' not specified.";
|
||||||
ChangeState(ERROR_FOUND);
|
throw runtime_error(fair::mq::tools::ToString("Cannot update configuration. Socket method (bind/connect) for channel ", vi->fName, " not specified."));
|
||||||
// throw runtime_error("Cannot update configuration. Socket method (bind/connect) not specified.");
|
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
@@ -170,22 +166,14 @@ 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)
|
||||||
@@ -199,8 +187,6 @@ void FairMQDevice::InitWrapper()
|
|||||||
{
|
{
|
||||||
this_thread::sleep_for(chrono::milliseconds(sleepTimeInMS));
|
this_thread::sleep_for(chrono::milliseconds(sleepTimeInMS));
|
||||||
|
|
||||||
if (fConfig)
|
|
||||||
{
|
|
||||||
for (auto& chan : uninitializedConnectingChannels)
|
for (auto& chan : uninitializedConnectingChannels)
|
||||||
{
|
{
|
||||||
string key{"chans." + chan->GetChannelPrefix() + "." + chan->GetChannelIndex() + ".address"};
|
string key{"chans." + chan->GetChannelPrefix() + "." + chan->GetChannelIndex() + ".address"};
|
||||||
@@ -210,13 +196,11 @@ void FairMQDevice::InitWrapper()
|
|||||||
chan->UpdateAddress(newAddress);
|
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);
|
||||||
@@ -224,13 +208,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()
|
||||||
@@ -294,18 +276,21 @@ bool FairMQDevice::AttachChannel(FairMQChannel& ch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set high water marks
|
// set linger duration (how long socket should wait for outstanding transfers before shutdown)
|
||||||
ch.fSocket->SetOption("snd-hwm", &(ch.fSndBufSize), sizeof(ch.fSndBufSize));
|
ch.fSocket->SetLinger(ch.fLinger);
|
||||||
ch.fSocket->SetOption("rcv-hwm", &(ch.fRcvBufSize), sizeof(ch.fRcvBufSize));
|
|
||||||
|
|
||||||
// set kernel transmit size
|
// set high water marks
|
||||||
|
ch.fSocket->SetSndBufSize(ch.fSndBufSize);
|
||||||
|
ch.fSocket->SetRcvBufSize(ch.fRcvBufSize);
|
||||||
|
|
||||||
|
// set kernel transmit size (set it only if value is not the default value)
|
||||||
if (ch.fSndKernelSize != 0)
|
if (ch.fSndKernelSize != 0)
|
||||||
{
|
{
|
||||||
ch.fSocket->SetOption("snd-size", &(ch.fSndKernelSize), sizeof(ch.fSndKernelSize));
|
ch.fSocket->SetSndKernelSize(ch.fSndKernelSize);
|
||||||
}
|
}
|
||||||
if (ch.fRcvKernelSize != 0)
|
if (ch.fRcvKernelSize != 0)
|
||||||
{
|
{
|
||||||
ch.fSocket->SetOption("rcv-size", &(ch.fRcvKernelSize), sizeof(ch.fRcvKernelSize));
|
ch.fSocket->SetRcvKernelSize(ch.fRcvKernelSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// attach
|
// attach
|
||||||
@@ -330,7 +315,7 @@ bool FairMQDevice::AttachChannel(FairMQChannel& ch)
|
|||||||
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 == "*"))
|
||||||
{
|
{
|
||||||
@@ -364,7 +349,7 @@ bool FairMQDevice::AttachChannel(FairMQChannel& ch)
|
|||||||
}
|
}
|
||||||
endpoint += address;
|
endpoint += address;
|
||||||
|
|
||||||
LOG(debug) << "Attached channel " << ch.fName << " to " << endpoint << (bind ? " (bind) " : " (connect) ");
|
LOG(debug) << "Attached channel " << ch.fName << " to " << endpoint << (bind ? " (bind) " : " (connect) ") << "(" << ch.fType << ")";
|
||||||
|
|
||||||
// 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)
|
||||||
@@ -378,12 +363,9 @@ bool FairMQDevice::AttachChannel(FairMQChannel& ch)
|
|||||||
if (newAddress != ch.fAddress)
|
if (newAddress != ch.fAddress)
|
||||||
{
|
{
|
||||||
ch.UpdateAddress(newAddress);
|
ch.UpdateAddress(newAddress);
|
||||||
if (fConfig)
|
|
||||||
{
|
|
||||||
string key{"chans." + ch.GetChannelPrefix() + "." + ch.GetChannelIndex() + ".address"};
|
string key{"chans." + ch.GetChannelPrefix() + "." + ch.GetChannelIndex() + ".address"};
|
||||||
fConfig->SetValue(key, newAddress);
|
fConfig->SetValue(key, newAddress);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -417,7 +399,7 @@ bool FairMQDevice::BindEndpoint(FairMQSocket& socket, string& endpoint)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t pos = endpoint.rfind(":");
|
size_t pos = endpoint.rfind(':');
|
||||||
endpoint = endpoint.substr(0, pos + 1) + fair::mq::tools::ToString(static_cast<int>(randomPort(generator)));
|
endpoint = endpoint.substr(0, pos + 1) + fair::mq::tools::ToString(static_cast<int>(randomPort(generator)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -467,15 +449,15 @@ void FairMQDevice::PrintChannel(const string& name)
|
|||||||
{
|
{
|
||||||
if (fChannels.find(name) != fChannels.end())
|
if (fChannels.find(name) != fChannels.end())
|
||||||
{
|
{
|
||||||
for (auto vi = fChannels[name].begin(); vi != fChannels[name].end(); ++vi)
|
for (const auto& vi : fChannels[name])
|
||||||
{
|
{
|
||||||
LOG(info) << vi->fName << ": "
|
LOG(info) << vi.fName << ": "
|
||||||
<< vi->fType << " | "
|
<< vi.fType << " | "
|
||||||
<< vi->fMethod << " | "
|
<< vi.fMethod << " | "
|
||||||
<< vi->fAddress << " | "
|
<< vi.fAddress << " | "
|
||||||
<< vi->fSndBufSize << " | "
|
<< vi.fSndBufSize << " | "
|
||||||
<< vi->fRcvBufSize << " | "
|
<< vi.fRcvBufSize << " | "
|
||||||
<< vi->fRateLogging;
|
<< vi.fRateLogging;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -491,7 +473,8 @@ void FairMQDevice::RunWrapper()
|
|||||||
LOG(info) << "DEVICE: Running...";
|
LOG(info) << "DEVICE: Running...";
|
||||||
|
|
||||||
// start the rate logger thread
|
// start the rate logger thread
|
||||||
thread rateLogger(&FairMQDevice::LogSocketRates, this);
|
fRateLogging = true;
|
||||||
|
future<void> rateLogger = async(launch::async, &FairMQDevice::LogSocketRates, this);
|
||||||
|
|
||||||
// notify transports to resume transfers
|
// notify transports to resume transfers
|
||||||
{
|
{
|
||||||
@@ -503,8 +486,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
|
||||||
@@ -534,11 +516,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.
|
||||||
@@ -549,7 +534,7 @@ void FairMQDevice::RunWrapper()
|
|||||||
|
|
||||||
PostRun();
|
PostRun();
|
||||||
|
|
||||||
rateLogger.join();
|
rateLogger.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQDevice::HandleSingleChannelInput()
|
void FairMQDevice::HandleSingleChannelInput()
|
||||||
@@ -592,17 +577,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,7 +645,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)
|
||||||
@@ -717,11 +702,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());
|
||||||
|
|
||||||
@@ -735,7 +720,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;
|
||||||
|
|
||||||
@@ -816,8 +801,6 @@ void FairMQDevice::LogSocketRates()
|
|||||||
chrono::time_point<chrono::high_resolution_clock> t0;
|
chrono::time_point<chrono::high_resolution_clock> t0;
|
||||||
chrono::time_point<chrono::high_resolution_clock> t1;
|
chrono::time_point<chrono::high_resolution_clock> t1;
|
||||||
|
|
||||||
unsigned long long msSinceLastLog;
|
|
||||||
|
|
||||||
vector<FairMQSocket*> filteredSockets;
|
vector<FairMQSocket*> filteredSockets;
|
||||||
vector<string> filteredChannelNames;
|
vector<string> filteredChannelNames;
|
||||||
vector<int> logIntervals;
|
vector<int> logIntervals;
|
||||||
@@ -875,11 +858,11 @@ 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();
|
||||||
|
|
||||||
msSinceLastLog = chrono::duration_cast<chrono::milliseconds>(t1 - t0).count();
|
unsigned long long msSinceLastLog = chrono::duration_cast<chrono::milliseconds>(t1 - t0).count();
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
@@ -915,8 +898,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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -930,6 +912,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();
|
||||||
}
|
}
|
||||||
@@ -951,13 +934,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)
|
||||||
{
|
{
|
||||||
@@ -968,11 +949,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()
|
||||||
|
@@ -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>
|
||||||
@@ -96,154 +97,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 +208,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 +219,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 +246,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 +255,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 +274,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 +301,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 +328,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() {}
|
||||||
|
|
||||||
@@ -432,7 +397,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.
|
||||||
@@ -462,47 +431,33 @@ class FairMQDevice : public FairMQStateMachine
|
|||||||
std::string fId; ///< Device ID
|
std::string fId; ///< Device ID
|
||||||
|
|
||||||
/// Additional user initialization (can be overloaded in child classes). Prefer to use InitTask().
|
/// Additional user initialization (can be overloaded in child classes). Prefer to use InitTask().
|
||||||
/// Executed in a worker thread
|
|
||||||
virtual void Init();
|
virtual void Init();
|
||||||
|
|
||||||
/// Task initialization (can be overloaded in child classes)
|
/// Task initialization (can be overloaded in child classes)
|
||||||
/// Executed in a worker thread
|
|
||||||
virtual void InitTask();
|
virtual void InitTask();
|
||||||
|
|
||||||
/// Runs the device (to be overloaded in child classes)
|
/// Runs the device (to be overloaded in child classes)
|
||||||
/// Executed in a worker thread
|
|
||||||
virtual void Run();
|
virtual void Run();
|
||||||
|
|
||||||
/// Called in the RUNNING state once before executing the Run()/ConditionalRun() method
|
/// Called in the RUNNING state once before executing the Run()/ConditionalRun() method
|
||||||
/// Executed in a worker thread
|
|
||||||
virtual void PreRun();
|
virtual void PreRun();
|
||||||
|
|
||||||
/// Called during RUNNING state repeatedly until it returns false or device state changes
|
/// Called during RUNNING state repeatedly until it returns false or device state changes
|
||||||
/// Executed in a worker thread
|
|
||||||
virtual bool ConditionalRun();
|
virtual bool ConditionalRun();
|
||||||
|
|
||||||
/// Called in the RUNNING state once after executing the Run()/ConditionalRun() method
|
/// Called in the RUNNING state once after executing the Run()/ConditionalRun() method
|
||||||
/// Executed in a worker thread
|
|
||||||
virtual void PostRun();
|
virtual void PostRun();
|
||||||
|
|
||||||
/// Handles the PAUSE state
|
/// Handles the PAUSE state
|
||||||
/// Executed in a worker thread
|
|
||||||
virtual void Pause();
|
virtual void Pause();
|
||||||
|
|
||||||
/// Resets the user task (to be overloaded in child classes)
|
/// Resets the user task (to be overloaded in child classes)
|
||||||
/// Executed in a worker thread
|
|
||||||
virtual void ResetTask();
|
virtual void ResetTask();
|
||||||
|
|
||||||
/// Resets the device (can be overloaded in child classes)
|
/// Resets the device (can be overloaded in child classes)
|
||||||
/// Executed in a worker thread
|
|
||||||
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 fPortRangeMin; ///< Minimum value for the port range (if dynamic)
|
||||||
int fPortRangeMax; ///< Maximum value for the port range (if dynamic)
|
int fPortRangeMax; ///< Maximum value for the port range (if dynamic)
|
||||||
|
|
||||||
@@ -545,8 +500,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();
|
||||||
|
|
||||||
@@ -566,6 +521,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_ */
|
||||||
|
@@ -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,16 @@ 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 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>;
|
||||||
|
@@ -18,8 +18,8 @@ class FairMQPoller
|
|||||||
virtual void Poll(const int timeout) = 0;
|
virtual void Poll(const int timeout) = 0;
|
||||||
virtual bool CheckInput(const int index) = 0;
|
virtual bool CheckInput(const int index) = 0;
|
||||||
virtual bool CheckOutput(const int index) = 0;
|
virtual bool CheckOutput(const int index) = 0;
|
||||||
virtual bool CheckInput(const std::string channelKey, const int index) = 0;
|
virtual bool CheckInput(const std::string& channelKey, const int index) = 0;
|
||||||
virtual bool CheckOutput(const std::string channelKey, const int index) = 0;
|
virtual bool CheckOutput(const std::string& channelKey, const int index) = 0;
|
||||||
|
|
||||||
virtual ~FairMQPoller() {};
|
virtual ~FairMQPoller() {};
|
||||||
};
|
};
|
||||||
|
@@ -25,34 +25,32 @@ class FairMQSocket
|
|||||||
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 void 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;
|
|
||||||
virtual int GetSendTimeout() const = 0;
|
|
||||||
virtual bool SetReceiveTimeout(const int timeout, const std::string& address, const std::string& method) = 0;
|
|
||||||
virtual int GetReceiveTimeout() const = 0;
|
|
||||||
|
|
||||||
virtual ~FairMQSocket() {};
|
virtual ~FairMQSocket() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -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>
|
||||||
@@ -644,16 +645,27 @@ bool FairMQStateMachine::CheckCurrentState(int state) const
|
|||||||
{
|
{
|
||||||
return state == static_pointer_cast<FairMQFSM>(fFsm)->fState;
|
return state == static_pointer_cast<FairMQFSM>(fFsm)->fState;
|
||||||
}
|
}
|
||||||
bool FairMQStateMachine::CheckCurrentState(string state) const
|
bool FairMQStateMachine::CheckCurrentState(const string& state) const
|
||||||
{
|
{
|
||||||
return state == GetCurrentStateName();
|
return state == GetCurrentStateName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQStateMachine::ProcessWork()
|
void FairMQStateMachine::ProcessWork()
|
||||||
|
try
|
||||||
{
|
{
|
||||||
static_pointer_cast<FairMQFSM>(fFsm)->ProcessWork();
|
static_pointer_cast<FairMQFSM>(fFsm)->ProcessWork();
|
||||||
|
} catch(...) {
|
||||||
|
{
|
||||||
|
lock_guard<mutex> lock(static_pointer_cast<FairMQFSM>(fFsm)->fWorkMutex);
|
||||||
|
static_pointer_cast<FairMQFSM>(fFsm)->fWorkActive = false;
|
||||||
|
static_pointer_cast<FairMQFSM>(fFsm)->fWorkAvailable = false;
|
||||||
|
static_pointer_cast<FairMQFSM>(fFsm)->fWorkDoneCondition.notify_one();
|
||||||
|
}
|
||||||
|
ChangeState(ERROR_FOUND);
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int FairMQStateMachine::GetEventNumber(const string& event)
|
int FairMQStateMachine::GetEventNumber(const string& event)
|
||||||
{
|
{
|
||||||
return eventNumbers.at(event);
|
return eventNumbers.at(event);
|
||||||
|
@@ -82,7 +82,7 @@ class FairMQStateMachine
|
|||||||
static std::string GetStateName(const State);
|
static std::string GetStateName(const State);
|
||||||
int GetCurrentState() const;
|
int GetCurrentState() const;
|
||||||
bool CheckCurrentState(int state) const;
|
bool CheckCurrentState(int state) const;
|
||||||
bool CheckCurrentState(std::string state) const;
|
bool CheckCurrentState(const std::string& state) const;
|
||||||
|
|
||||||
// actions to be overwritten by derived classes
|
// actions to be overwritten by derived classes
|
||||||
virtual void InitWrapper() {}
|
virtual void InitWrapper() {}
|
||||||
|
@@ -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,22 +41,25 @@ 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; }
|
||||||
|
|
||||||
/// @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) const = 0;
|
||||||
@@ -60,11 +67,9 @@ class FairMQTransportFactory
|
|||||||
/// 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 +78,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 +95,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 +104,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 +118,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);
|
||||||
}
|
}
|
||||||
|
60
fairmq/MemoryResourceTools.h
Normal file
60
fairmq/MemoryResourceTools.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/********************************************************************************
|
||||||
|
* 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 {
|
||||||
|
auto message = targetResource->getTransportFactory()->CreateMessage(containerSizeBytes);
|
||||||
|
std::memcpy(static_cast<fair::mq::byte *>(message->GetData()),
|
||||||
|
container.data(),
|
||||||
|
containerSizeBytes);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* namespace mq */
|
||||||
|
} /* namespace fair */
|
22
fairmq/MemoryResources.cxx
Normal file
22
fairmq/MemoryResources.cxx
Normal 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
116
fairmq/MemoryResources.h
Normal 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 */
|
@@ -21,6 +21,7 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace fair
|
namespace fair
|
||||||
{
|
{
|
||||||
@@ -185,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; };
|
||||||
|
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -88,7 +94,6 @@ void FairMQBenchmarkSampler::Run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (fMsgRate > 0)
|
if (fMsgRate > 0)
|
||||||
{
|
{
|
||||||
rateLimiter.maybe_sleep();
|
rateLimiter.maybe_sleep();
|
||||||
|
@@ -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;
|
||||||
|
@@ -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))
|
||||||
{
|
{
|
||||||
|
@@ -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;
|
||||||
|
|
||||||
|
@@ -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();
|
||||||
|
@@ -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;
|
||||||
|
@@ -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");
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
|
|
||||||
|
@@ -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");
|
||||||
}
|
}
|
||||||
@@ -55,6 +58,25 @@ class FairMQSink : public FairMQDevice//, public OutputPolicy
|
|||||||
auto tStart = std::chrono::high_resolution_clock::now();
|
auto tStart = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
while (CheckCurrentState(RUNNING))
|
while (CheckCurrentState(RUNNING))
|
||||||
|
{
|
||||||
|
if (fMultipart)
|
||||||
|
{
|
||||||
|
FairMQParts parts;
|
||||||
|
|
||||||
|
if (dataInChannel.Receive(parts) >= 0)
|
||||||
|
{
|
||||||
|
if (fMaxIterations > 0)
|
||||||
|
{
|
||||||
|
if (fNumIterations >= fMaxIterations)
|
||||||
|
{
|
||||||
|
LOG(info) << "Configured maximum number of iterations reached.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fNumIterations++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
FairMQMessagePtr msg(dataInChannel.NewMessage());
|
FairMQMessagePtr msg(dataInChannel.NewMessage());
|
||||||
|
|
||||||
@@ -64,12 +86,14 @@ class FairMQSink : public FairMQDevice//, public OutputPolicy
|
|||||||
{
|
{
|
||||||
if (fNumIterations >= fMaxIterations)
|
if (fNumIterations >= fMaxIterations)
|
||||||
{
|
{
|
||||||
|
LOG(info) << "Configured maximum number of iterations reached.";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fNumIterations++;
|
fNumIterations++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto tEnd = std::chrono::high_resolution_clock::now();
|
auto tEnd = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
@@ -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();
|
||||||
|
@@ -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;
|
||||||
|
@@ -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)
|
||||||
|
@@ -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;
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -68,10 +69,9 @@ FairMQPollerNN::FairMQPollerNN(const unordered_map<string, vector<FairMQChannel>
|
|||||||
, fNumItems(0)
|
, fNumItems(0)
|
||||||
, fOffsetMap()
|
, fOffsetMap()
|
||||||
{
|
{
|
||||||
int offset = 0;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
int offset = 0;
|
||||||
// calculate offsets and the total size of the poll item set
|
// calculate offsets and the total size of the poll item set
|
||||||
for (string channel : channelList)
|
for (string channel : channelList)
|
||||||
{
|
{
|
||||||
@@ -88,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);
|
||||||
}
|
}
|
||||||
@@ -106,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)
|
||||||
@@ -184,7 +163,7 @@ bool FairMQPollerNN::CheckOutput(const int index)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FairMQPollerNN::CheckInput(const string channelKey, const int index)
|
bool FairMQPollerNN::CheckInput(const string& channelKey, const int index)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -203,7 +182,7 @@ bool FairMQPollerNN::CheckInput(const string channelKey, const int index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FairMQPollerNN::CheckOutput(const string channelKey, const int index)
|
bool FairMQPollerNN::CheckOutput(const string& channelKey, const int index)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@@ -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;
|
||||||
|
|
||||||
|
@@ -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,6 +28,7 @@
|
|||||||
#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);
|
||||||
|
|
||||||
@@ -39,6 +41,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")
|
||||||
{
|
{
|
||||||
@@ -116,18 +119,13 @@ void FairMQSocketNN::Connect(const string& address)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 +153,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,9 +189,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 nbytes = -1;
|
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());
|
||||||
@@ -205,7 +203,7 @@ int FairMQSocketNN::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const in
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
void* ptr = nullptr;
|
void* ptr = nullptr;
|
||||||
nbytes = nn_recv(fSocket, &ptr, NN_MSG, flags);
|
int nbytes = nn_recv(fSocket, &ptr, NN_MSG, flags);
|
||||||
if (nbytes >= 0)
|
if (nbytes >= 0)
|
||||||
{
|
{
|
||||||
fBytesRx += nbytes;
|
fBytesRx += nbytes;
|
||||||
@@ -214,15 +212,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)
|
||||||
@@ -254,8 +248,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;
|
||||||
|
|
||||||
@@ -279,26 +278,20 @@ int64_t FairMQSocketNN::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fla
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t nbytes = -1;
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
nbytes = nn_send(fSocket, sbuf.data(), sbuf.size(), flags);
|
int64_t nbytes = nn_send(fSocket, sbuf.data(), sbuf.size(), flags);
|
||||||
if (nbytes >= 0)
|
if (nbytes >= 0)
|
||||||
{
|
{
|
||||||
fBytesTx += nbytes;
|
fBytesTx += nbytes;
|
||||||
++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)
|
||||||
@@ -330,8 +323,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)
|
||||||
// {
|
// {
|
||||||
@@ -377,15 +375,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)
|
||||||
@@ -432,12 +426,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;
|
||||||
}
|
}
|
||||||
@@ -449,7 +438,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -459,6 +448,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)
|
||||||
{
|
{
|
||||||
@@ -468,6 +463,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)
|
||||||
{
|
{
|
||||||
@@ -475,6 +483,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;
|
||||||
@@ -495,40 +570,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 == "")
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
#include "FairMQSocket.h"
|
#include "FairMQSocket.h"
|
||||||
#include "FairMQMessage.h"
|
#include "FairMQMessage.h"
|
||||||
|
|
||||||
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 = "");
|
||||||
@@ -27,18 +27,12 @@ class FairMQSocketNN : public FairMQSocket
|
|||||||
bool Bind(const std::string& address) override;
|
bool Bind(const std::string& address) override;
|
||||||
void Connect(const std::string& address) override;
|
void 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 +42,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 +74,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_ */
|
||||||
|
@@ -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) const
|
||||||
{
|
{
|
||||||
return unique_ptr<FairMQSocket>(new FairMQSocketNN(type, name, GetId()));
|
unique_ptr<FairMQSocket> socket(new FairMQSocketNN(type, name, GetId()));
|
||||||
|
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();
|
||||||
|
@@ -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) const 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_ */
|
||||||
|
@@ -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;
|
||||||
|
|
||||||
|
@@ -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();
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -59,9 +60,8 @@ Poller::Poller(const vector<const FairMQChannel*>& channels)
|
|||||||
|
|
||||||
Poller::Poller(const unordered_map<string, vector<FairMQChannel>>& channelsMap, const vector<string>& channelList)
|
Poller::Poller(const unordered_map<string, vector<FairMQChannel>>& channelsMap, const vector<string>& channelList)
|
||||||
{
|
{
|
||||||
int offset = 0;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
int offset = 0;
|
||||||
// calculate offsets and the total size of the poll item set
|
// calculate offsets and the total size of the poll item set
|
||||||
for (string channel : channelList) {
|
for (string channel : channelList) {
|
||||||
fOffsetMap[channel] = offset;
|
fOffsetMap[channel] = offset;
|
||||||
@@ -76,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);
|
||||||
}
|
}
|
||||||
@@ -94,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) {
|
||||||
|
@@ -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;
|
||||||
|
|
||||||
|
@@ -619,114 +619,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
|
||||||
|
@@ -32,7 +32,7 @@ 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 = "");
|
||||||
@@ -54,8 +54,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 +77,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;
|
||||||
|
@@ -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."};
|
||||||
|
@@ -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);
|
||||||
@@ -43,7 +43,6 @@ class TransportFactory : public FairMQTransportFactory
|
|||||||
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;
|
||||||
|
@@ -153,6 +153,7 @@ 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()));
|
||||||
|
|
||||||
// temporary FairMQChannel container
|
// temporary FairMQChannel container
|
||||||
@@ -172,6 +173,7 @@ void ChannelParser(const boost::property_tree::ptree& tree, FairMQChannelMap& ch
|
|||||||
LOG(debug) << "\trcvBufSize = " << commonChannel.GetRcvBufSize();
|
LOG(debug) << "\trcvBufSize = " << commonChannel.GetRcvBufSize();
|
||||||
LOG(debug) << "\tsndKernelSize = " << commonChannel.GetSndKernelSize();
|
LOG(debug) << "\tsndKernelSize = " << commonChannel.GetSndKernelSize();
|
||||||
LOG(debug) << "\trcvKernelSize = " << commonChannel.GetRcvKernelSize();
|
LOG(debug) << "\trcvKernelSize = " << commonChannel.GetRcvKernelSize();
|
||||||
|
LOG(debug) << "\tlinger = " << commonChannel.GetLinger();
|
||||||
LOG(debug) << "\trateLogging = " << commonChannel.GetRateLogging();
|
LOG(debug) << "\trateLogging = " << commonChannel.GetRateLogging();
|
||||||
|
|
||||||
for (int i = 0; i < numSockets; ++i)
|
for (int i = 0; i < numSockets; ++i)
|
||||||
@@ -214,6 +216,7 @@ 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()));
|
||||||
|
|
||||||
LOG(debug) << "" << channelName << "[" << socketCounter << "]:";
|
LOG(debug) << "" << channelName << "[" << socketCounter << "]:";
|
||||||
@@ -225,6 +228,7 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
|
|||||||
LOG(debug) << "\trcvBufSize = " << channel.GetRcvBufSize();
|
LOG(debug) << "\trcvBufSize = " << channel.GetRcvBufSize();
|
||||||
LOG(debug) << "\tsndKernelSize = " << channel.GetSndKernelSize();
|
LOG(debug) << "\tsndKernelSize = " << channel.GetSndKernelSize();
|
||||||
LOG(debug) << "\trcvKernelSize = " << channel.GetRcvKernelSize();
|
LOG(debug) << "\trcvKernelSize = " << channel.GetRcvKernelSize();
|
||||||
|
LOG(debug) << "\tlinger = " << channel.GetLinger();
|
||||||
LOG(debug) << "\trateLogging = " << channel.GetRateLogging();
|
LOG(debug) << "\trateLogging = " << channel.GetRateLogging();
|
||||||
|
|
||||||
channelList.push_back(channel);
|
channelList.push_back(channel);
|
||||||
@@ -253,6 +257,7 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
|
|||||||
LOG(debug) << "\trcvBufSize = " << channel.GetRcvBufSize();
|
LOG(debug) << "\trcvBufSize = " << channel.GetRcvBufSize();
|
||||||
LOG(debug) << "\tsndKernelSize = " << channel.GetSndKernelSize();
|
LOG(debug) << "\tsndKernelSize = " << channel.GetSndKernelSize();
|
||||||
LOG(debug) << "\trcvKernelSize = " << channel.GetRcvKernelSize();
|
LOG(debug) << "\trcvKernelSize = " << channel.GetRcvKernelSize();
|
||||||
|
LOG(debug) << "\tlinger = " << channel.GetLinger();
|
||||||
LOG(debug) << "\trateLogging = " << channel.GetRateLogging();
|
LOG(debug) << "\trateLogging = " << channel.GetRateLogging();
|
||||||
|
|
||||||
channelList.push_back(channel);
|
channelList.push_back(channel);
|
||||||
|
@@ -162,7 +162,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
|
||||||
{
|
{
|
||||||
@@ -185,6 +185,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();
|
||||||
@@ -268,6 +285,7 @@ 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";
|
||||||
|
|
||||||
fChannelKeyMap[typeKey] = ChannelKey{p.first, index, "type"};
|
fChannelKeyMap[typeKey] = ChannelKey{p.first, index, "type"};
|
||||||
@@ -278,6 +296,7 @@ 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"};
|
||||||
|
|
||||||
UpdateVarMap<string>(typeKey, channel.GetType());
|
UpdateVarMap<string>(typeKey, channel.GetType());
|
||||||
@@ -288,6 +307,7 @@ 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());
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
@@ -343,6 +363,24 @@ int FairMQProgOptions::UpdateChannelValue(const string& channelName, int index,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (member == "sndKernelSize")
|
||||||
|
{
|
||||||
|
fFairMQChannelMap.at(channelName).at(index).UpdateSndKernelSize(val);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (member == "rcvKernelSize")
|
||||||
|
{
|
||||||
|
fFairMQChannelMap.at(channelName).at(index).UpdateRcvKernelSize(val);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (member == "linger")
|
||||||
|
{
|
||||||
|
fFairMQChannelMap.at(channelName).at(index).UpdateLinger(val);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (member == "rateLogging")
|
if (member == "rateLogging")
|
||||||
{
|
{
|
||||||
fFairMQChannelMap.at(channelName).at(index).UpdateRateLogging(val);
|
fFairMQChannelMap.at(channelName).at(index).UpdateRateLogging(val);
|
||||||
|
@@ -59,14 +59,14 @@ 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();
|
||||||
|
}
|
||||||
|
else if (fChannelKeyMap.count(key))
|
||||||
{
|
{
|
||||||
UpdateChannelValue(fChannelKeyMap.at(key).channel, fChannelKeyMap.at(key).index, fChannelKeyMap.at(key).member, val);
|
UpdateChannelValue(fChannelKeyMap.at(key).channel, fChannelKeyMap.at(key).index, fChannelKeyMap.at(key).member, val);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
@@ -210,6 +210,12 @@ 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);
|
||||||
|
|
||||||
@@ -223,6 +229,7 @@ class FairMQProgOptions
|
|||||||
vm[key].value() = boost::any(val);
|
vm[key].value() = boost::any(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ParseChannelsFromCmdLine();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FAIRMQPROGOPTIONS_H */
|
#endif /* FAIRMQPROGOPTIONS_H */
|
||||||
|
@@ -56,6 +56,7 @@ 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
|
||||||
NUMSOCKETS,
|
NUMSOCKETS,
|
||||||
lastsocketkey
|
lastsocketkey
|
||||||
@@ -71,6 +72,7 @@ struct SUBOPT
|
|||||||
/*[RCVBUFSIZE] = */ "rcvBufSize",
|
/*[RCVBUFSIZE] = */ "rcvBufSize",
|
||||||
/*[SNDKERNELSIZE] = */ "sndKernelSize",
|
/*[SNDKERNELSIZE] = */ "sndKernelSize",
|
||||||
/*[RCVKERNELSIZE] = */ "rcvKernelSize",
|
/*[RCVKERNELSIZE] = */ "rcvKernelSize",
|
||||||
|
/*[LINGER] = */ "linger",
|
||||||
/*[RATELOGGING] = */ "rateLogging",
|
/*[RATELOGGING] = */ "rateLogging",
|
||||||
/*[NUMSOCKETS] = */ "numSockets",
|
/*[NUMSOCKETS] = */ "numSockets",
|
||||||
nullptr
|
nullptr
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2017-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <termios.h> // for the interactive mode
|
#include <termios.h> // for the interactive mode
|
||||||
#include <poll.h> // for the interactive mode
|
#include <poll.h> // for the interactive mode
|
||||||
#include <csignal> // catching system signals
|
#include <csignal> // catching system signals
|
||||||
|
#include <cstdlib>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
@@ -18,11 +19,18 @@ using namespace std;
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
std::atomic<sig_atomic_t> gSignalStatus(0);
|
std::atomic<sig_atomic_t> gLastSignal(0);
|
||||||
|
std::atomic<int> gSignalCount(0);
|
||||||
|
|
||||||
extern "C" auto signal_handler(int signal) -> void
|
extern "C" auto signal_handler(int signal) -> void
|
||||||
{
|
{
|
||||||
gSignalStatus = signal;
|
++gSignalCount;
|
||||||
|
gLastSignal = signal;
|
||||||
|
|
||||||
|
if (gSignalCount > 1)
|
||||||
|
{
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,18 +41,27 @@ namespace mq
|
|||||||
namespace plugins
|
namespace plugins
|
||||||
{
|
{
|
||||||
|
|
||||||
Control::Control(const string name, const Plugin::Version version, const string maintainer, const string homepage, PluginServices* pluginServices)
|
Control::Control(const string& name, const Plugin::Version version, const string& maintainer, const string& homepage, PluginServices* pluginServices)
|
||||||
: Plugin(name, version, maintainer, homepage, pluginServices)
|
: Plugin(name, version, maintainer, homepage, pluginServices)
|
||||||
, fControllerThread()
|
, fControllerThread()
|
||||||
, fSignalHandlerThread()
|
, fSignalHandlerThread()
|
||||||
, fShutdownThread()
|
|
||||||
, fEvents()
|
, fEvents()
|
||||||
, fEventsMutex()
|
, fEventsMutex()
|
||||||
, fShutdownMutex()
|
, fControllerMutex()
|
||||||
, fNewEvent()
|
, fNewEvent()
|
||||||
, fDeviceTerminationRequested(false)
|
, fDeviceShutdownRequested(false)
|
||||||
, fHasShutdown(false)
|
, fDeviceHasShutdown(false)
|
||||||
|
, fPluginShutdownRequested(false)
|
||||||
{
|
{
|
||||||
|
SubscribeToDeviceStateChange([&](DeviceState newState)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
lock_guard<mutex> lock{fEventsMutex};
|
||||||
|
fEvents.push(newState);
|
||||||
|
}
|
||||||
|
fNewEvent.notify_one();
|
||||||
|
});
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TakeDeviceControl();
|
TakeDeviceControl();
|
||||||
@@ -96,22 +113,39 @@ auto ControlPluginProgramOptions() -> Plugin::ProgOptions
|
|||||||
return pluginOptions;
|
return pluginOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Control::InteractiveMode() -> void
|
struct terminal_config
|
||||||
{
|
{
|
||||||
try
|
terminal_config()
|
||||||
{
|
{
|
||||||
|
termios t;
|
||||||
|
tcgetattr(STDIN_FILENO, &t); // get the current terminal I/O structure
|
||||||
|
t.c_lflag &= ~ICANON; // disable canonical input
|
||||||
|
t.c_lflag &= ~ECHO; // do not echo input chars
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings
|
||||||
|
}
|
||||||
|
|
||||||
|
~terminal_config()
|
||||||
|
{
|
||||||
|
termios t;
|
||||||
|
tcgetattr(STDIN_FILENO, &t); // get the current terminal I/O structure
|
||||||
|
t.c_lflag |= ICANON; // re-enable canonical input
|
||||||
|
t.c_lflag |= ECHO; // echo input chars
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
auto Control::InteractiveMode() -> void
|
||||||
|
try
|
||||||
|
{
|
||||||
RunStartupSequence();
|
RunStartupSequence();
|
||||||
|
|
||||||
char input; // hold the user console input
|
char input; // hold the user console input
|
||||||
pollfd cinfd[1];
|
pollfd cinfd[1];
|
||||||
cinfd[0].fd = fileno(stdin);
|
cinfd[0].fd = fileno(stdin);
|
||||||
cinfd[0].events = POLLIN;
|
cinfd[0].events = POLLIN;
|
||||||
|
cinfd[0].revents = 0;
|
||||||
|
|
||||||
struct termios t;
|
terminal_config tconfig;
|
||||||
tcgetattr(STDIN_FILENO, &t); // get the current terminal I/O structure
|
|
||||||
t.c_lflag &= ~ICANON; // disable canonical input
|
|
||||||
t.c_lflag &= ~ECHO; // do not echo input chars
|
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings
|
|
||||||
|
|
||||||
PrintInteractiveHelp();
|
PrintInteractiveHelp();
|
||||||
|
|
||||||
@@ -121,7 +155,7 @@ auto Control::InteractiveMode() -> void
|
|||||||
{
|
{
|
||||||
if (poll(cinfd, 1, 500))
|
if (poll(cinfd, 1, 500))
|
||||||
{
|
{
|
||||||
if (fDeviceTerminationRequested)
|
if (fDeviceShutdownRequested)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -193,27 +227,26 @@ auto Control::InteractiveMode() -> void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fDeviceTerminationRequested)
|
if (GetCurrentDeviceState() == DeviceState::Error)
|
||||||
{
|
{
|
||||||
keepRunning = false;
|
throw DeviceErrorState("Controlled device transitioned to error state.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fDeviceShutdownRequested)
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tcgetattr(STDIN_FILENO, &t); // get the current terminal I/O structure
|
|
||||||
t.c_lflag |= ICANON; // re-enable canonical input
|
|
||||||
t.c_lflag |= ECHO; // echo input chars
|
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings
|
|
||||||
|
|
||||||
if (!fDeviceTerminationRequested)
|
|
||||||
{
|
|
||||||
RunShutdownSequence();
|
RunShutdownSequence();
|
||||||
}
|
}
|
||||||
}
|
catch (PluginServices::DeviceControlError& e)
|
||||||
catch (PluginServices::DeviceControlError& e)
|
{
|
||||||
{
|
|
||||||
// If we are here, it means another plugin has taken control. That's fine, just print the exception message and do nothing else.
|
// If we are here, it means another plugin has taken control. That's fine, just print the exception message and do nothing else.
|
||||||
LOG(debug) << e.what();
|
LOG(debug) << e.what();
|
||||||
}
|
}
|
||||||
|
catch (DeviceErrorState&)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Control::PrintInteractiveHelp() -> void
|
auto Control::PrintInteractiveHelp() -> void
|
||||||
@@ -234,94 +267,92 @@ auto Control::WaitForNextState() -> DeviceState
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto result = fEvents.front();
|
auto result = fEvents.front();
|
||||||
|
|
||||||
|
if (result == DeviceState::Error)
|
||||||
|
{
|
||||||
|
throw DeviceErrorState("Controlled device transitioned to error state.");
|
||||||
|
}
|
||||||
|
|
||||||
fEvents.pop();
|
fEvents.pop();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Control::StaticMode() -> void
|
auto Control::StaticMode() -> void
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
RunStartupSequence();
|
RunStartupSequence();
|
||||||
|
|
||||||
{
|
{
|
||||||
// Wait for next state, which is DeviceState::Ready,
|
// Wait for next state, which is DeviceState::Ready,
|
||||||
// or for device termination request
|
// or for device shutdown request (Ctrl-C)
|
||||||
unique_lock<mutex> lock{fEventsMutex};
|
unique_lock<mutex> lock{fEventsMutex};
|
||||||
while (fEvents.empty() && !fDeviceTerminationRequested)
|
while (fEvents.empty() && !fDeviceShutdownRequested)
|
||||||
{
|
{
|
||||||
fNewEvent.wait(lock);
|
fNewEvent.wait_for(lock, chrono::milliseconds(50));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fEvents.front() == DeviceState::Error)
|
||||||
|
{
|
||||||
|
throw DeviceErrorState("Controlled device transitioned to error state.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fDeviceTerminationRequested)
|
|
||||||
{
|
|
||||||
RunShutdownSequence();
|
RunShutdownSequence();
|
||||||
}
|
}
|
||||||
}
|
catch (PluginServices::DeviceControlError& e)
|
||||||
catch (PluginServices::DeviceControlError& e)
|
{
|
||||||
{
|
|
||||||
// If we are here, it means another plugin has taken control. That's fine, just print the exception message and do nothing else.
|
// If we are here, it means another plugin has taken control. That's fine, just print the exception message and do nothing else.
|
||||||
LOG(debug) << e.what();
|
LOG(debug) << e.what();
|
||||||
}
|
}
|
||||||
|
catch (DeviceErrorState&)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Control::SignalHandler() -> void
|
auto Control::SignalHandler() -> void
|
||||||
{
|
{
|
||||||
while (true)
|
while (gSignalCount == 0 && !fPluginShutdownRequested)
|
||||||
{
|
{
|
||||||
if (gSignalStatus != 0 && !fHasShutdown)
|
|
||||||
{
|
|
||||||
LOG(info) << "Received device shutdown request (signal " << gSignalStatus << ").";
|
|
||||||
LOG(info) << "Waiting for graceful device shutdown. Hit Ctrl-C again to abort immediately.";
|
|
||||||
|
|
||||||
if (!fDeviceTerminationRequested)
|
|
||||||
{
|
|
||||||
fDeviceTerminationRequested = true;
|
|
||||||
gSignalStatus = 0;
|
|
||||||
fShutdownThread = thread(&Control::HandleShutdownSignal, this);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG(warn) << "Received 2nd device shutdown request (signal " << gSignalStatus << ").";
|
|
||||||
LOG(warn) << "Aborting immediately!";
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (fHasShutdown)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
this_thread::sleep_for(chrono::milliseconds(100));
|
this_thread::sleep_for(chrono::milliseconds(100));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
auto Control::HandleShutdownSignal() -> void
|
if (!fPluginShutdownRequested)
|
||||||
{
|
{
|
||||||
StealDeviceControl();
|
LOG(info) << "Received device shutdown request (signal " << gLastSignal << ").";
|
||||||
|
LOG(info) << "Waiting for graceful device shutdown. Hit Ctrl-C again to abort immediately.";
|
||||||
|
|
||||||
UnsubscribeFromDeviceStateChange(); // In case, static or interactive mode have subscribed already
|
// Signal and wait for controller thread, if we are controller
|
||||||
SubscribeToDeviceStateChange([&](DeviceState newState)
|
fDeviceShutdownRequested = true;
|
||||||
{
|
{
|
||||||
{
|
unique_lock<mutex> lock(fControllerMutex);
|
||||||
lock_guard<mutex> lock{fEventsMutex};
|
if (fControllerThread.joinable()) fControllerThread.join();
|
||||||
fEvents.push(newState);
|
|
||||||
}
|
}
|
||||||
fNewEvent.notify_one();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
if (!fDeviceHasShutdown)
|
||||||
|
{
|
||||||
|
// Take over control and attempt graceful shutdown
|
||||||
|
StealDeviceControl();
|
||||||
|
try
|
||||||
|
{
|
||||||
RunShutdownSequence();
|
RunShutdownSequence();
|
||||||
|
}
|
||||||
|
catch (PluginServices::DeviceControlError& e)
|
||||||
|
{
|
||||||
|
LOG(info) << "Graceful device shutdown failed: " << e.what() << " If hanging, hit Ctrl-C again to abort immediately.";
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
LOG(info) << "Graceful device shutdown failed. If hanging, hit Ctrl-C again to abort immediately.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Control::RunShutdownSequence() -> void
|
auto Control::RunShutdownSequence() -> void
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(fShutdownMutex);
|
|
||||||
if (!fHasShutdown)
|
|
||||||
{
|
|
||||||
auto nextState = GetCurrentDeviceState();
|
auto nextState = GetCurrentDeviceState();
|
||||||
EmptyEventQueue();
|
EmptyEventQueue();
|
||||||
while (nextState != DeviceState::Exiting)
|
while (nextState != DeviceState::Exiting && nextState != DeviceState::Error)
|
||||||
{
|
{
|
||||||
switch (nextState)
|
switch (nextState)
|
||||||
{
|
{
|
||||||
@@ -341,30 +372,19 @@ auto Control::RunShutdownSequence() -> void
|
|||||||
ChangeDeviceState(DeviceStateTransition::Resume);
|
ChangeDeviceState(DeviceStateTransition::Resume);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// ignore other states
|
LOG(debug) << "Controller ignoring event: " << nextState;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
nextState = WaitForNextState();
|
nextState = WaitForNextState();
|
||||||
}
|
}
|
||||||
|
|
||||||
fHasShutdown = true;
|
fDeviceHasShutdown = true;
|
||||||
UnsubscribeFromDeviceStateChange();
|
|
||||||
ReleaseDeviceControl();
|
ReleaseDeviceControl();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Control::RunStartupSequence() -> void
|
auto Control::RunStartupSequence() -> void
|
||||||
{
|
{
|
||||||
SubscribeToDeviceStateChange([&](DeviceState newState)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
lock_guard<mutex> lock{fEventsMutex};
|
|
||||||
fEvents.push(newState);
|
|
||||||
}
|
|
||||||
fNewEvent.notify_one();
|
|
||||||
});
|
|
||||||
|
|
||||||
ChangeDeviceState(DeviceStateTransition::InitDevice);
|
ChangeDeviceState(DeviceStateTransition::InitDevice);
|
||||||
while (WaitForNextState() != DeviceState::DeviceReady) {}
|
while (WaitForNextState() != DeviceState::DeviceReady) {}
|
||||||
ChangeDeviceState(DeviceStateTransition::InitTask);
|
ChangeDeviceState(DeviceStateTransition::InitTask);
|
||||||
@@ -381,9 +401,16 @@ auto Control::EmptyEventQueue() -> void
|
|||||||
|
|
||||||
Control::~Control()
|
Control::~Control()
|
||||||
{
|
{
|
||||||
|
// Notify threads to exit
|
||||||
|
fPluginShutdownRequested = true;
|
||||||
|
|
||||||
|
{
|
||||||
|
unique_lock<mutex> lock(fControllerMutex);
|
||||||
if (fControllerThread.joinable()) fControllerThread.join();
|
if (fControllerThread.joinable()) fControllerThread.join();
|
||||||
|
}
|
||||||
if (fSignalHandlerThread.joinable()) fSignalHandlerThread.join();
|
if (fSignalHandlerThread.joinable()) fSignalHandlerThread.join();
|
||||||
if (fShutdownThread.joinable()) fShutdownThread.join();
|
|
||||||
|
UnsubscribeFromDeviceStateChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace plugins */
|
} /* namespace plugins */
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace fair
|
namespace fair
|
||||||
{
|
{
|
||||||
@@ -29,30 +30,31 @@ namespace plugins
|
|||||||
class Control : public Plugin
|
class Control : public Plugin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Control(const std::string name, const Plugin::Version version, const std::string maintainer, const std::string homepage, PluginServices* pluginServices);
|
Control(const std::string& name, const Plugin::Version version, const std::string& maintainer, const std::string& homepage, PluginServices* pluginServices);
|
||||||
|
|
||||||
~Control();
|
~Control();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
auto InteractiveMode() -> void;
|
auto InteractiveMode() -> void;
|
||||||
auto PrintInteractiveHelp() -> void;
|
static auto PrintInteractiveHelp() -> void;
|
||||||
auto StaticMode() -> void;
|
auto StaticMode() -> void;
|
||||||
auto WaitForNextState() -> DeviceState;
|
auto WaitForNextState() -> DeviceState;
|
||||||
auto SignalHandler() -> void;
|
auto SignalHandler() -> void;
|
||||||
auto HandleShutdownSignal() -> void;
|
|
||||||
auto RunShutdownSequence() -> void;
|
auto RunShutdownSequence() -> void;
|
||||||
auto RunStartupSequence() -> void;
|
auto RunStartupSequence() -> void;
|
||||||
auto EmptyEventQueue() -> void;
|
auto EmptyEventQueue() -> void;
|
||||||
|
|
||||||
std::thread fControllerThread;
|
std::thread fControllerThread;
|
||||||
std::thread fSignalHandlerThread;
|
std::thread fSignalHandlerThread;
|
||||||
std::thread fShutdownThread;
|
|
||||||
std::queue<DeviceState> fEvents;
|
std::queue<DeviceState> fEvents;
|
||||||
std::mutex fEventsMutex;
|
std::mutex fEventsMutex;
|
||||||
std::mutex fShutdownMutex;
|
std::mutex fControllerMutex;
|
||||||
std::condition_variable fNewEvent;
|
std::condition_variable fNewEvent;
|
||||||
std::atomic<bool> fDeviceTerminationRequested;
|
std::atomic<bool> fDeviceShutdownRequested;
|
||||||
std::atomic<bool> fHasShutdown;
|
std::atomic<bool> fDeviceHasShutdown;
|
||||||
|
std::atomic<bool> fPluginShutdownRequested;
|
||||||
|
|
||||||
|
struct DeviceErrorState : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||||
}; /* class Control */
|
}; /* class Control */
|
||||||
|
|
||||||
auto ControlPluginProgramOptions() -> Plugin::ProgOptions;
|
auto ControlPluginProgramOptions() -> Plugin::ProgOptions;
|
||||||
|
@@ -31,7 +31,7 @@ namespace mq
|
|||||||
namespace plugins
|
namespace plugins
|
||||||
{
|
{
|
||||||
|
|
||||||
DDS::DDS(const string name, const Plugin::Version version, const string maintainer, const string homepage, PluginServices* pluginServices)
|
DDS::DDS(const string& name, const Plugin::Version version, const string& maintainer, const string& homepage, PluginServices* pluginServices)
|
||||||
: Plugin(name, version, maintainer, homepage, pluginServices)
|
: Plugin(name, version, maintainer, homepage, pluginServices)
|
||||||
, fService()
|
, fService()
|
||||||
, fDDSCustomCmd(fService)
|
, fDDSCustomCmd(fService)
|
||||||
|
@@ -61,7 +61,7 @@ struct IofN
|
|||||||
class DDS : public Plugin
|
class DDS : public Plugin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DDS(const std::string name, const Plugin::Version version, const std::string maintainer, const std::string homepage, PluginServices* pluginServices);
|
DDS(const std::string& name, const Plugin::Version version, const std::string& maintainer, const std::string& homepage, PluginServices* pluginServices);
|
||||||
|
|
||||||
~DDS();
|
~DDS();
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
string sessionID;
|
string sessionID;
|
||||||
char command;
|
char command = ' ';
|
||||||
string topologyPath;
|
string topologyPath;
|
||||||
|
|
||||||
bpo::options_description options("fairmq-dds-command-ui options");
|
bpo::options_description options("fairmq-dds-command-ui options");
|
||||||
|
@@ -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");
|
||||||
}
|
}
|
||||||
|
@@ -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*/)
|
||||||
|
@@ -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*/)
|
||||||
|
@@ -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*/)
|
||||||
|
@@ -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*/)
|
||||||
|
@@ -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*/)
|
||||||
|
@@ -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 &
|
||||||
|
@@ -56,12 +56,12 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
LOG(error) << "Unhandled exception reached the top of main: " << e.what() << ", application will now exit";
|
LOG(error) << "Uncaught exception reached the top of main: " << e.what();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
LOG(error) << "Non-exception instance being thrown. Please make sure you use std::runtime_exception() instead. Application will now exit.";
|
LOG(error) << "Uncaught exception reached the top of main.";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,8 +9,13 @@
|
|||||||
#define FAIR_MQ_SHMEM_COMMON_H_
|
#define FAIR_MQ_SHMEM_COMMON_H_
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <boost/interprocess/managed_shared_memory.hpp>
|
#include <boost/interprocess/managed_shared_memory.hpp>
|
||||||
|
#include <boost/functional/hash.hpp>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
namespace fair
|
namespace fair
|
||||||
{
|
{
|
||||||
@@ -73,6 +78,16 @@ struct RegionBlock
|
|||||||
size_t fHint;
|
size_t fHint;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// find id for unique shmem name:
|
||||||
|
// a hash of user id + session id, truncated to 8 characters (to accommodate for name size limit on some systems (MacOS)).
|
||||||
|
inline std::string buildShmIdFromSessionIdAndUserId(const std::string& sessionId)
|
||||||
|
{
|
||||||
|
boost::hash<std::string> stringHash;
|
||||||
|
std::string shmId(std::to_string(stringHash(std::string((std::to_string(geteuid()) + sessionId)))));
|
||||||
|
shmId.resize(8, '_');
|
||||||
|
return shmId;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace shmem
|
} // namespace shmem
|
||||||
} // namespace mq
|
} // namespace mq
|
||||||
} // namespace fair
|
} // namespace fair
|
||||||
|
@@ -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)
|
||||||
|
@@ -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;
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -68,10 +69,9 @@ FairMQPollerSHM::FairMQPollerSHM(const unordered_map<string, vector<FairMQChanne
|
|||||||
, fNumItems(0)
|
, fNumItems(0)
|
||||||
, fOffsetMap()
|
, fOffsetMap()
|
||||||
{
|
{
|
||||||
int offset = 0;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
int offset = 0;
|
||||||
// calculate offsets and the total size of the poll item set
|
// calculate offsets and the total size of the poll item set
|
||||||
for (string channel : channelList)
|
for (string channel : channelList)
|
||||||
{
|
{
|
||||||
@@ -89,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);
|
||||||
}
|
}
|
||||||
@@ -109,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)
|
||||||
@@ -189,7 +166,7 @@ bool FairMQPollerSHM::CheckOutput(const int index)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FairMQPollerSHM::CheckInput(const string channelKey, const int index)
|
bool FairMQPollerSHM::CheckInput(const string& channelKey, const int index)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -208,7 +185,7 @@ bool FairMQPollerSHM::CheckInput(const string channelKey, const int index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FairMQPollerSHM::CheckOutput(const string channelKey, const int index)
|
bool FairMQPollerSHM::CheckOutput(const string& channelKey, const int index)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@@ -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;
|
||||||
@@ -37,14 +37,12 @@ class FairMQPollerSHM : public FairMQPoller
|
|||||||
void Poll(const int timeout) override;
|
void Poll(const int timeout) override;
|
||||||
bool CheckInput(const int index) override;
|
bool CheckInput(const int index) override;
|
||||||
bool CheckOutput(const int index) override;
|
bool CheckOutput(const int index) override;
|
||||||
bool CheckInput(const std::string channelKey, const int index) override;
|
bool CheckInput(const std::string& channelKey, const int index) override;
|
||||||
bool CheckOutput(const std::string channelKey, const int index) override;
|
bool CheckOutput(const std::string& channelKey, const int index) override;
|
||||||
|
|
||||||
~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;
|
||||||
|
|
||||||
|
@@ -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,6 +19,7 @@
|
|||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@@ -109,24 +111,18 @@ void FairMQSocketSHM::Connect(const string& address)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 nbytes = -1;
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = ZMQ_DONTWAIT;
|
||||||
|
}
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
while (true && !fInterrupted)
|
while (true && !fInterrupted)
|
||||||
{
|
{
|
||||||
nbytes = zmq_msg_send(static_cast<FairMQMessageSHM*>(msg.get())->GetMessage(), fSocket, flags);
|
int nbytes = zmq_msg_send(static_cast<FairMQMessageSHM*>(msg.get())->GetMessage(), fSocket, flags);
|
||||||
if (nbytes == 0)
|
if (nbytes == 0)
|
||||||
{
|
{
|
||||||
return nbytes;
|
return nbytes;
|
||||||
@@ -145,7 +141,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)
|
||||||
@@ -175,15 +171,19 @@ 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 nbytes = -1;
|
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();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
nbytes = zmq_msg_recv(msgPtr, fSocket, flags);
|
int nbytes = zmq_msg_recv(msgPtr, fSocket, flags);
|
||||||
if (nbytes == 0)
|
if (nbytes == 0)
|
||||||
{
|
{
|
||||||
++fMessagesRx;
|
++fMessagesRx;
|
||||||
@@ -218,7 +218,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)
|
||||||
@@ -246,14 +246,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();
|
||||||
int64_t totalSize = 0;
|
|
||||||
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
|
||||||
@@ -263,7 +267,7 @@ int64_t FairMQSocketSHM::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
|
|||||||
// prepare the message with shm metas
|
// prepare the message with shm metas
|
||||||
MetaHeader* metas = static_cast<MetaHeader*>(zmq_msg_data(&zmqMsg));
|
MetaHeader* metas = static_cast<MetaHeader*>(zmq_msg_data(&zmqMsg));
|
||||||
|
|
||||||
for (auto &msg : msgVec)
|
for (auto& msg : msgVec)
|
||||||
{
|
{
|
||||||
zmq_msg_t* metaMsg = static_cast<FairMQMessageSHM*>(msg.get())->GetMessage();
|
zmq_msg_t* metaMsg = static_cast<FairMQMessageSHM*>(msg.get())->GetMessage();
|
||||||
memcpy(metas++, zmq_msg_data(metaMsg), sizeof(MetaHeader));
|
memcpy(metas++, zmq_msg_data(metaMsg), sizeof(MetaHeader));
|
||||||
@@ -271,9 +275,8 @@ int64_t FairMQSocketSHM::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
|
|||||||
|
|
||||||
while (!fInterrupted)
|
while (!fInterrupted)
|
||||||
{
|
{
|
||||||
int nbytes = -1;
|
int64_t totalSize = 0;
|
||||||
nbytes = zmq_msg_send(&zmqMsg, fSocket, flags);
|
int nbytes = zmq_msg_send(&zmqMsg, fSocket, flags);
|
||||||
|
|
||||||
if (nbytes == 0)
|
if (nbytes == 0)
|
||||||
{
|
{
|
||||||
zmq_msg_close(&zmqMsg);
|
zmq_msg_close(&zmqMsg);
|
||||||
@@ -283,7 +286,7 @@ int64_t FairMQSocketSHM::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fl
|
|||||||
{
|
{
|
||||||
assert(nbytes == (vecSize * sizeof(MetaHeader))); // all or nothing
|
assert(nbytes == (vecSize * sizeof(MetaHeader))); // all or nothing
|
||||||
|
|
||||||
for (auto &msg : msgVec)
|
for (auto& msg : msgVec)
|
||||||
{
|
{
|
||||||
FairMQMessageSHM* shmMsg = static_cast<FairMQMessageSHM*>(msg.get());
|
FairMQMessageSHM* shmMsg = static_cast<FairMQMessageSHM*>(msg.get());
|
||||||
shmMsg->fQueued = true;
|
shmMsg->fQueued = true;
|
||||||
@@ -301,7 +304,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)
|
||||||
@@ -336,9 +339,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)
|
||||||
{
|
{
|
||||||
int64_t totalSize = 0;
|
int flags = 0;
|
||||||
|
if (timeout == 0)
|
||||||
|
{
|
||||||
|
flags = ZMQ_DONTWAIT;
|
||||||
|
}
|
||||||
int elapsed = 0;
|
int elapsed = 0;
|
||||||
|
|
||||||
zmq_msg_t zmqMsg;
|
zmq_msg_t zmqMsg;
|
||||||
@@ -346,6 +353,7 @@ int64_t FairMQSocketSHM::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int
|
|||||||
|
|
||||||
while (!fInterrupted)
|
while (!fInterrupted)
|
||||||
{
|
{
|
||||||
|
int64_t totalSize = 0;
|
||||||
int nbytes = zmq_msg_recv(&zmqMsg, fSocket, flags);
|
int nbytes = zmq_msg_recv(&zmqMsg, fSocket, flags);
|
||||||
if (nbytes == 0)
|
if (nbytes == 0)
|
||||||
{
|
{
|
||||||
@@ -394,7 +402,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)
|
||||||
@@ -459,12 +467,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)
|
||||||
@@ -481,6 +483,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;
|
||||||
@@ -501,112 +588,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;
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <memory> // unique_ptr
|
#include <memory> // unique_ptr
|
||||||
|
|
||||||
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);
|
||||||
@@ -28,18 +28,12 @@ class FairMQSocketSHM : public FairMQSocket
|
|||||||
bool Bind(const std::string& address) override;
|
bool Bind(const std::string& address) override;
|
||||||
void Connect(const std::string& address) override;
|
void 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 +43,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 +76,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_ */
|
||||||
|
@@ -37,7 +37,7 @@ fair::mq::Transport FairMQTransportFactorySHM::fTransportType = fair::mq::Transp
|
|||||||
FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const FairMQProgOptions* config)
|
FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const FairMQProgOptions* config)
|
||||||
: FairMQTransportFactory(id)
|
: FairMQTransportFactory(id)
|
||||||
, fDeviceId(id)
|
, fDeviceId(id)
|
||||||
, fSessionName("default")
|
, fShmId()
|
||||||
, fContext(nullptr)
|
, fContext(nullptr)
|
||||||
, fHeartbeatThread()
|
, fHeartbeatThread()
|
||||||
, fSendHeartbeats(true)
|
, fSendHeartbeats(true)
|
||||||
@@ -58,12 +58,13 @@ FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const Fai
|
|||||||
}
|
}
|
||||||
|
|
||||||
int numIoThreads = 1;
|
int numIoThreads = 1;
|
||||||
|
string sessionName = "default";
|
||||||
size_t segmentSize = 2000000000;
|
size_t segmentSize = 2000000000;
|
||||||
bool autolaunchMonitor = false;
|
bool autolaunchMonitor = false;
|
||||||
if (config)
|
if (config)
|
||||||
{
|
{
|
||||||
numIoThreads = config->GetValue<int>("io-threads");
|
numIoThreads = config->GetValue<int>("io-threads");
|
||||||
fSessionName = config->GetValue<string>("session");
|
sessionName = config->GetValue<string>("session");
|
||||||
segmentSize = config->GetValue<size_t>("shm-segment-size");
|
segmentSize = config->GetValue<size_t>("shm-segment-size");
|
||||||
autolaunchMonitor = config->GetValue<bool>("shm-monitor");
|
autolaunchMonitor = config->GetValue<bool>("shm-monitor");
|
||||||
}
|
}
|
||||||
@@ -72,11 +73,11 @@ FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const Fai
|
|||||||
LOG(debug) << "FairMQProgOptions not available! Using defaults.";
|
LOG(debug) << "FairMQProgOptions not available! Using defaults.";
|
||||||
}
|
}
|
||||||
|
|
||||||
fSessionName.resize(8, '_'); // shorten the session name, to accommodate for name size limit on some systems (MacOS)
|
fShmId = buildShmIdFromSessionIdAndUserId(sessionName);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
fShMutex = fair::mq::tools::make_unique<bipc::named_mutex>(bipc::open_or_create, string("fmq_" + fSessionName + "_mtx").c_str());
|
fShMutex = fair::mq::tools::make_unique<bipc::named_mutex>(bipc::open_or_create, string("fmq_" + fShmId + "_mtx").c_str());
|
||||||
|
|
||||||
if (zmq_ctx_set(fContext, ZMQ_IO_THREADS, numIoThreads) != 0)
|
if (zmq_ctx_set(fContext, ZMQ_IO_THREADS, numIoThreads) != 0)
|
||||||
{
|
{
|
||||||
@@ -89,8 +90,8 @@ FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const Fai
|
|||||||
LOG(error) << "failed configuring context, reason: " << zmq_strerror(errno);
|
LOG(error) << "failed configuring context, reason: " << zmq_strerror(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
fManager = fair::mq::tools::make_unique<Manager>(fSessionName, segmentSize);
|
fManager = fair::mq::tools::make_unique<Manager>(fShmId, segmentSize);
|
||||||
LOG(debug) << "created/opened shared memory segment '" << "fmq_" << fSessionName << "_main" << "' of " << segmentSize << " bytes. Available are " << fManager->Segment().get_free_memory() << " bytes.";
|
LOG(debug) << "created/opened shared memory segment '" << "fmq_" << fShmId << "_main" << "' of " << segmentSize << " bytes. Available are " << fManager->Segment().get_free_memory() << " bytes.";
|
||||||
|
|
||||||
{
|
{
|
||||||
bipc::scoped_lock<bipc::named_mutex> lock(*fShMutex);
|
bipc::scoped_lock<bipc::named_mutex> lock(*fShMutex);
|
||||||
@@ -145,8 +146,6 @@ FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const Fai
|
|||||||
|
|
||||||
void FairMQTransportFactorySHM::StartMonitor()
|
void FairMQTransportFactorySHM::StartMonitor()
|
||||||
{
|
{
|
||||||
int numTries = 0;
|
|
||||||
|
|
||||||
auto env = boost::this_process::environment();
|
auto env = boost::this_process::environment();
|
||||||
|
|
||||||
vector<bfs::path> ownPath = boost::this_process::path();
|
vector<bfs::path> ownPath = boost::this_process::path();
|
||||||
@@ -160,8 +159,8 @@ void FairMQTransportFactorySHM::StartMonitor()
|
|||||||
|
|
||||||
if (!p.empty())
|
if (!p.empty())
|
||||||
{
|
{
|
||||||
boost::process::spawn(p, "-x", "-s", fSessionName, "-d", "-t", "2000", env);
|
boost::process::spawn(p, "-x", "--shmid", fShmId, "-d", "-t", "2000", env);
|
||||||
|
int numTries = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
MonitorStatus* monitorStatus = fManager->ManagementSegment().find<MonitorStatus>(bipc::unique_instance).first;
|
MonitorStatus* monitorStatus = fManager->ManagementSegment().find<MonitorStatus>(bipc::unique_instance).first;
|
||||||
@@ -190,7 +189,7 @@ void FairMQTransportFactorySHM::StartMonitor()
|
|||||||
|
|
||||||
void FairMQTransportFactorySHM::SendHeartbeats()
|
void FairMQTransportFactorySHM::SendHeartbeats()
|
||||||
{
|
{
|
||||||
string controlQueueName("fmq_" + fSessionName + "_cq");
|
string controlQueueName("fmq_" + fShmId + "_cq");
|
||||||
while (fSendHeartbeats)
|
while (fSendHeartbeats)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -214,24 +213,24 @@ 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) const
|
||||||
@@ -245,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));
|
||||||
}
|
}
|
||||||
@@ -255,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));
|
||||||
@@ -312,7 +306,7 @@ FairMQTransportFactorySHM::~FairMQTransportFactorySHM()
|
|||||||
|
|
||||||
if (lastRemoved)
|
if (lastRemoved)
|
||||||
{
|
{
|
||||||
boost::interprocess::named_mutex::remove(string("fmq_" + fSessionName + "_mtx").c_str());
|
bipc::named_mutex::remove(string("fmq_" + fShmId + "_mtx").c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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) const 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;
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ class FairMQTransportFactorySHM : public FairMQTransportFactory
|
|||||||
|
|
||||||
static fair::mq::Transport fTransportType;
|
static fair::mq::Transport fTransportType;
|
||||||
std::string fDeviceId;
|
std::string fDeviceId;
|
||||||
std::string fSessionName;
|
std::string fShmId;
|
||||||
void* fContext;
|
void* fContext;
|
||||||
std::thread fHeartbeatThread;
|
std::thread fHeartbeatThread;
|
||||||
std::atomic<bool> fSendHeartbeats;
|
std::atomic<bool> fSendHeartbeats;
|
||||||
|
@@ -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;
|
||||||
|
@@ -105,7 +105,7 @@ void Manager::RemoveSegment()
|
|||||||
{
|
{
|
||||||
if (bipc::shared_memory_object::remove(fSegmentName.c_str()))
|
if (bipc::shared_memory_object::remove(fSegmentName.c_str()))
|
||||||
{
|
{
|
||||||
LOG(debug) << "successfully removed " << fSegmentName << " segment after the device has stopped.";
|
LOG(debug) << "successfully removed '" << fSegmentName << "' segment after the device has stopped.";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -51,17 +51,17 @@ void signalHandler(int signal)
|
|||||||
gSignalStatus = signal;
|
gSignalStatus = signal;
|
||||||
}
|
}
|
||||||
|
|
||||||
Monitor::Monitor(const string& sessionName, bool selfDestruct, bool interactive, unsigned int timeoutInMS, bool runAsDaemon, bool cleanOnExit)
|
Monitor::Monitor(const string& shmId, bool selfDestruct, bool interactive, unsigned int timeoutInMS, bool runAsDaemon, bool cleanOnExit)
|
||||||
: fSelfDestruct(selfDestruct)
|
: fSelfDestruct(selfDestruct)
|
||||||
, fInteractive(interactive)
|
, fInteractive(interactive)
|
||||||
, fSeenOnce(false)
|
, fSeenOnce(false)
|
||||||
, fIsDaemon(runAsDaemon)
|
, fIsDaemon(runAsDaemon)
|
||||||
, fCleanOnExit(cleanOnExit)
|
, fCleanOnExit(cleanOnExit)
|
||||||
, fTimeoutInMS(timeoutInMS)
|
, fTimeoutInMS(timeoutInMS)
|
||||||
, fSessionName(sessionName)
|
, fShmId(shmId)
|
||||||
, fSegmentName("fmq_" + fSessionName + "_main")
|
, fSegmentName("fmq_" + fShmId + "_main")
|
||||||
, fManagementSegmentName("fmq_" + fSessionName + "_mng")
|
, fManagementSegmentName("fmq_" + fShmId + "_mng")
|
||||||
, fControlQueueName("fmq_" + fSessionName + "_cq")
|
, fControlQueueName("fmq_" + fShmId + "_cq")
|
||||||
, fTerminating(false)
|
, fTerminating(false)
|
||||||
, fHeartbeatTriggered(false)
|
, fHeartbeatTriggered(false)
|
||||||
, fLastHeartbeat(chrono::high_resolution_clock::now())
|
, fLastHeartbeat(chrono::high_resolution_clock::now())
|
||||||
@@ -201,7 +201,7 @@ void Monitor::Interactive()
|
|||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
cout << "\n[x] --> closing shared memory:" << endl;
|
cout << "\n[x] --> closing shared memory:" << endl;
|
||||||
Cleanup(fSessionName);
|
Cleanup(fShmId);
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
cout << "\n[h] --> help:" << endl << endl;
|
cout << "\n[h] --> help:" << endl << endl;
|
||||||
@@ -245,11 +245,11 @@ void Monitor::Interactive()
|
|||||||
|
|
||||||
void Monitor::CheckSegment()
|
void Monitor::CheckSegment()
|
||||||
{
|
{
|
||||||
static uint64_t counter = 0;
|
|
||||||
char c = '#';
|
char c = '#';
|
||||||
|
|
||||||
if (fInteractive)
|
if (fInteractive)
|
||||||
{
|
{
|
||||||
|
static uint64_t counter = 0;
|
||||||
int mod = counter++ % 5;
|
int mod = counter++ % 5;
|
||||||
switch (mod)
|
switch (mod)
|
||||||
{
|
{
|
||||||
@@ -293,7 +293,7 @@ void Monitor::CheckSegment()
|
|||||||
if (fHeartbeatTriggered && duration > fTimeoutInMS)
|
if (fHeartbeatTriggered && duration > fTimeoutInMS)
|
||||||
{
|
{
|
||||||
cout << "no heartbeats since over " << fTimeoutInMS << " milliseconds, cleaning..." << endl;
|
cout << "no heartbeats since over " << fTimeoutInMS << " milliseconds, cleaning..." << endl;
|
||||||
Cleanup(fSessionName);
|
Cleanup(fShmId);
|
||||||
fHeartbeatTriggered = false;
|
fHeartbeatTriggered = false;
|
||||||
if (fSelfDestruct)
|
if (fSelfDestruct)
|
||||||
{
|
{
|
||||||
@@ -340,7 +340,7 @@ void Monitor::CheckSegment()
|
|||||||
|
|
||||||
if (fIsDaemon && duration > fTimeoutInMS * 2)
|
if (fIsDaemon && duration > fTimeoutInMS * 2)
|
||||||
{
|
{
|
||||||
Cleanup(fSessionName);
|
Cleanup(fShmId);
|
||||||
fHeartbeatTriggered = false;
|
fHeartbeatTriggered = false;
|
||||||
if (fSelfDestruct)
|
if (fSelfDestruct)
|
||||||
{
|
{
|
||||||
@@ -360,9 +360,9 @@ void Monitor::CheckSegment()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Monitor::Cleanup(const string& sessionName)
|
void Monitor::Cleanup(const string& shmId)
|
||||||
{
|
{
|
||||||
string managementSegmentName("fmq_" + sessionName + "_mng");
|
string managementSegmentName("fmq_" + shmId + "_mng");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bipc::managed_shared_memory managementSegment(bipc::open_only, managementSegmentName.c_str());
|
bipc::managed_shared_memory managementSegment(bipc::open_only, managementSegmentName.c_str());
|
||||||
@@ -373,8 +373,8 @@ void Monitor::Cleanup(const string& sessionName)
|
|||||||
unsigned int regionCount = rc->fCount;
|
unsigned int regionCount = rc->fCount;
|
||||||
for (unsigned int i = 1; i <= regionCount; ++i)
|
for (unsigned int i = 1; i <= regionCount; ++i)
|
||||||
{
|
{
|
||||||
RemoveObject("fmq_" + sessionName + "_rg_" + to_string(i));
|
RemoveObject("fmq_" + shmId + "_rg_" + to_string(i));
|
||||||
RemoveQueue(string("fmq_" + sessionName + "_rgq_" + to_string(i)));
|
RemoveQueue(string("fmq_" + shmId + "_rgq_" + to_string(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -389,9 +389,8 @@ void Monitor::Cleanup(const string& sessionName)
|
|||||||
cout << "Did not find '" << managementSegmentName << "' shared memory segment. No regions to cleanup." << endl;
|
cout << "Did not find '" << managementSegmentName << "' shared memory segment. No regions to cleanup." << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoveObject("fmq_" + sessionName + "_main");
|
RemoveObject("fmq_" + shmId + "_main");
|
||||||
|
RemoveMutex("fmq_" + shmId + "_mtx");
|
||||||
boost::interprocess::named_mutex::remove(string("fmq_" + sessionName + "_mtx").c_str());
|
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
@@ -420,6 +419,18 @@ void Monitor::RemoveQueue(const string& name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Monitor::RemoveMutex(const string& name)
|
||||||
|
{
|
||||||
|
if (bipc::named_mutex::remove(name.c_str()))
|
||||||
|
{
|
||||||
|
cout << "Successfully removed \"" << name << "\"." << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "Did not remove \"" << name << "\". Already removed?" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Monitor::PrintQueues()
|
void Monitor::PrintQueues()
|
||||||
{
|
{
|
||||||
cout << '\n';
|
cout << '\n';
|
||||||
@@ -427,14 +438,14 @@ void Monitor::PrintQueues()
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
bipc::managed_shared_memory segment(bipc::open_only, fSegmentName.c_str());
|
bipc::managed_shared_memory segment(bipc::open_only, fSegmentName.c_str());
|
||||||
StringVector* queues = segment.find<StringVector>(string("fmq_" + fSessionName + "_qs").c_str()).first;
|
StringVector* queues = segment.find<StringVector>(string("fmq_" + fShmId + "_qs").c_str()).first;
|
||||||
if (queues)
|
if (queues)
|
||||||
{
|
{
|
||||||
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)
|
||||||
@@ -500,7 +511,7 @@ Monitor::~Monitor()
|
|||||||
}
|
}
|
||||||
if (fCleanOnExit)
|
if (fCleanOnExit)
|
||||||
{
|
{
|
||||||
Cleanup(fSessionName);
|
Cleanup(fShmId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -39,6 +39,7 @@ class Monitor
|
|||||||
static void Cleanup(const std::string& sessionName);
|
static void Cleanup(const std::string& sessionName);
|
||||||
static void RemoveObject(const std::string&);
|
static void RemoveObject(const std::string&);
|
||||||
static void RemoveQueue(const std::string&);
|
static void RemoveQueue(const std::string&);
|
||||||
|
static void RemoveMutex(const std::string&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void PrintHeader();
|
void PrintHeader();
|
||||||
@@ -55,7 +56,7 @@ class Monitor
|
|||||||
bool fIsDaemon;
|
bool fIsDaemon;
|
||||||
bool fCleanOnExit;
|
bool fCleanOnExit;
|
||||||
unsigned int fTimeoutInMS;
|
unsigned int fTimeoutInMS;
|
||||||
std::string fSessionName;
|
std::string fShmId;
|
||||||
std::string fSegmentName;
|
std::string fSegmentName;
|
||||||
std::string fManagementSegmentName;
|
std::string fManagementSegmentName;
|
||||||
std::string fControlQueueName;
|
std::string fControlQueueName;
|
||||||
|
@@ -12,8 +12,9 @@ The shared memory monitor tool, supplied with the shared memory transport can be
|
|||||||
|
|
||||||
With default arguments the monitor will run indefinitely with no output, and clean up shared memory segment if it is open and no heartbeats from devices arrive within a timeout period. It can be further customized with following parameters:
|
With default arguments the monitor will run indefinitely with no output, and clean up shared memory segment if it is open and no heartbeats from devices arrive within a timeout period. It can be further customized with following parameters:
|
||||||
|
|
||||||
`--session <arg>`: customize the name of the shared memory segment via the session name (default is "default").
|
`--session <arg>`: for which session to run the monitor (default is "default"). The actual ressource names will be built out of session id, user id (hashed and truncated).
|
||||||
`--cleanup`: start monitor, perform cleanup of the memory and quit.
|
`--cleanup`: start monitor, perform cleanup of the memory and quit.
|
||||||
|
`--shmid <arg>`: if provided, this shmem id will be used instead of the one generated from session id. Use this if you know the name of the shared memory ressource, but do not have the used session id.
|
||||||
`--self-destruct`: run until the memory segment is closed (either naturally via cleanup performed by devices or in case of a crash (no heartbeats within timeout)).
|
`--self-destruct`: run until the memory segment is closed (either naturally via cleanup performed by devices or in case of a crash (no heartbeats within timeout)).
|
||||||
`--interactive`: run interactively, with detailed segment details and user input for various shmem operations.
|
`--interactive`: run interactively, with detailed segment details and user input for various shmem operations.
|
||||||
`--timeout <arg>`: specifiy the timeout for the heartbeats from shmem transports in milliseconds (default 5000).
|
`--timeout <arg>`: specifiy the timeout for the heartbeats from shmem transports in milliseconds (default 5000).
|
||||||
@@ -27,9 +28,9 @@ The Monitor class can also be used independently from the supplied executable (b
|
|||||||
|
|
||||||
FairMQ Shared Memory currently uses following names to register shared memory on the system:
|
FairMQ Shared Memory currently uses following names to register shared memory on the system:
|
||||||
|
|
||||||
`fmq_<sessionName>_main` - main segment name, used for user data (session name can be overridden via `--session`).
|
`fmq_<shmId>_main` - main segment name, used for user data (the shmId is generated out of session id and user id).
|
||||||
`fmq_<sessionName>_mng` - management segment name, used for storing management data.
|
`fmq_<shmId>_mng` - management segment name, used for storing management data.
|
||||||
`fmq_<sessionName>_cq` - message queue for communicating between shm transport and shm monitor (exists independent of above segments).
|
`fmq_<shmId>_cq` - message queue for communicating between shm transport and shm monitor (exists independent of above segments).
|
||||||
`fmq_<sessionName>_mtx` - boost::interprocess::named_mutex for management purposes (exists independent of above segments).
|
`fmq_<shmId>_mtx` - boost::interprocess::named_mutex for management purposes (exists independent of above segments).
|
||||||
`fmq_<sessionName>_rg_<index>` - names of unmanaged regions.
|
`fmq_<shmId>_rg_<index>` - names of unmanaged regions.
|
||||||
`fmq_<sessionName>_rgq_<index>` - names of queues for the unmanaged regions.
|
`fmq_<shmId>_rgq_<index>` - names of queues for the unmanaged regions.
|
||||||
|
@@ -1,76 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# 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" #
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/fairmq/shmem/prototype/shm-prototype.json
|
|
||||||
${CMAKE_BINARY_DIR}/bin/config/shm-prototype.json)
|
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/fairmq/shmem/prototype/startShmPrototype.sh.in
|
|
||||||
${CMAKE_BINARY_DIR}/bin/prototype/shmem/startShmPrototype.sh)
|
|
||||||
|
|
||||||
Set(INCLUDE_DIRECTORIES
|
|
||||||
${CMAKE_SOURCE_DIR}/fairmq
|
|
||||||
${CMAKE_SOURCE_DIR}/fairmq/zeromq
|
|
||||||
${CMAKE_SOURCE_DIR}/fairmq/nanomsg
|
|
||||||
${CMAKE_SOURCE_DIR}/fairmq/devices
|
|
||||||
${CMAKE_SOURCE_DIR}/fairmq/tools
|
|
||||||
${CMAKE_SOURCE_DIR}/fairmq/options
|
|
||||||
${CMAKE_SOURCE_DIR}/fairmq/shmem/prototype
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
Set(SYSTEM_INCLUDE_DIRECTORIES
|
|
||||||
${Boost_INCLUDE_DIR}
|
|
||||||
${ZeroMQ_INCLUDE_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
Include_Directories(${INCLUDE_DIRECTORIES})
|
|
||||||
Include_Directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES})
|
|
||||||
|
|
||||||
Set(LINK_DIRECTORIES
|
|
||||||
${Boost_LIBRARY_DIRS}
|
|
||||||
)
|
|
||||||
|
|
||||||
Link_Directories(${LINK_DIRECTORIES})
|
|
||||||
|
|
||||||
Set(SRCS
|
|
||||||
"FairMQShmPrototypeSampler.cxx"
|
|
||||||
"FairMQShmPrototypeSink.cxx"
|
|
||||||
)
|
|
||||||
|
|
||||||
Set(DEPENDENCIES
|
|
||||||
${DEPENDENCIES}
|
|
||||||
${Boost_INTERPROCESS_LIBRARY}
|
|
||||||
FairMQ
|
|
||||||
)
|
|
||||||
|
|
||||||
Set(LIBRARY_NAME FairMQShmPrototype)
|
|
||||||
|
|
||||||
GENERATE_LIBRARY()
|
|
||||||
|
|
||||||
Set(Exe_Names
|
|
||||||
shm-prototype-sampler
|
|
||||||
shm-prototype-sink
|
|
||||||
)
|
|
||||||
|
|
||||||
Set(Exe_Source
|
|
||||||
runShmPrototypeSampler.cxx
|
|
||||||
runShmPrototypeSink.cxx
|
|
||||||
)
|
|
||||||
|
|
||||||
list(LENGTH Exe_Names _length)
|
|
||||||
math(EXPR _length ${_length}-1)
|
|
||||||
|
|
||||||
set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/prototype/shmem")
|
|
||||||
|
|
||||||
ForEach(_file RANGE 0 ${_length})
|
|
||||||
list(GET Exe_Names ${_file} _name)
|
|
||||||
list(GET Exe_Source ${_file} _src)
|
|
||||||
set(EXE_NAME ${_name})
|
|
||||||
set(SRCS ${_src})
|
|
||||||
set(DEPENDENCIES FairMQShmPrototype)
|
|
||||||
GENERATE_EXECUTABLE()
|
|
||||||
EndForEach(_file RANGE 0 ${_length})
|
|
@@ -1,227 +0,0 @@
|
|||||||
/********************************************************************************
|
|
||||||
* 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" *
|
|
||||||
********************************************************************************/
|
|
||||||
/**
|
|
||||||
* FairMQShmPrototypeSampler.cpp
|
|
||||||
*
|
|
||||||
* @since 2016-04-08
|
|
||||||
* @author A. Rybalchenko
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <thread>
|
|
||||||
#include <chrono>
|
|
||||||
#include <iomanip>
|
|
||||||
|
|
||||||
#include <boost/interprocess/managed_shared_memory.hpp>
|
|
||||||
#include <boost/interprocess/smart_ptr/shared_ptr.hpp>
|
|
||||||
|
|
||||||
#include "FairMQShmPrototypeSampler.h"
|
|
||||||
#include "FairMQProgOptions.h"
|
|
||||||
#include "FairMQLogger.h"
|
|
||||||
|
|
||||||
#include "ShmChunk.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace boost::interprocess;
|
|
||||||
|
|
||||||
FairMQShmPrototypeSampler::FairMQShmPrototypeSampler()
|
|
||||||
: fMsgSize(10000)
|
|
||||||
, fMsgCounter(0)
|
|
||||||
, fMsgRate(1)
|
|
||||||
, fBytesOut(0)
|
|
||||||
, fMsgOut(0)
|
|
||||||
, fBytesOutNew(0)
|
|
||||||
, fMsgOutNew(0)
|
|
||||||
{
|
|
||||||
if (shared_memory_object::remove("FairMQSharedMemoryPrototype"))
|
|
||||||
{
|
|
||||||
LOG(info) << "Successfully removed shared memory upon device start.";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG(info) << "Did not remove shared memory upon device start.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FairMQShmPrototypeSampler::~FairMQShmPrototypeSampler()
|
|
||||||
{
|
|
||||||
if (shared_memory_object::remove("FairMQSharedMemoryPrototype"))
|
|
||||||
{
|
|
||||||
LOG(info) << "Successfully removed shared memory after the device has stopped.";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG(info) << "Did not remove shared memory after the device stopped. Still in use?";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FairMQShmPrototypeSampler::Init()
|
|
||||||
{
|
|
||||||
fMsgSize = fConfig->GetValue<int>("msg-size");
|
|
||||||
fMsgRate = fConfig->GetValue<int>("msg-rate");
|
|
||||||
|
|
||||||
SegmentManager::Instance().InitializeSegment("open_or_create", "FairMQSharedMemoryPrototype", 2000000000);
|
|
||||||
LOG(info) << "Created/Opened shared memory segment of 2,000,000,000 bytes. Available are "
|
|
||||||
<< SegmentManager::Instance().Segment()->get_free_memory() << " bytes.";
|
|
||||||
}
|
|
||||||
|
|
||||||
void FairMQShmPrototypeSampler::Run()
|
|
||||||
{
|
|
||||||
// count sent messages (also used in creating ShmChunk container ID)
|
|
||||||
static uint64_t numSentMsgs = 0;
|
|
||||||
|
|
||||||
LOG(info) << "Starting the benchmark with message size of " << fMsgSize;
|
|
||||||
|
|
||||||
// start rate logger and acknowledgement listener in separate threads
|
|
||||||
thread rateLogger(&FairMQShmPrototypeSampler::Log, this, 1000);
|
|
||||||
// thread resetMsgCounter(&FairMQShmPrototypeSampler::ResetMsgCounter, this);
|
|
||||||
|
|
||||||
// int charnum = 97;
|
|
||||||
|
|
||||||
while (CheckCurrentState(RUNNING))
|
|
||||||
{
|
|
||||||
void* ptr = nullptr;
|
|
||||||
bipc::managed_shared_memory::handle_t handle;
|
|
||||||
|
|
||||||
while (!ptr)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ptr = SegmentManager::Instance().Segment()->allocate(fMsgSize);
|
|
||||||
}
|
|
||||||
catch (bipc::bad_alloc& ba)
|
|
||||||
{
|
|
||||||
this_thread::sleep_for(chrono::milliseconds(50));
|
|
||||||
if (CheckCurrentState(RUNNING))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// // ShmChunk container ID
|
|
||||||
// string chunkID = "c" + to_string(numSentMsgs);
|
|
||||||
// // shared pointer ID
|
|
||||||
// string ownerID = "o" + to_string(numSentMsgs);
|
|
||||||
|
|
||||||
// ShPtrOwner* owner = nullptr;
|
|
||||||
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// owner = SegmentManager::Instance().Segment()->construct<ShPtrOwner>(ownerID.c_str())(
|
|
||||||
// make_managed_shared_ptr(SegmentManager::Instance().Segment()->construct<ShmChunk>(chunkID.c_str())(fMsgSize),
|
|
||||||
// *(SegmentManager::Instance().Segment())));
|
|
||||||
// }
|
|
||||||
// catch (bipc::bad_alloc& ba)
|
|
||||||
// {
|
|
||||||
// LOG(warn) << "Shared memory full...";
|
|
||||||
// this_thread::sleep_for(chrono::milliseconds(100));
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void* ptr = owner->fPtr->GetData();
|
|
||||||
|
|
||||||
// write something to memory, otherwise only (incomplete) allocation will be measured
|
|
||||||
// memset(ptr, 0, fMsgSize);
|
|
||||||
|
|
||||||
// static_cast<char*>(ptr)[3] = charnum++;
|
|
||||||
// if (charnum == 123)
|
|
||||||
// {
|
|
||||||
// charnum = 97;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// LOG(debug) << "chunk handle: " << owner->fPtr->GetHandle();
|
|
||||||
// LOG(debug) << "chunk size: " << owner->fPtr->GetSize();
|
|
||||||
// LOG(debug) << "owner (" << ownerID << ") use count: " << owner->fPtr.use_count();
|
|
||||||
|
|
||||||
// char* cptr = static_cast<char*>(ptr);
|
|
||||||
// LOG(debug) << "check: " << cptr[3];
|
|
||||||
|
|
||||||
// FairMQMessagePtr msg(NewSimpleMessage(ownerID));
|
|
||||||
|
|
||||||
if (ptr)
|
|
||||||
{
|
|
||||||
handle = SegmentManager::Instance().Segment()->get_handle_from_address(ptr);
|
|
||||||
FairMQMessagePtr msg(NewMessage(sizeof(ExMetaHeader)));
|
|
||||||
ExMetaHeader* metaPtr = new(msg->GetData()) ExMetaHeader();
|
|
||||||
metaPtr->fSize = fMsgSize;
|
|
||||||
metaPtr->fHandle = handle;
|
|
||||||
|
|
||||||
// LOG(info) << metaPtr->fSize;
|
|
||||||
// LOG(info) << metaPtr->fHandle;
|
|
||||||
// LOG(warn) << ptr;
|
|
||||||
|
|
||||||
if (Send(msg, "meta", 0) > 0)
|
|
||||||
{
|
|
||||||
fBytesOutNew += fMsgSize;
|
|
||||||
++fMsgOutNew;
|
|
||||||
++numSentMsgs;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SegmentManager::Instance().Segment()->deallocate(ptr);
|
|
||||||
// SegmentManager::Instance().Segment()->destroy_ptr(owner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --fMsgCounter;
|
|
||||||
// while (fMsgCounter == 0)
|
|
||||||
// {
|
|
||||||
// this_thread::sleep_for(chrono::milliseconds(1));
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG(info) << "Sent " << numSentMsgs << " messages, leaving RUNNING state.";
|
|
||||||
|
|
||||||
rateLogger.join();
|
|
||||||
// resetMsgCounter.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FairMQShmPrototypeSampler::Log(const int intervalInMs)
|
|
||||||
{
|
|
||||||
chrono::time_point<chrono::high_resolution_clock> t0 = chrono::high_resolution_clock::now();
|
|
||||||
chrono::time_point<chrono::high_resolution_clock> t1;
|
|
||||||
unsigned long long msSinceLastLog;
|
|
||||||
|
|
||||||
double mbPerSecOut = 0;
|
|
||||||
double msgPerSecOut = 0;
|
|
||||||
|
|
||||||
while (CheckCurrentState(RUNNING))
|
|
||||||
{
|
|
||||||
t1 = chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
msSinceLastLog = chrono::duration_cast<chrono::milliseconds>(t1 - t0).count();
|
|
||||||
|
|
||||||
mbPerSecOut = (static_cast<double>(fBytesOutNew - fBytesOut) / (1024. * 1024.)) / static_cast<double>(msSinceLastLog) * 1000.;
|
|
||||||
fBytesOut = fBytesOutNew;
|
|
||||||
|
|
||||||
msgPerSecOut = static_cast<double>(fMsgOutNew - fMsgOut) / static_cast<double>(msSinceLastLog) * 1000.;
|
|
||||||
fMsgOut = fMsgOutNew;
|
|
||||||
|
|
||||||
LOG(debug) << fixed
|
|
||||||
<< setprecision(0) << "out: " << msgPerSecOut << " msg ("
|
|
||||||
<< setprecision(2) << mbPerSecOut << " MB)\t("
|
|
||||||
<< SegmentManager::Instance().Segment()->get_free_memory() / (1024. * 1024.) << " MB free)";
|
|
||||||
|
|
||||||
t0 = t1;
|
|
||||||
this_thread::sleep_for(chrono::milliseconds(intervalInMs));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FairMQShmPrototypeSampler::ResetMsgCounter()
|
|
||||||
{
|
|
||||||
while (CheckCurrentState(RUNNING))
|
|
||||||
{
|
|
||||||
fMsgCounter = fMsgRate / 100;
|
|
||||||
this_thread::sleep_for(chrono::milliseconds(10));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,45 +0,0 @@
|
|||||||
/********************************************************************************
|
|
||||||
* 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" *
|
|
||||||
********************************************************************************/
|
|
||||||
/**
|
|
||||||
* FairMQShmPrototypeSampler.h
|
|
||||||
*
|
|
||||||
* @since 2016-04-08
|
|
||||||
* @author A. Rybalchenko
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FAIRMQSHMPROTOTYPESAMPLER_H_
|
|
||||||
#define FAIRMQSHMPROTOTYPESAMPLER_H_
|
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
#include "FairMQDevice.h"
|
|
||||||
|
|
||||||
class FairMQShmPrototypeSampler : public FairMQDevice
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FairMQShmPrototypeSampler();
|
|
||||||
virtual ~FairMQShmPrototypeSampler();
|
|
||||||
|
|
||||||
void Log(const int intervalInMs);
|
|
||||||
void ResetMsgCounter();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
unsigned int fMsgSize;
|
|
||||||
unsigned int fMsgCounter;
|
|
||||||
unsigned int fMsgRate;
|
|
||||||
|
|
||||||
unsigned long long fBytesOut;
|
|
||||||
unsigned long long fMsgOut;
|
|
||||||
std::atomic<unsigned long long> fBytesOutNew;
|
|
||||||
std::atomic<unsigned long long> fMsgOutNew;
|
|
||||||
|
|
||||||
virtual void Init();
|
|
||||||
virtual void Run();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* FAIRMQSHMPROTOTYPESAMPLER_H_ */
|
|
@@ -1,145 +0,0 @@
|
|||||||
/********************************************************************************
|
|
||||||
* 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" *
|
|
||||||
********************************************************************************/
|
|
||||||
/**
|
|
||||||
* FairMQShmPrototypeSink.cxx
|
|
||||||
*
|
|
||||||
* @since 2016-04-08
|
|
||||||
* @author A. Rybalchenko
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <thread>
|
|
||||||
#include <chrono>
|
|
||||||
#include <iomanip>
|
|
||||||
|
|
||||||
#include <boost/interprocess/managed_shared_memory.hpp>
|
|
||||||
#include <boost/interprocess/smart_ptr/shared_ptr.hpp>
|
|
||||||
|
|
||||||
#include "FairMQShmPrototypeSink.h"
|
|
||||||
#include "FairMQProgOptions.h"
|
|
||||||
#include "FairMQLogger.h"
|
|
||||||
|
|
||||||
#include "ShmChunk.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace boost::interprocess;
|
|
||||||
|
|
||||||
FairMQShmPrototypeSink::FairMQShmPrototypeSink()
|
|
||||||
: fBytesIn(0)
|
|
||||||
, fMsgIn(0)
|
|
||||||
, fBytesInNew(0)
|
|
||||||
, fMsgInNew(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
FairMQShmPrototypeSink::~FairMQShmPrototypeSink()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void FairMQShmPrototypeSink::Init()
|
|
||||||
{
|
|
||||||
SegmentManager::Instance().InitializeSegment("open_or_create", "FairMQSharedMemoryPrototype", 2000000000);
|
|
||||||
LOG(info) << "Created/Opened shared memory segment of 2,000,000,000 bytes. Available are "
|
|
||||||
<< SegmentManager::Instance().Segment()->get_free_memory() << " bytes.";
|
|
||||||
}
|
|
||||||
|
|
||||||
void FairMQShmPrototypeSink::Run()
|
|
||||||
{
|
|
||||||
static uint64_t numReceivedMsgs = 0;
|
|
||||||
|
|
||||||
thread rateLogger(&FairMQShmPrototypeSink::Log, this, 1000);
|
|
||||||
|
|
||||||
while (CheckCurrentState(RUNNING))
|
|
||||||
{
|
|
||||||
FairMQMessagePtr msg(NewMessage());
|
|
||||||
|
|
||||||
if (Receive(msg, "meta") > 0)
|
|
||||||
{
|
|
||||||
ExMetaHeader* hdr = static_cast<ExMetaHeader*>(msg->GetData());
|
|
||||||
size_t size = hdr->fSize;
|
|
||||||
bipc::managed_shared_memory::handle_t handle = hdr->fHandle;
|
|
||||||
void* ptr = SegmentManager::Instance().Segment()->get_address_from_handle(handle);
|
|
||||||
|
|
||||||
// LOG(info) << size;
|
|
||||||
// LOG(info) << handle;
|
|
||||||
// LOG(warn) << ptr;
|
|
||||||
|
|
||||||
fBytesInNew += size;
|
|
||||||
++fMsgInNew;
|
|
||||||
SegmentManager::Instance().Segment()->deallocate(ptr);
|
|
||||||
|
|
||||||
// get the shared pointer ID from the received message
|
|
||||||
// string ownerID(static_cast<char*>(msg->GetData()), msg->GetSize());
|
|
||||||
|
|
||||||
// find the shared pointer in shared memory with its ID
|
|
||||||
// ShPtrOwner* owner = SegmentManager::Instance().Segment()->find<ShPtrOwner>(ownerID.c_str()).first;
|
|
||||||
// LOG(debug) << "owner (" << ownerID << ") use count: " << owner->fPtr.use_count();
|
|
||||||
|
|
||||||
|
|
||||||
// if (owner)
|
|
||||||
// {
|
|
||||||
// // void* ptr = owner->fPtr->GetData();
|
|
||||||
|
|
||||||
// // LOG(debug) << "chunk handle: " << owner->fPtr->GetHandle();
|
|
||||||
// // LOG(debug) << "chunk size: " << owner->fPtr->GetSize();
|
|
||||||
|
|
||||||
// fBytesInNew += owner->fPtr->GetSize();
|
|
||||||
// ++fMsgInNew;
|
|
||||||
|
|
||||||
// // char* cptr = static_cast<char*>(ptr);
|
|
||||||
// // LOG(debug) << "check: " << cptr[3];
|
|
||||||
|
|
||||||
// SegmentManager::Instance().Segment()->deallocate(ptr);
|
|
||||||
|
|
||||||
// // SegmentManager::Instance().Segment()->destroy_ptr(owner);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// LOG(warn) << "Shared pointer is zero.";
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
++numReceivedMsgs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG(info) << "Received " << numReceivedMsgs << " messages, leaving RUNNING state.";
|
|
||||||
|
|
||||||
rateLogger.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FairMQShmPrototypeSink::Log(const int intervalInMs)
|
|
||||||
{
|
|
||||||
chrono::time_point<chrono::high_resolution_clock> t0 = chrono::high_resolution_clock::now();
|
|
||||||
chrono::time_point<chrono::high_resolution_clock> t1;
|
|
||||||
unsigned long long msSinceLastLog;
|
|
||||||
|
|
||||||
double mbPerSecIn = 0;
|
|
||||||
double msgPerSecIn = 0;
|
|
||||||
|
|
||||||
while (CheckCurrentState(RUNNING))
|
|
||||||
{
|
|
||||||
t1 = chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
msSinceLastLog = chrono::duration_cast<chrono::milliseconds>(t1 - t0).count();
|
|
||||||
|
|
||||||
mbPerSecIn = (static_cast<double>(fBytesInNew - fBytesIn) / (1024. * 1024.)) / static_cast<double>(msSinceLastLog) * 1000.;
|
|
||||||
fBytesIn = fBytesInNew;
|
|
||||||
|
|
||||||
msgPerSecIn = static_cast<double>(fMsgInNew - fMsgIn) / static_cast<double>(msSinceLastLog) * 1000.;
|
|
||||||
fMsgIn = fMsgInNew;
|
|
||||||
|
|
||||||
LOG(debug) << fixed
|
|
||||||
<< setprecision(0) << "in: " << msgPerSecIn << " msg ("
|
|
||||||
<< setprecision(2) << mbPerSecIn << " MB)\t("
|
|
||||||
<< SegmentManager::Instance().Segment()->get_free_memory() / (1024. * 1024.) << " MB free)";
|
|
||||||
|
|
||||||
t0 = t1;
|
|
||||||
this_thread::sleep_for(chrono::milliseconds(intervalInMs));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,40 +0,0 @@
|
|||||||
/********************************************************************************
|
|
||||||
* 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" *
|
|
||||||
********************************************************************************/
|
|
||||||
/**
|
|
||||||
* FairMQShmPrototypeSink.h
|
|
||||||
*
|
|
||||||
* @since 2016-04-08
|
|
||||||
* @author A. Rybalchenko
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FAIRMQSHMPROTOTYPESINK_H_
|
|
||||||
#define FAIRMQSHMPROTOTYPESINK_H_
|
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
#include "FairMQDevice.h"
|
|
||||||
|
|
||||||
class FairMQShmPrototypeSink : public FairMQDevice
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FairMQShmPrototypeSink();
|
|
||||||
virtual ~FairMQShmPrototypeSink();
|
|
||||||
|
|
||||||
void Log(const int intervalInMs);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
unsigned long long fBytesIn;
|
|
||||||
unsigned long long fMsgIn;
|
|
||||||
std::atomic<unsigned long long> fBytesInNew;
|
|
||||||
std::atomic<unsigned long long> fMsgInNew;
|
|
||||||
|
|
||||||
virtual void Init();
|
|
||||||
virtual void Run();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* FAIRMQSHMPROTOTYPESINK_H_ */
|
|
@@ -1,182 +0,0 @@
|
|||||||
/********************************************************************************
|
|
||||||
* 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" *
|
|
||||||
********************************************************************************/
|
|
||||||
/**
|
|
||||||
* ShmChunk.h
|
|
||||||
*
|
|
||||||
* @since 2016-04-08
|
|
||||||
* @author A. Rybalchenko
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SHMCHUNK_H_
|
|
||||||
#define SHMCHUNK_H_
|
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
#include <boost/interprocess/managed_shared_memory.hpp>
|
|
||||||
#include <boost/interprocess/smart_ptr/shared_ptr.hpp>
|
|
||||||
|
|
||||||
#include "FairMQLogger.h"
|
|
||||||
|
|
||||||
namespace bipc = boost::interprocess;
|
|
||||||
|
|
||||||
class SegmentManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static SegmentManager& Instance()
|
|
||||||
{
|
|
||||||
static SegmentManager man;
|
|
||||||
return man;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeSegment(const std::string& op, const std::string& name, const size_t size = 0)
|
|
||||||
{
|
|
||||||
if (!fSegment)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (op == "open_or_create")
|
|
||||||
{
|
|
||||||
fSegment = new bipc::managed_shared_memory(bipc::open_or_create, name.c_str(), size);
|
|
||||||
}
|
|
||||||
else if (op == "create_only")
|
|
||||||
{
|
|
||||||
fSegment = new bipc::managed_shared_memory(bipc::create_only, name.c_str(), size);
|
|
||||||
}
|
|
||||||
else if (op == "open_only")
|
|
||||||
{
|
|
||||||
int numTries = 0;
|
|
||||||
bool success = false;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
fSegment = new bipc::managed_shared_memory(bipc::open_only, name.c_str());
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
catch (bipc::interprocess_exception& ie)
|
|
||||||
{
|
|
||||||
if (++numTries == 5)
|
|
||||||
{
|
|
||||||
LOG(error) << "Could not open shared memory after " << numTries << " attempts, exiting!";
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG(debug) << "Could not open shared memory segment on try " << numTries << ". Retrying in 1 second...";
|
|
||||||
LOG(debug) << ie.what();
|
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (!success);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG(error) << "Unknown operation when initializing shared memory segment: " << op;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (std::exception& e)
|
|
||||||
{
|
|
||||||
LOG(error) << "Exception during shared memory segment initialization: " << e.what() << ", application will now exit";
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG(info) << "Segment already initialized";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bipc::managed_shared_memory* Segment() const
|
|
||||||
{
|
|
||||||
if (fSegment)
|
|
||||||
{
|
|
||||||
return fSegment;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG(error) << "Segment not initialized";
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
SegmentManager()
|
|
||||||
: fSegment(nullptr)
|
|
||||||
{}
|
|
||||||
|
|
||||||
bipc::managed_shared_memory* fSegment;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct alignas(16) ExMetaHeader
|
|
||||||
{
|
|
||||||
uint64_t fSize;
|
|
||||||
bipc::managed_shared_memory::handle_t fHandle;
|
|
||||||
};
|
|
||||||
|
|
||||||
// class ShmChunk
|
|
||||||
// {
|
|
||||||
// public:
|
|
||||||
// ShmChunk()
|
|
||||||
// : fHandle()
|
|
||||||
// , fSize(0)
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ShmChunk(const size_t size)
|
|
||||||
// : fHandle()
|
|
||||||
// , fSize(size)
|
|
||||||
// {
|
|
||||||
// void* ptr = SegmentManager::Instance().Segment()->allocate(size);
|
|
||||||
// fHandle = SegmentManager::Instance().Segment()->get_handle_from_address(ptr);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ~ShmChunk()
|
|
||||||
// {
|
|
||||||
// SegmentManager::Instance().Segment()->deallocate(SegmentManager::Instance().Segment()->get_address_from_handle(fHandle));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// bipc::managed_shared_memory::handle_t GetHandle() const
|
|
||||||
// {
|
|
||||||
// return fHandle;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void* GetData() const
|
|
||||||
// {
|
|
||||||
// return SegmentManager::Instance().Segment()->get_address_from_handle(fHandle);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// size_t GetSize() const
|
|
||||||
// {
|
|
||||||
// return fSize;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private:
|
|
||||||
// bipc::managed_shared_memory::handle_t fHandle;
|
|
||||||
// size_t fSize;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// typedef bipc::managed_shared_ptr<ShmChunk, bipc::managed_shared_memory>::type ShPtrType;
|
|
||||||
|
|
||||||
// struct ShPtrOwner
|
|
||||||
// {
|
|
||||||
// ShPtrOwner(const ShPtrType& other)
|
|
||||||
// : fPtr(other)
|
|
||||||
// {}
|
|
||||||
|
|
||||||
// ShPtrOwner(const ShPtrOwner& other)
|
|
||||||
// : fPtr(other.fPtr)
|
|
||||||
// {}
|
|
||||||
|
|
||||||
// ShPtrType fPtr;
|
|
||||||
// };
|
|
||||||
|
|
||||||
#endif /* SHMCHUNK_H_ */
|
|
@@ -1,24 +0,0 @@
|
|||||||
/********************************************************************************
|
|
||||||
* 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" *
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
#include "runFairMQDevice.h"
|
|
||||||
#include "FairMQShmPrototypeSampler.h"
|
|
||||||
|
|
||||||
namespace bpo = boost::program_options;
|
|
||||||
|
|
||||||
void addCustomOptions(bpo::options_description& options)
|
|
||||||
{
|
|
||||||
options.add_options()
|
|
||||||
("msg-size", bpo::value<int>()->default_value(1000), "Message size in bytes")
|
|
||||||
("msg-rate", bpo::value<int>()->default_value(0), "Msg rate limit in maximum number of messages per second");
|
|
||||||
}
|
|
||||||
|
|
||||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
|
||||||
{
|
|
||||||
return new FairMQShmPrototypeSampler();
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
{
|
|
||||||
"fairMQOptions": {
|
|
||||||
"devices": [
|
|
||||||
{
|
|
||||||
"id": "sampler1",
|
|
||||||
"channels": [
|
|
||||||
{
|
|
||||||
"name": "meta",
|
|
||||||
"type": "push",
|
|
||||||
"method": "bind",
|
|
||||||
"address": "tcp://127.0.0.1:5555",
|
|
||||||
"sndBufSize": 10,
|
|
||||||
"rcvBufSize": 10,
|
|
||||||
"rateLogging": 0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "sink1",
|
|
||||||
"channels": [
|
|
||||||
{
|
|
||||||
"name": "meta",
|
|
||||||
"type": "pull",
|
|
||||||
"method": "connect",
|
|
||||||
"address": "tcp://127.0.0.1:5555",
|
|
||||||
"sndBufSize": 10,
|
|
||||||
"rcvBufSize": 10,
|
|
||||||
"rateLogging": 0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,49 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
msgSize="1000000"
|
|
||||||
transport="zeromq"
|
|
||||||
|
|
||||||
if [[ $1 =~ ^[0-9]+$ ]]; then
|
|
||||||
msgSize=$1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Starting shared memory example with message size of $msgSize bytes."
|
|
||||||
echo ""
|
|
||||||
echo "Usage: startShmPrototype [message size=1000000]"
|
|
||||||
|
|
||||||
SAMPLER="shm-prototype-sampler"
|
|
||||||
SAMPLER+=" --id sampler1"
|
|
||||||
SAMPLER+=" --transport $transport"
|
|
||||||
# SAMPLER+=" --severity TRACE"
|
|
||||||
SAMPLER+=" --msg-size $msgSize"
|
|
||||||
# SAMPLER+=" --msg-rate 1000"
|
|
||||||
SAMPLER+=" --mq-config @CMAKE_BINARY_DIR@/bin/config/shm-prototype.json"
|
|
||||||
xterm -geometry 80x32+0+0 -hold -e @CMAKE_BINARY_DIR@/bin/prototype/shmem/$SAMPLER &
|
|
||||||
|
|
||||||
SINK1="shm-prototype-sink"
|
|
||||||
SINK1+=" --id sink1"
|
|
||||||
SINK1+=" --transport $transport"
|
|
||||||
# SINK1+=" --severity TRACE"
|
|
||||||
SINK1+=" --mq-config @CMAKE_BINARY_DIR@/bin/config/shm-prototype.json"
|
|
||||||
xterm -geometry 80x32+500+0 -hold -e @CMAKE_BINARY_DIR@/bin/prototype/shmem/$SINK1 &
|
|
||||||
|
|
||||||
# SINK2="shm-prototype-sink"
|
|
||||||
# SINK2+=" --id sink2"
|
|
||||||
# SINK2+=" --transport $transport"
|
|
||||||
# # SINK2+=" --severity TRACE"
|
|
||||||
# SINK2+=" --mq-config @CMAKE_BINARY_DIR@/bin/config/shm-prototype.json"
|
|
||||||
# xterm -geometry 80x32+500+500 -hold -e @CMAKE_BINARY_DIR@/bin/prototype/shmem/$SINK2 &
|
|
||||||
|
|
||||||
# SINK3="shm-prototype-sink"
|
|
||||||
# SINK3+=" --id sink3"
|
|
||||||
# SINK3+=" --transport $transport"
|
|
||||||
# # SINK3+=" --severity TRACE"
|
|
||||||
# SINK3+=" --mq-config @CMAKE_BINARY_DIR@/bin/config/shm-prototype.json"
|
|
||||||
# xterm -geometry 80x32+1000+0 -hold -e @CMAKE_BINARY_DIR@/bin/prototype/shmem/$SINK3 &
|
|
||||||
|
|
||||||
# SINK4="shm-prototype-sink"
|
|
||||||
# SINK4+=" --id sink4"
|
|
||||||
# SINK4+=" --transport $transport"
|
|
||||||
# # SINK4+=" --severity TRACE"
|
|
||||||
# SINK4+=" --mq-config @CMAKE_BINARY_DIR@/bin/config/shm-prototype.json"
|
|
||||||
# xterm -geometry 80x32+1000+500 -hold -e @CMAKE_BINARY_DIR@/bin/prototype/shmem/$SINK4 &
|
|
@@ -6,6 +6,7 @@
|
|||||||
* copied verbatim in the file "LICENSE" *
|
* copied verbatim in the file "LICENSE" *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
#include <fairmq/shmem/Monitor.h>
|
#include <fairmq/shmem/Monitor.h>
|
||||||
|
#include <fairmq/shmem/Common.h>
|
||||||
|
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost::program_options;
|
using namespace boost::program_options;
|
||||||
|
using namespace fair::mq::shmem;
|
||||||
|
|
||||||
static void daemonize()
|
static void daemonize()
|
||||||
{
|
{
|
||||||
@@ -68,16 +70,18 @@ int main(int argc, char** argv)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string sessionName;
|
string sessionName;
|
||||||
|
string shmId;
|
||||||
bool cleanup = false;
|
bool cleanup = false;
|
||||||
bool selfDestruct = false;
|
bool selfDestruct = false;
|
||||||
bool interactive = false;
|
bool interactive = false;
|
||||||
unsigned int timeoutInMS;
|
unsigned int timeoutInMS = 5000;
|
||||||
bool runAsDaemon = false;
|
bool runAsDaemon = false;
|
||||||
bool cleanOnExit = false;
|
bool cleanOnExit = false;
|
||||||
|
|
||||||
options_description desc("Options");
|
options_description desc("Options");
|
||||||
desc.add_options()
|
desc.add_options()
|
||||||
("session,s", value<string>(&sessionName)->default_value("default"), "Name of the session which to monitor")
|
("session,s", value<string>(&sessionName)->default_value("default"), "session id which to monitor")
|
||||||
|
("shmid", value<string>(&shmId)->default_value(""), "Shmem Id to monitor (if not provided, it is generated out of session id and user id)")
|
||||||
("cleanup,c", value<bool>(&cleanup)->implicit_value(true), "Perform cleanup and quit")
|
("cleanup,c", value<bool>(&cleanup)->implicit_value(true), "Perform cleanup and quit")
|
||||||
("self-destruct,x", value<bool>(&selfDestruct)->implicit_value(true), "Quit after first closing of the memory")
|
("self-destruct,x", value<bool>(&selfDestruct)->implicit_value(true), "Quit after first closing of the memory")
|
||||||
("interactive,i", value<bool>(&interactive)->implicit_value(true), "Interactive run")
|
("interactive,i", value<bool>(&interactive)->implicit_value(true), "Interactive run")
|
||||||
@@ -97,24 +101,27 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
notify(vm);
|
notify(vm);
|
||||||
|
|
||||||
sessionName.resize(8, '_'); // shorten the session name, to accommodate for name size limit on some systems (MacOS)
|
|
||||||
|
|
||||||
if (runAsDaemon)
|
if (runAsDaemon)
|
||||||
{
|
{
|
||||||
daemonize();
|
daemonize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shmId == "")
|
||||||
|
{
|
||||||
|
shmId = buildShmIdFromSessionIdAndUserId(sessionName);
|
||||||
|
}
|
||||||
|
|
||||||
if (cleanup)
|
if (cleanup)
|
||||||
{
|
{
|
||||||
cout << "Cleaning up \"" << sessionName << "\"..." << endl;
|
cout << "Cleaning up \"" << shmId << "\"..." << endl;
|
||||||
fair::mq::shmem::Monitor::Cleanup(sessionName);
|
Monitor::Cleanup(shmId);
|
||||||
fair::mq::shmem::Monitor::RemoveQueue("fmq_" + sessionName + "_cq");
|
Monitor::RemoveQueue("fmq_" + shmId + "_cq");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Starting shared memory monitor for session: \"" << sessionName << "\"..." << endl;
|
cout << "Starting shared memory monitor for session: \"" << sessionName << "\" (shmId: " << shmId << ")..." << endl;
|
||||||
|
|
||||||
fair::mq::shmem::Monitor monitor{sessionName, selfDestruct, interactive, timeoutInMS, runAsDaemon, cleanOnExit};
|
Monitor monitor{shmId, selfDestruct, interactive, timeoutInMS, runAsDaemon, cleanOnExit};
|
||||||
|
|
||||||
monitor.CatchSignals();
|
monitor.CatchSignals();
|
||||||
monitor.Run();
|
monitor.Run();
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -30,23 +31,33 @@ namespace tools
|
|||||||
* @param[in] log_prefix How to prefix each captured output line with
|
* @param[in] log_prefix How to prefix each captured output line with
|
||||||
* @return Captured stdout output and exit code
|
* @return Captured stdout output and exit code
|
||||||
*/
|
*/
|
||||||
execute_result execute(string cmd, string prefix)
|
execute_result execute(const string& cmd, const string& prefix, const string& input)
|
||||||
{
|
{
|
||||||
execute_result result;
|
execute_result result;
|
||||||
stringstream out;
|
stringstream out;
|
||||||
|
|
||||||
// print full line thread-safe
|
// print full line thread-safe
|
||||||
stringstream printCmd;
|
stringstream printCmd;
|
||||||
printCmd << prefix << cmd << "\n";
|
printCmd << prefix << " " << cmd << "\n";
|
||||||
cout << printCmd.str() << flush;
|
cout << printCmd.str() << flush;
|
||||||
|
|
||||||
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 stdout;
|
boost::process::ipstream c_stdout;
|
||||||
boost::process::child c(cmd, boost::process::std_out > stdout);
|
boost::process::opstream c_stdin;
|
||||||
|
boost::process::child c(
|
||||||
|
cmd, boost::process::std_out > c_stdout, boost::process::std_in < c_stdin);
|
||||||
|
|
||||||
|
// Optionally, write to stdin of the child
|
||||||
|
if (input != "") {
|
||||||
|
this_thread::sleep_for(chrono::milliseconds(100));
|
||||||
|
c_stdin << input;
|
||||||
|
c_stdin.flush();
|
||||||
|
}
|
||||||
|
|
||||||
string line;
|
string line;
|
||||||
while (getline(stdout, line))
|
while (getline(c_stdout, line))
|
||||||
{
|
{
|
||||||
// print full line thread-safe
|
// print full line thread-safe
|
||||||
stringstream printLine;
|
stringstream printLine;
|
||||||
|
@@ -32,10 +32,13 @@ struct execute_result
|
|||||||
* and exit code.
|
* and exit code.
|
||||||
*
|
*
|
||||||
* @param[in] cmd Command to execute
|
* @param[in] cmd Command to execute
|
||||||
* @param[in] log_prefix How to prefix each captured output line with
|
* @param[in] prefix How to prefix each captured output line with
|
||||||
|
* @param[in] input Data which is sent to stdin of the child process
|
||||||
* @return Captured stdout output and exit code
|
* @return Captured stdout output and exit code
|
||||||
*/
|
*/
|
||||||
execute_result execute(std::string cmd, std::string prefix = "");
|
execute_result execute(const std::string& cmd,
|
||||||
|
const std::string& prefix = "",
|
||||||
|
const std::string& input = "");
|
||||||
|
|
||||||
} /* namespace tools */
|
} /* namespace tools */
|
||||||
} /* namespace mq */
|
} /* namespace mq */
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user