git-svn-id: svn://elaine/murooma/trunk@128 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-08-01 17:05:27 +00:00
parent d94f6c99da
commit 4f5cbb5e25
2 changed files with 17 additions and 7 deletions

View file

@ -22,8 +22,16 @@ using namespace std;
void alive(zmq::socket_t* worker) void alive(zmq::socket_t* worker)
{ {
// Tell the router we're ready for work // Tell the router we're ready for work
zmq::message_t message;
while (1) { while (1) {
s_send (*worker, "ping"); s_send (*worker, "ping");
int res = worker->recv(&message);
if (res == 0)
{
std::string recvMsg = std::string(static_cast<char*>(message.data()), message.size());
}
else
cout << "Error: " << res << "\n";
sleep(1); sleep(1);
} }
} }
@ -32,7 +40,7 @@ void alive(zmq::socket_t* worker)
void control(zmq::socket_t* worker) void control(zmq::socket_t* worker)
{ {
// Tell the router we're ready for work // Tell the router we're ready for work
// s_send (*worker, "ready"); s_send (*worker, "ready");
while (1) { while (1) {
std::string cmd = s_recv (*worker); std::string cmd = s_recv (*worker);
vector<std::string> splitCmd = split(cmd); vector<std::string> splitCmd = split(cmd);
@ -46,14 +54,16 @@ void control(zmq::socket_t* worker)
int main () { int main () {
cout << getMacAddress() << "\n"; cout << getMacAddress() << "\n";
zmq::context_t context(1); zmq::context_t context(1);
zmq::socket_t worker (context, ZMQ_DEALER); zmq::socket_t worker (context, ZMQ_REQ);
srand (time(NULL)); srand (time(NULL));
// We use a string identity for ease here // We use a string identity for ease here
string macAddress = getMacAddress(); string macAddress = getMacAddress();
worker.setsockopt(ZMQ_IDENTITY, macAddress.c_str(), macAddress.length()); worker.setsockopt(ZMQ_IDENTITY, macAddress.c_str(), macAddress.length());
// int timeout = 1000;
// worker.setsockopt(ZMQ_RCVTIMEO, &timeout, sizeof(timeout));
worker.connect("tcp://127.0.0.1:123459"); worker.connect("tcp://127.0.0.1:123459");
std::thread controlThread(control, &worker); // std::thread controlThread(control, &worker);
std::thread aliveThread(alive, &worker); std::thread aliveThread(alive, &worker);
controlThread.join(); controlThread.join();
return 0; return 0;

View file

@ -77,7 +77,7 @@ timeval Stream::getNextPlayerChunk(short* outputBuffer, int correction)
} }
else else
{ {
int idx(chunk->idx); /* int idx(chunk->idx);
for (size_t n=0; n<PLAYER_CHUNK_SIZE; n+=2) for (size_t n=0; n<PLAYER_CHUNK_SIZE; n+=2)
{ {
*(outputBuffer + n) = chunk->payload[idx]; *(outputBuffer + n) = chunk->payload[idx];
@ -97,8 +97,8 @@ timeval Stream::getNextPlayerChunk(short* outputBuffer, int correction)
} }
} }
chunk->idx = idx; chunk->idx = idx;
*/
/* size_t missing = PLAYER_CHUNK_SIZE;// + correction*PLAYER_CHUNK_MS_SIZE; size_t missing = PLAYER_CHUNK_SIZE;// + correction*PLAYER_CHUNK_MS_SIZE;
if (chunk->idx + PLAYER_CHUNK_SIZE > WIRE_CHUNK_SIZE) if (chunk->idx + PLAYER_CHUNK_SIZE > WIRE_CHUNK_SIZE)
{ {
if (outputBuffer != NULL) if (outputBuffer != NULL)
@ -118,7 +118,7 @@ timeval Stream::getNextPlayerChunk(short* outputBuffer, int correction)
chunks.pop_front(); chunks.pop_front();
delete chunk; delete chunk;
} }
*/
} }
return tv; return tv;