mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 21:23:03 +01:00
Make port wait for event thread shutdown on disconnect
This commit is contained in:
parent
1bd136a9d8
commit
4ee99ff984
@ -1482,18 +1482,15 @@ static void disconnect( rem_port* port)
|
||||
Firebird::MutexLockGuard guard(port_mutex);
|
||||
port->port_state = rem_port::DISCONNECTED;
|
||||
|
||||
if (port->port_async) {
|
||||
disconnect(port->port_async);
|
||||
port->port_async = NULL;
|
||||
}
|
||||
|
||||
rem_port* parent = port->port_parent;
|
||||
if (parent != NULL) {
|
||||
if (port->port_async) {
|
||||
disconnect(port->port_async);
|
||||
port->port_async = NULL;
|
||||
}
|
||||
|
||||
unhook_port(port, parent);
|
||||
}
|
||||
else if (port->port_async) {
|
||||
port->port_async->port_flags |= PORT_disconnect;
|
||||
}
|
||||
|
||||
inet_ports->unRegisterPort(port);
|
||||
|
||||
|
@ -3065,6 +3065,18 @@ ISC_STATUS GDS_PUT_SLICE(ISC_STATUS* user_status,
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
void portEventsShutdown(rem_port* port)
|
||||
{
|
||||
if (port->port_events_thread)
|
||||
{
|
||||
THD_wait_for_completion(port->port_events_thread);
|
||||
port->port_events_thread = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ISC_STATUS GDS_QUE_EVENTS(ISC_STATUS* user_status,
|
||||
Rdb** handle,
|
||||
SLONG* id,
|
||||
@ -3115,7 +3127,9 @@ ISC_STATUS GDS_QUE_EVENTS(ISC_STATUS* user_status,
|
||||
return user_status[1];
|
||||
}
|
||||
|
||||
gds__thread_start(event_thread, port->port_async, THREAD_high, 0, 0);
|
||||
gds__thread_start(event_thread, port->port_async, THREAD_high, 0,
|
||||
&port->port_async->port_events_thread);
|
||||
port->port_async->port_events_shutdown = portEventsShutdown;
|
||||
|
||||
port->port_async->port_context = rdb;
|
||||
}
|
||||
@ -5321,7 +5335,7 @@ static THREAD_ENTRY_DECLARE event_thread(THREAD_ENTRY_PARAM arg)
|
||||
*
|
||||
**************************************/
|
||||
rem_port* port = (rem_port*)arg;
|
||||
Reference portRef(*port);
|
||||
// Reference portRef(*port);
|
||||
PACKET packet;
|
||||
|
||||
for (;;)
|
||||
@ -6863,8 +6877,6 @@ static void server_death(rem_port* port)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
port->disconnect();
|
||||
}
|
||||
|
||||
|
||||
|
@ -792,28 +792,19 @@ static void disconnect(rem_port* port)
|
||||
*
|
||||
**************************************/
|
||||
|
||||
if (port->port_async)
|
||||
{
|
||||
disconnect(port->port_async);
|
||||
port->port_async = NULL;
|
||||
}
|
||||
|
||||
// If this is a sub-port, unlink it from it's parent
|
||||
|
||||
rem_port* const parent = port->port_parent;
|
||||
if (parent)
|
||||
{
|
||||
if (port->port_async)
|
||||
{
|
||||
disconnect(port->port_async);
|
||||
port->port_async = NULL;
|
||||
}
|
||||
|
||||
port->unlinkParent();
|
||||
}
|
||||
else if (port->port_async)
|
||||
{
|
||||
#ifdef SUPERSERVER
|
||||
disconnect(port->port_async);
|
||||
port->port_async = NULL;
|
||||
#else
|
||||
port->port_async->port_flags |= PORT_disconnect;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (port->port_server_flags & SRVR_server)
|
||||
{
|
||||
|
@ -825,3 +825,30 @@ void PortsCleanup::closePorts()
|
||||
m_ports = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
rem_port::~rem_port()
|
||||
{
|
||||
if (port_events_shutdown)
|
||||
{
|
||||
port_events_shutdown(this);
|
||||
}
|
||||
|
||||
delete port_version;
|
||||
delete port_connection;
|
||||
delete port_user_name;
|
||||
delete port_host;
|
||||
delete port_protocol_str;
|
||||
delete port_address_str;
|
||||
|
||||
#ifdef DEBUG_XDR_MEMORY
|
||||
delete port_packet_vector;
|
||||
#endif
|
||||
|
||||
#ifdef TRUSTED_AUTH
|
||||
delete port_trusted_auth;
|
||||
#endif
|
||||
|
||||
#ifdef DEV_BUILD
|
||||
--portCounter;
|
||||
#endif
|
||||
}
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "gen/iberror.h"
|
||||
#include "../remote/remote_def.h"
|
||||
#include "../jrd/ThreadData.h"
|
||||
#include "../jrd/ThreadStart.h"
|
||||
#include "../common/thd.h"
|
||||
#include "../common/classes/objects_array.h"
|
||||
#include "../auth/trusted/AuthSspi.h"
|
||||
@ -620,6 +621,8 @@ struct rem_port : public Firebird::GlobalStorage, public Firebird::RefCounted
|
||||
int port_channel; /* handle for connection (from by OS) */
|
||||
struct linger port_linger; /* linger value as defined by SO_LINGER */
|
||||
Rdb* port_context;
|
||||
ThreadHandle port_events_thread; // handle of thread, handling incoming events
|
||||
void (*port_events_shutdown)(rem_port*); // hack - avoid changing API at beta stage
|
||||
#ifdef WIN_NT
|
||||
HANDLE port_event; // event associated with port, Windows only
|
||||
#endif
|
||||
@ -666,7 +669,7 @@ public:
|
||||
port_server(0), port_server_flags(0), port_protocol(0), port_buff_size(0),
|
||||
port_flags(0), port_connect_timeout(0), port_dummy_packet_interval(0),
|
||||
port_dummy_timeout(0), port_status_vector(0), port_handle(0), port_channel(0),
|
||||
port_context(0),
|
||||
port_context(0), port_events_thread(0), port_events_shutdown(0),
|
||||
#ifdef WIN_NT
|
||||
port_event(INVALID_HANDLE_VALUE),
|
||||
#endif
|
||||
@ -694,27 +697,7 @@ public:
|
||||
}
|
||||
|
||||
private: // this is refCounted object
|
||||
~rem_port()
|
||||
{
|
||||
delete port_version;
|
||||
delete port_connection;
|
||||
delete port_user_name;
|
||||
delete port_host;
|
||||
delete port_protocol_str;
|
||||
delete port_address_str;
|
||||
|
||||
#ifdef DEBUG_XDR_MEMORY
|
||||
delete port_packet_vector;
|
||||
#endif
|
||||
|
||||
#ifdef TRUSTED_AUTH
|
||||
delete port_trusted_auth;
|
||||
#endif
|
||||
|
||||
#ifdef DEV_BUILD
|
||||
--portCounter;
|
||||
#endif
|
||||
}
|
||||
~rem_port();
|
||||
|
||||
public:
|
||||
void linkParent(rem_port* parent);
|
||||
|
@ -1471,23 +1471,14 @@ static void disconnect(rem_port* port)
|
||||
|
||||
// If this is a sub-port, unlink it from it's parent
|
||||
|
||||
rem_port* const parent = port->port_parent;
|
||||
if (parent != NULL) {
|
||||
|
||||
if (port->port_async) {
|
||||
disconnect(port->port_async);
|
||||
port->port_async = NULL;
|
||||
}
|
||||
|
||||
port->unlinkParent();
|
||||
}
|
||||
else if (port->port_async) {
|
||||
#ifdef SUPERSERVER
|
||||
if (port->port_async) {
|
||||
disconnect(port->port_async);
|
||||
port->port_async = NULL;
|
||||
#else
|
||||
port->port_async->port_flags |= PORT_disconnect;
|
||||
#endif
|
||||
}
|
||||
|
||||
rem_port* const parent = port->port_parent;
|
||||
if (parent != NULL) {
|
||||
port->unlinkParent();
|
||||
}
|
||||
|
||||
if (port->port_flags & PORT_server)
|
||||
|
Loading…
Reference in New Issue
Block a user