git-svn-id: svn://elaine/murooma/trunk@122 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-07-30 19:41:56 +00:00
parent b0fe090d21
commit ce1c5fb3ac
5 changed files with 73 additions and 40 deletions

View file

@ -13,20 +13,11 @@
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include "utils.h"
using namespace std;
std::string getMacAddress()
{
std::ifstream t("/sys/class/net/eth0/address");
std::string str((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
str.erase(std::find_if(str.rbegin(), str.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), str.end());
return str;
}
void control()
{
@ -36,15 +27,13 @@ void control()
// We use a string identity for ease here
string macAddress = getMacAddress();
worker.setsockopt(ZMQ_IDENTITY, macAddress.c_str(), macAddress.length());
worker.connect("tcp://127.0.0.1:10000");
worker.connect("tcp://127.0.0.1:123459");
// Tell the router we're ready for work
s_send (worker, "ready");
while (1) {
std::string cmd = s_recv (worker);
istringstream iss(cmd);
vector<std::string> splitCmd;
copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(splitCmd));
vector<std::string> splitCmd = split(cmd);
for (size_t n=0; n<splitCmd.size(); ++n)
std::cout << "cmd: " << splitCmd[n] << "\n";
s_send(worker, "ACK " + cmd);