Created
December 1, 2011 14:23
-
-
Save skayred/1417086 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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