| 92 | // ---------------------------------------------------------------------------------------- |
| 93 | |
| 94 | void server:: |
| 95 | clear ( |
| 96 | ) |
| 97 | { |
| 98 | // signal that we are shutting down |
| 99 | shutting_down_mutex.lock(); |
| 100 | shutting_down = true; |
| 101 | shutting_down_mutex.unlock(); |
| 102 | |
| 103 | |
| 104 | |
| 105 | max_connections_mutex.lock(); |
| 106 | listening_port_mutex.lock(); |
| 107 | listening_ip_mutex.lock(); |
| 108 | listening_ip = ""; |
| 109 | listening_port = 0; |
| 110 | max_connections = 1000; |
| 111 | graceful_close_timeout = 500; |
| 112 | listening_port_mutex.unlock(); |
| 113 | listening_ip_mutex.unlock(); |
| 114 | max_connections_mutex.unlock(); |
| 115 | |
| 116 | |
| 117 | // tell all the connections to shut down |
| 118 | cons_mutex.lock(); |
| 119 | connection* temp; |
| 120 | while (cons.size() > 0) |
| 121 | { |
| 122 | cons.remove_any(temp); |
| 123 | temp->shutdown(); |
| 124 | } |
| 125 | cons_mutex.unlock(); |
| 126 | |
| 127 | |
| 128 | // wait for all the connections to shut down |
| 129 | thread_count_mutex.lock(); |
| 130 | while (thread_count > 0) |
| 131 | { |
| 132 | thread_count_zero.wait(); |
| 133 | } |
| 134 | thread_count_mutex.unlock(); |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | // wait for the listener to close |
| 140 | running_mutex.lock(); |
| 141 | while (running == true) |
| 142 | { |
| 143 | running_signaler.wait(); |
| 144 | } |
| 145 | running_mutex.unlock(); |
| 146 | |
| 147 | |
| 148 | |
| 149 | // signal that the shutdown is complete |
| 150 | shutting_down_mutex.lock(); |
| 151 | shutting_down = false; |