| 153 | }; |
| 154 | |
| 155 | void thread(void* param) |
| 156 | { |
| 157 | thread_data p = *static_cast<thread_data*>(param); |
| 158 | try |
| 159 | { |
| 160 | p.con = connect(p.host_or_ip, p.port); |
| 161 | } |
| 162 | catch (...) |
| 163 | { |
| 164 | p.error_occurred = true; |
| 165 | } |
| 166 | |
| 167 | auto_mutex M(connect_mutex); |
| 168 | // report the results back to the connect() call that spawned this |
| 169 | // thread. |
| 170 | static_cast<thread_data*>(param)->con = p.con; |
| 171 | static_cast<thread_data*>(param)->error_occurred = p.error_occurred; |
| 172 | connect_signaler.broadcast(); |
| 173 | |
| 174 | // wait for the call to connect() that spawned this thread to terminate |
| 175 | // before we delete the thread_data struct. |
| 176 | while (static_cast<thread_data*>(param)->connect_ended == false) |
| 177 | connect_signaler.wait(); |
| 178 | |
| 179 | connect_signaler.broadcast(); |
| 180 | --outstanding_connects; |
| 181 | delete static_cast<thread_data*>(param); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | connection* connect ( |