Refactored poll support. Add Chapter 2 examples from the official ZMQ guide.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| RRBroker.mq4 |
|
||||
//| Copyright 2017, Li Ding |
|
||||
//| dingmaotu@126.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2017, Li Ding"
|
||||
#property link "dingmaotu@126.com"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
#include <Zmq/Zmq.mqh>
|
||||
//+------------------------------------------------------------------+
|
||||
//| Simple request-reply broker in MQL (adapted from C++ version) |
|
||||
//| |
|
||||
//| Olivier Chamoux <olivier.chamoux@fr.thalesgroup.com> |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnStart()
|
||||
{
|
||||
// Prepare our context and sockets
|
||||
Context context;
|
||||
Socket frontend(context,ZMQ_ROUTER);
|
||||
Socket backend(context,ZMQ_DEALER);
|
||||
|
||||
frontend.bind("tcp://*:5559");
|
||||
backend.bind("tcp://*:5560");
|
||||
|
||||
// Initialize poll set
|
||||
PollItem items[2];
|
||||
frontend.fillPollItem(items[0],ZMQ_POLLIN);
|
||||
backend.fillPollItem(items[1],ZMQ_POLLIN);
|
||||
|
||||
// Switch messages between sockets
|
||||
while(!IsStopped())
|
||||
{
|
||||
ZmqMsg message;
|
||||
bool more=false; // Multipart detection
|
||||
|
||||
Socket::poll(items,500);
|
||||
|
||||
if(items[0].hasInput())
|
||||
{
|
||||
// Process all parts of the message
|
||||
do
|
||||
{
|
||||
frontend.recv(message);
|
||||
more=message.more();
|
||||
backend.send(message,false,more);
|
||||
}
|
||||
while(more);
|
||||
}
|
||||
if(items[1].hasInput())
|
||||
{
|
||||
// Process all parts of the message
|
||||
do
|
||||
{
|
||||
backend.recv(message);
|
||||
more=message.more();
|
||||
frontend.send(message,false,more);
|
||||
}
|
||||
while(more);
|
||||
}
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Reference in New Issue
Block a user