mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
use clang-format for FairMQ
This commit is contained in:
@@ -39,131 +39,156 @@ FairMQSocketZMQ::FairMQSocketZMQ(const string& type, int num, int numIoThreads)
|
||||
if (rc != 0) {
|
||||
LOG(ERROR) << "failed setting socket option, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
}
|
||||
|
||||
LOG(INFO) << "created socket #" << fId;
|
||||
if (type == "sub")
|
||||
{
|
||||
rc = zmq_setsockopt(fSocket, ZMQ_SUBSCRIBE, NULL, 0);
|
||||
if (rc != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed setting socket option, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
}
|
||||
|
||||
LOG(INFO) << "created socket #" << fId;
|
||||
}
|
||||
|
||||
string FairMQSocketZMQ::GetId()
|
||||
{
|
||||
return fId;
|
||||
return fId;
|
||||
}
|
||||
|
||||
void FairMQSocketZMQ::Bind(const string& address)
|
||||
{
|
||||
LOG(INFO) << "bind socket #" << fId << " on " << address;
|
||||
LOG(INFO) << "bind socket #" << fId << " on " << address;
|
||||
|
||||
int rc = zmq_bind (fSocket, address.c_str());
|
||||
if (rc != 0) {
|
||||
LOG(ERROR) << "failed binding socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
}
|
||||
int rc = zmq_bind(fSocket, address.c_str());
|
||||
if (rc != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed binding socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQSocketZMQ::Connect(const string& address)
|
||||
{
|
||||
LOG(INFO) << "connect socket #" << fId << " on " << address;
|
||||
LOG(INFO) << "connect socket #" << fId << " on " << address;
|
||||
|
||||
int rc = zmq_connect (fSocket, address.c_str());
|
||||
if (rc != 0) {
|
||||
LOG(ERROR) << "failed connecting socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
}
|
||||
int rc = zmq_connect(fSocket, address.c_str());
|
||||
if (rc != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed connecting socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
}
|
||||
}
|
||||
|
||||
size_t FairMQSocketZMQ::Send(FairMQMessage* msg)
|
||||
{
|
||||
int nbytes = zmq_msg_send (static_cast<zmq_msg_t*>(msg->GetMessage()), fSocket, 0);
|
||||
if (nbytes >= 0){
|
||||
fBytesTx += nbytes;
|
||||
++fMessagesTx;
|
||||
int nbytes = zmq_msg_send(static_cast<zmq_msg_t*>(msg->GetMessage()), fSocket, 0);
|
||||
if (nbytes >= 0)
|
||||
{
|
||||
fBytesTx += nbytes;
|
||||
++fMessagesTx;
|
||||
return nbytes;
|
||||
}
|
||||
if (zmq_errno() == EAGAIN)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
LOG(ERROR) << "failed sending on socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
return nbytes;
|
||||
}
|
||||
if (zmq_errno() == EAGAIN){
|
||||
return false;
|
||||
}
|
||||
LOG(ERROR) << "failed sending on socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
size_t FairMQSocketZMQ::Receive(FairMQMessage* msg)
|
||||
{
|
||||
int nbytes = zmq_msg_recv (static_cast<zmq_msg_t*>(msg->GetMessage()), fSocket, 0);
|
||||
if (nbytes >= 0){
|
||||
fBytesRx += nbytes;
|
||||
++fMessagesRx;
|
||||
int nbytes = zmq_msg_recv(static_cast<zmq_msg_t*>(msg->GetMessage()), fSocket, 0);
|
||||
if (nbytes >= 0)
|
||||
{
|
||||
fBytesRx += nbytes;
|
||||
++fMessagesRx;
|
||||
return nbytes;
|
||||
}
|
||||
if (zmq_errno() == EAGAIN)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
LOG(ERROR) << "failed receiving on socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
return nbytes;
|
||||
}
|
||||
if (zmq_errno() == EAGAIN){
|
||||
return false;
|
||||
}
|
||||
LOG(ERROR) << "failed receiving on socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
void FairMQSocketZMQ::Close()
|
||||
{
|
||||
if (fSocket == NULL){
|
||||
return;
|
||||
}
|
||||
if (fSocket == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int rc = zmq_close (fSocket);
|
||||
if (rc != 0) {
|
||||
LOG(ERROR) << "failed closing socket, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
int rc = zmq_close(fSocket);
|
||||
if (rc != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed closing socket, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
||||
fSocket = NULL;
|
||||
fSocket = NULL;
|
||||
}
|
||||
|
||||
void* FairMQSocketZMQ::GetSocket()
|
||||
{
|
||||
return fSocket;
|
||||
return fSocket;
|
||||
}
|
||||
|
||||
int FairMQSocketZMQ::GetSocket(int nothing)
|
||||
{
|
||||
// dummy method to comply with the interface. functionality not possible in zeromq.
|
||||
return -1;
|
||||
// dummy method to comply with the interface. functionality not possible in zeromq.
|
||||
return -1;
|
||||
}
|
||||
|
||||
void FairMQSocketZMQ::SetOption(const string& option, const void* value, size_t valueSize)
|
||||
{
|
||||
int rc = zmq_setsockopt(fSocket, GetConstant(option), value, valueSize);
|
||||
if (rc < 0) {
|
||||
LOG(ERROR) << "failed setting socket option, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
int rc = zmq_setsockopt(fSocket, GetConstant(option), value, valueSize);
|
||||
if (rc < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed setting socket option, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long FairMQSocketZMQ::GetBytesTx()
|
||||
{
|
||||
return fBytesTx;
|
||||
return fBytesTx;
|
||||
}
|
||||
|
||||
unsigned long FairMQSocketZMQ::GetBytesRx()
|
||||
{
|
||||
return fBytesRx;
|
||||
return fBytesRx;
|
||||
}
|
||||
|
||||
unsigned long FairMQSocketZMQ::GetMessagesTx()
|
||||
{
|
||||
return fMessagesTx;
|
||||
return fMessagesTx;
|
||||
}
|
||||
|
||||
unsigned long FairMQSocketZMQ::GetMessagesRx()
|
||||
{
|
||||
return fMessagesRx;
|
||||
return fMessagesRx;
|
||||
}
|
||||
|
||||
int FairMQSocketZMQ::GetConstant(const string& constant)
|
||||
{
|
||||
if (constant == "sub") return ZMQ_SUB;
|
||||
if (constant == "pub") return ZMQ_PUB;
|
||||
if (constant == "xsub") return ZMQ_XSUB;
|
||||
if (constant == "xpub") return ZMQ_XPUB;
|
||||
if (constant == "push") return ZMQ_PUSH;
|
||||
if (constant == "pull") return ZMQ_PULL;
|
||||
if (constant == "snd-hwm") return ZMQ_SNDHWM;
|
||||
if (constant == "rcv-hwm") return ZMQ_RCVHWM;
|
||||
if (constant == "sub")
|
||||
return ZMQ_SUB;
|
||||
if (constant == "pub")
|
||||
return ZMQ_PUB;
|
||||
if (constant == "xsub")
|
||||
return ZMQ_XSUB;
|
||||
if (constant == "xpub")
|
||||
return ZMQ_XPUB;
|
||||
if (constant == "push")
|
||||
return ZMQ_PUSH;
|
||||
if (constant == "pull")
|
||||
return ZMQ_PULL;
|
||||
if (constant == "snd-hwm")
|
||||
return ZMQ_SNDHWM;
|
||||
if (constant == "rcv-hwm")
|
||||
return ZMQ_RCVHWM;
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
FairMQSocketZMQ::~FairMQSocketZMQ()
|
||||
|
Reference in New Issue
Block a user