Skip to content

Instantly share code, notes, and snippets.

@skayred
Created December 1, 2011 14:23
Show Gist options
  • Select an option

  • Save skayred/1417086 to your computer and use it in GitHub Desktop.

Select an option

Save skayred/1417086 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <sstream>
#include <cstdlib>
#include "zhelpers.hpp"
int main ()
{
srandom ((unsigned) time (NULL));
zmq::context_t context(1);
zmq::socket_t server(context, ZMQ_REP);
server.bind("tcp://*:5555");
int cycles = 0;
while (1) {
std::string request = s_recv (server);
cycles++;
// Simulate various problems, after a few cycles
if (cycles > 3 && within (3) == 0) {
std::cout << "I: simulating a crash" << std::endl;
break;
}
else
if (cycles > 3 && within (3) == 0) {
std::cout << "I: simulating CPU overload" << std::endl;
sleep (2);
}
std::cout << "I: normal request (" << request << ")" << std::endl;
sleep (1); // Do some heavy work
s_send (server, request);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment