| 60 | thread::id g_root_thread = std::this_thread::get_id(); |
| 61 | |
| 62 | static void OnINT_SetInterrupted(int) |
| 63 | { |
| 64 | Verb() << VerbLock << "SIGINT: Setting interrupt state."; |
| 65 | ::transmit_int_state = true; |
| 66 | |
| 67 | // Just for a case, forcefully close all active SRT sockets. |
| 68 | SrtModel* pm = ::g_pending_model; |
| 69 | if (pm) |
| 70 | { |
| 71 | // The program is hanged on accepting a new SRT connection. |
| 72 | // We need to check which thread we've fallen into. |
| 73 | if (this_thread::get_id() == g_root_thread) |
| 74 | { |
| 75 | // Throw an exception, it will be caught in a predicted place. |
| 76 | throw std::runtime_error("Interrupted on request"); |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | // This is some other thread, so close the listener socket. |
| 81 | // This will cause the accept block to be interrupted. |
| 82 | for (SRTSOCKET i: { pm->Socket(), pm->Listener() }) |
| 83 | if (i != SRT_INVALID_SOCK) |
| 84 | srt_close(i); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | } |
| 89 | |
| 90 | using namespace std; |
| 91 | |