mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Support multiple endpoints per socket
Sent messages will be scheduled among the endpoints according to socket type: PUB will send the same data to all endpoints simultaneously, PUSH will do round robin transfer. Incoming data is fair queued between endpoints. This is a feature of at least zeromq and nanomsg. _____________ To use: in the device configuration, instead of specifying just one address, specify a comma separated list e.g. tcp://localhost:123,ipc:///tmp/socket the connection method (bind/connect) applies to all endpoints in this case. ______________ Mixing binding and connecting endpoints is supported: prefix "@" means "bind", "+" (or ">") means connect, e.g. +tcp://localhost:123,@ipc:///tmp/socket,ipc:///tmp/asd (in case of missing prefix, the default channel method is used for that endpoint).
This commit is contained in:
@@ -11,3 +11,53 @@
|
||||
* @since 2012-12-05
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include "FairMQSocket.h"
|
||||
|
||||
bool FairMQSocket::Attach(const std::string& config, bool serverish)
|
||||
{
|
||||
if (config.empty())
|
||||
return false;
|
||||
if (config.size()<2)
|
||||
return false;
|
||||
|
||||
const char* endpoints = config.c_str();
|
||||
|
||||
// We hold each individual endpoint here
|
||||
char endpoint [256];
|
||||
while (*endpoints) {
|
||||
const char *delimiter = strchr (endpoints, ',');
|
||||
if (!delimiter)
|
||||
delimiter = endpoints + strlen (endpoints);
|
||||
if (delimiter - endpoints > 255)
|
||||
return false;
|
||||
memcpy (endpoint, endpoints, delimiter - endpoints);
|
||||
endpoint [delimiter - endpoints] = 0;
|
||||
|
||||
bool rc;
|
||||
if (endpoint [0] == '@') {
|
||||
rc = Bind(endpoint + 1);
|
||||
}
|
||||
else if (endpoint [0] == '>' || endpoint [0] == '-' || endpoint [0] == '+' ) {
|
||||
Connect(endpoint + 1);
|
||||
}
|
||||
else if (serverish) {
|
||||
rc = Bind(endpoint);
|
||||
}
|
||||
else {
|
||||
Connect(endpoint);
|
||||
}
|
||||
|
||||
if (!rc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (*delimiter == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
endpoints = delimiter + 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user