| 262 | // ---------------------------------------------------------------------------------------- |
| 263 | |
| 264 | void linker:: |
| 265 | service_connection ( |
| 266 | void* param |
| 267 | ) |
| 268 | { |
| 269 | linker& p = *static_cast<linker*>(param); |
| 270 | |
| 271 | p.cons_mutex.lock(); |
| 272 | // if the connections are gone for whatever reason then return |
| 273 | if (p.A == 0 || p.B == 0) |
| 274 | { |
| 275 | // signal that this function is ending |
| 276 | p.service_connection_running_mutex.lock(); |
| 277 | p.service_connection_running = false; |
| 278 | p.service_connection_running_signaler.broadcast(); |
| 279 | p.service_connection_running_mutex.unlock(); |
| 280 | return; |
| 281 | } |
| 282 | connection& a = *p.A; |
| 283 | connection& b = *p.B; |
| 284 | p.cons_mutex.unlock(); |
| 285 | |
| 286 | |
| 287 | |
| 288 | // forward data from b to a |
| 289 | char buf[200]; |
| 290 | long status; |
| 291 | bool error = false; |
| 292 | while (true) |
| 293 | { |
| 294 | status = b.read(buf,sizeof(buf)); |
| 295 | // if there was an error reading from the socket |
| 296 | if (status == OTHER_ERROR) |
| 297 | { |
| 298 | error = true; |
| 299 | break; |
| 300 | } |
| 301 | else if (status == SHUTDOWN) |
| 302 | { |
| 303 | a.shutdown(); |
| 304 | } |
| 305 | |
| 306 | |
| 307 | if (status <= 0) |
| 308 | { |
| 309 | // if b has closed normally |
| 310 | if (status == 0) |
| 311 | a.shutdown_outgoing(); |
| 312 | break; |
| 313 | } |
| 314 | |
| 315 | |
| 316 | status = a.write(buf,status); |
| 317 | // if there was an error writing to the socket then break |
| 318 | if (status == OTHER_ERROR) |
| 319 | { |
| 320 | error = true; |
| 321 | break; |