| 8455 | |
| 8456 | |
| 8457 | static void finalize(rem_port* port) |
| 8458 | { |
| 8459 | /************************************** |
| 8460 | * |
| 8461 | * f i n a l i z e |
| 8462 | * |
| 8463 | ************************************** |
| 8464 | * |
| 8465 | * Functional description |
| 8466 | * Disconnect remote port. |
| 8467 | * |
| 8468 | **************************************/ |
| 8469 | |
| 8470 | // no need to do something if port already detached |
| 8471 | if (port->port_flags & PORT_detached) |
| 8472 | return; |
| 8473 | |
| 8474 | // Avoid async send during finalize |
| 8475 | RefMutexGuard guard(*port->port_write_sync, FB_FUNCTION); |
| 8476 | |
| 8477 | // recheck with mutex taken |
| 8478 | if (port->port_flags & PORT_detached) |
| 8479 | return; |
| 8480 | |
| 8481 | // Send a disconnect to the server so that it |
| 8482 | // gracefully terminates. |
| 8483 | |
| 8484 | Rdb* rdb = port->port_context; |
| 8485 | if (rdb) |
| 8486 | { |
| 8487 | PACKET* packet = &rdb->rdb_packet; |
| 8488 | |
| 8489 | // Deliver the pending deferred packets |
| 8490 | if (port->port_deferred_packets) |
| 8491 | { |
| 8492 | for (rem_que_packet* p = port->port_deferred_packets->begin(); |
| 8493 | p < port->port_deferred_packets->end(); |
| 8494 | p++) |
| 8495 | { |
| 8496 | if (!p->sent) |
| 8497 | port->send(&p->packet); |
| 8498 | } |
| 8499 | } |
| 8500 | |
| 8501 | packet->p_operation = op_disconnect; |
| 8502 | port->send(packet); |
| 8503 | |
| 8504 | REMOTE_free_packet(port, packet); |
| 8505 | } |
| 8506 | |
| 8507 | // Cleanup the queue |
| 8508 | |
| 8509 | delete port->port_deferred_packets; |
| 8510 | port->port_deferred_packets = nullptr; |
| 8511 | port->port_flags &= ~PORT_lazy; |
| 8512 | |
| 8513 | port->port_flags |= PORT_detached; |
| 8514 | } |
no test coverage detected