| 1 |
|
|---|
| 2 | /** Test out callstack functionality
|
|---|
| 3 | *
|
|---|
| 4 | * Currently broken on windows when running from dll
|
|---|
| 5 | *
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include <boost/asio.hpp>
|
|---|
| 9 | #include <boost/bind.hpp>
|
|---|
| 10 | #include <boost/ref.hpp>
|
|---|
| 11 |
|
|---|
| 12 | #include <iostream>
|
|---|
| 13 |
|
|---|
| 14 | bool strand_dispatched = false;
|
|---|
| 15 | bool io_service_dispatched = false;
|
|---|
| 16 |
|
|---|
| 17 | void strand_handler2()
|
|---|
| 18 | {
|
|---|
| 19 | strand_dispatched = true;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | void strand_handler(boost::asio::strand &strand)
|
|---|
| 23 | {
|
|---|
| 24 | if(strand.running_in_this_thread())
|
|---|
| 25 | {
|
|---|
| 26 | std::cout << "running_in_this_thread: PASS\n";
|
|---|
| 27 | }
|
|---|
| 28 | else
|
|---|
| 29 | {
|
|---|
| 30 | std::cout << "running_in_this_thread: FAIL\n";
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | strand.dispatch(&strand_handler2);
|
|---|
| 34 |
|
|---|
| 35 | if(strand_dispatched)
|
|---|
| 36 | {
|
|---|
| 37 | std::cout << "strand dispatch: PASS\n";
|
|---|
| 38 | }
|
|---|
| 39 | else
|
|---|
| 40 | {
|
|---|
| 41 | std::cout << "strand dispatch: FAIL\n";
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | void io_service_handler2()
|
|---|
| 46 | {
|
|---|
| 47 | io_service_dispatched = true;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | void service_handler(boost::asio::io_service &io_service)
|
|---|
| 51 | {
|
|---|
| 52 | io_service.dispatch(&io_service_handler2);
|
|---|
| 53 |
|
|---|
| 54 | if(io_service_dispatched)
|
|---|
| 55 | {
|
|---|
| 56 | std::cout << "io_service dispatch: PASS\n";
|
|---|
| 57 | }
|
|---|
| 58 | else
|
|---|
| 59 | {
|
|---|
| 60 | std::cout << "io_service dispatch: FAIL\n";
|
|---|
| 61 | }
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | void wait_for_debugger()
|
|---|
| 65 | {
|
|---|
| 66 | std::string input;
|
|---|
| 67 | std::cout << "Attach debugger, and press CTRL-d <ENTER>\n";
|
|---|
| 68 | std::cin >> input;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | int main(int /*argc*/, char ** /*argv*/)
|
|---|
| 72 | {
|
|---|
| 73 | //wait_for_debugger();
|
|---|
| 74 |
|
|---|
| 75 | boost::asio::io_service io_service;
|
|---|
| 76 | boost::asio::strand strand(io_service);
|
|---|
| 77 |
|
|---|
| 78 | strand.post(boost::bind(&strand_handler, boost::ref(strand)));
|
|---|
| 79 |
|
|---|
| 80 | io_service.post(boost::bind(&service_handler, boost::ref(io_service)));
|
|---|
| 81 |
|
|---|
| 82 | io_service.run();
|
|---|
| 83 |
|
|---|
| 84 | return 0;
|
|---|
| 85 | }
|
|---|