giopstrand.cc
来自「编译工具」· CC 代码 · 共 1,069 行 · 第 1/3 页
CC
1,069 行
// -*- Mode: C++; -*-// Package : omniORB// giopStrand.cc Created on: 16/01/2001// Author : Sai Lai Lo (sll)//// Copyright (C) 2001 AT&T Laboratories Cambridge//// This file is part of the omniORB library//// The omniORB library is free software; you can redistribute it and/or// modify it under the terms of the GNU Library General Public// License as published by the Free Software Foundation; either// version 2 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Library General Public License for more details.//// You should have received a copy of the GNU Library General Public// License along with this library; if not, write to the Free// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA// 02111-1307, USA////// Description:///* $Log: giopStrand.cc,v $ Revision 1.1.4.25 2005/11/14 10:58:23 dgrisby Better connection / thread shutdown behaviour. Revision 1.1.4.24 2005/10/13 11:38:16 dgrisby Dump CloseConnection messages. Revision 1.1.4.23 2005/04/10 22:17:18 dgrisby Fixes to connection management. Thanks Jon Biggar. Revision 1.1.4.22 2005/03/16 09:16:59 dgrisby Previous change to CancelRequest handling accidentally broke server-side connection shutdown. Revision 1.1.4.21 2004/10/17 21:48:40 dgrisby Support CancelRequest better. Revision 1.1.4.20 2004/03/30 14:26:36 dgrisby Better fix for scavenger thread restarting after shutdown. Revision 1.1.4.19 2004/03/30 13:14:47 dgrisby Allow scavenger thread to restart. Revision 1.1.4.18 2002/09/04 23:29:30 dgrisby Avoid memory corruption with multiple list removals. Revision 1.1.4.17 2002/08/21 06:23:15 dgrisby Properly clean up bidir connections and ropes. Other small tweaks. Revision 1.1.4.16 2002/03/18 15:13:08 dpg1 Fix bug with old-style ORBInitRef in config file; look for -ORBtraceLevel arg before anything else; update Windows registry key. Correct error message. Revision 1.1.4.15 2002/03/14 14:40:46 dpg1 Scavenger locking bug. Revision 1.1.4.14 2002/03/14 12:21:49 dpg1 Undo accidental scavenger period change, remove invalid assertion. Revision 1.1.4.13 2002/03/13 16:05:39 dpg1 Transport shutdown fixes. Reference count SocketCollections to avoid connections using them after they are deleted. Properly close connections when in thread pool mode. Revision 1.1.4.12 2001/09/19 17:26:49 dpg1 Full clean-up after orb->destroy(). Revision 1.1.4.11 2001/09/10 17:51:46 sll Scavenger now manages passive connections as well. Send CloseConnection message when a scavenger close a connection. Revision 1.1.4.10 2001/09/03 16:56:09 sll Make sure that the deadline is set to 0. Revision 1.1.4.9 2001/08/29 17:52:34 sll Make sure that the invariant of the dtor is satisfied in safeDelete. Revision 1.1.4.8 2001/08/24 15:21:13 sll Corrected a bug in the conversion from {in,out}ConScanPeriod to idleclicks. Revision 1.1.4.7 2001/08/21 11:02:15 sll orbOptions handlers are now told where an option comes from. This is necessary to process DefaultInitRef and InitRef correctly. Revision 1.1.4.6 2001/08/17 17:12:38 sll Modularise ORB configuration parameters. Revision 1.1.4.5 2001/07/31 16:27:59 sll Added GIOP BiDir support. Revision 1.1.4.4 2001/07/13 15:28:17 sll Use safeDelete to manage the lifecycle of a strand. Revision 1.1.4.3 2001/06/13 20:13:15 sll Minor updates to make the ORB compiles with MSVC++. Revision 1.1.4.2 2001/05/09 19:36:54 sll Client side idle connection cleanup now works Revision 1.1.4.1 2001/04/18 18:10:49 sll Big checkin with the brand new internal APIs. */#include <omniORB4/CORBA.h>#include <giopStream.h>#include <giopStreamImpl.h>#include <giopRope.h>#include <giopStrand.h>#include <GIOP_S.h>#include <GIOP_C.h>#include <initialiser.h>#include <invoker.h>#include <orbOptions.h>#include <orbParameters.h>OMNI_NAMESPACE_BEGIN(omni)////////////////////////////////////////////////////////////////////////////// Configuration options //////////////////////////////////////////////////////////////////////////////CORBA::ULong orbParameters::scanGranularity = 5;// The granularity at which the ORB scan for idle connections.// This value determines the minimum value that inConScanPeriod or// outConScanPeriod can be implemented.//// Valid values = (n >= 0 in seconds) // 0 --> do not scan for idle connections.CORBA::ULong orbParameters::outConScanPeriod = 120;// Idle connections shutdown. The ORB periodically scans all the// outgoing connections to detect if they are idle.// If no operation has passed through a connection for a scan period,// the ORB would treat this connection idle and shut it down.//// Valid values = (n >= 0 in seconds) // 0 --> do not close idle connections.CORBA::ULong orbParameters::inConScanPeriod = 180;// Idle connections shutdown. The ORB periodically scans all the// incoming connections to detect if they are idle.// If no operation has passed through a connection for a scan period,// the ORB would treat this connection idle and shut it down.//// Valid values = (n >= 0 in seconds) // 0 --> do not close idle connections.////////////////////////////////////////////////////////////////////////class Scavenger : public omniTask {public: Scavenger() : omniTask(omniTask::AnyTime) {} ~Scavenger() {} void execute(); static void notify(); static void terminate(); static void initialise();private: static CORBA::Boolean shutdown; static omni_tracedmutex* mutex; static omni_tracedcondition* cond; static Scavenger* theTask; void removeIdle(StrandList& src,StrandList& dest, CORBA::Boolean skip_bidir);};////////////////////////////////////////////////////////////////////////static inline voidsendCloseConnection(giopStrand* s){ // Send close connection message. char hdr[12]; hdr[0] = 'G'; hdr[1] = 'I'; hdr[2] = 'O'; hdr[3] = 'P'; hdr[4] = s->version.major; hdr[5] = s->version.minor; hdr[6] = _OMNIORB_HOST_BYTE_ORDER_; hdr[7] = (char)GIOP::CloseConnection; hdr[8] = hdr[9] = hdr[10] = hdr[11] = 0; if (omniORB::trace(25)) { omniORB::logger log; log << "sendCloseConnection: to " << s->connection->peeraddress() << " 12 bytes\n"; } if (omniORB::trace(30)) giopStream::dumpbuf((unsigned char*)hdr, 12); s->connection->Send(hdr,12);}////////////////////////////////////////////////////////////////////////giopStrand::giopStrand(const giopAddress* addr) : pd_safelyDeleted(0), idlebeats(-1), biDir(0), address(addr), connection(0), server(0), gatekeeper_checked(0),first_use(1),orderly_closed(0), biDir_initiated(0), biDir_has_callbacks(0), tcs_selected(0), tcs_c(0), tcs_w(0), giopImpl(0), rdcond(omniTransportLock), rd_nwaiting(0), rd_n_justwaiting(0), wrcond(omniTransportLock), wr_nwaiting(0), seqNumber(0), head(0), spare(0), pd_state(ACTIVE){ version.major = version.minor = 0; Scavenger::notify(); // Call scavenger::notify() to cause the scavenger thread to be // created if it hasn't been created already.}////////////////////////////////////////////////////////////////////////giopStrand::giopStrand(giopConnection* conn, giopServer* serv) : pd_safelyDeleted(0), idlebeats(-1), biDir(0), address(0), connection(conn), server(serv), gatekeeper_checked(0),first_use(0),orderly_closed(0), biDir_initiated(0), biDir_has_callbacks(0), tcs_selected(0), tcs_c(0), tcs_w(0), giopImpl(0), rdcond(omniTransportLock), rd_nwaiting(0), rd_n_justwaiting(0), wrcond(omniTransportLock), wr_nwaiting(0), seqNumber(1), head(0), spare(0), pd_state(ACTIVE){ version.major = version.minor = 0; Scavenger::notify(); // Call scavenger::notify() to cause the scavenger thread to be // created if it hasn't been created already. if (omniORB::trace(20)) { omniORB::logger log; log << "Server accepted connection from " << conn->peeraddress() << "\n"; }}////////////////////////////////////////////////////////////////////////giopStrand::~giopStrand(){ OMNIORB_ASSERT(pd_state == DYING); if (!giopStreamList::is_empty(servers)) { giopStreamList* gp = servers.next; while (gp != &servers) { GIOP_S* g = (GIOP_S*)gp; OMNIORB_ASSERT(g->state() == IOP_S::UnUsed); gp = gp->next; g->giopStreamList::remove(); delete g; } } if (!giopStreamList::is_empty(clients)) { giopStreamList* gp = clients.next; while (gp != &clients) { GIOP_C* g = (GIOP_C*)gp; OMNIORB_ASSERT(g->state() == IOP_C::UnUsed); gp = gp->next; g->giopStreamList::remove(); delete g; } } giopStream_Buffer* p = head; while (p) { giopStream_Buffer* q = p->next; giopStream_Buffer::deleteBuffer(p); p = q; } head = 0; p = spare; while (p) { giopStream_Buffer* q = p->next; giopStream_Buffer::deleteBuffer(p); p = q; } spare = 0;}////////////////////////////////////////////////////////////////////////CORBA::BooleangiopStrand::safeDelete(CORBA::Boolean forced){ CORBA::Boolean deleted = 1; if (!forced) { ASSERT_OMNI_TRACEDMUTEX_HELD(*omniTransportLock,1); deleted = pd_safelyDeleted = 1; if (giopStreamList::is_empty(clients) && giopStreamList::is_empty(servers) && giopStream::noLockWaiting(this)) { // No other threads should be waiting for a read or write lock // on the strand. Otherwise, the GIOP_C or GIOP_S lists would not // be empty. StrandList::remove(); RopeLink::remove(); deleteStrandAndConnection(); } } else { deleteStrandAndConnection(1); } return deleted;}////////////////////////////////////////////////////////////////////////voidgiopStrand::deleteStrandAndConnection(CORBA::Boolean forced){ // Delete this strand only when connection's reference count goes to 0. CORBA::String_var peeraddr; if (connection) { peeraddr = connection->peeraddress(); int count; if (!forced) { count = connection->decrRefCount(); if (omniORB::trace(25)) { omniORB::logger log; log << (isClient() ? "Client" : "Server") << " connection refcount = " << count << "\n"; } OMNIORB_ASSERT(count >= 0); if (count != 0) return; } else { count = connection->decrRefCount(1); if (omniORB::trace(25)) { omniORB::logger log; log << (isClient() ? "Client" : "Server") << " connection refcount (forced) = " << count << "\n"; } if (count) { // The only condition when this happen is when the connection // is bidirectional. giopServer still holds a refcount on this // connection. OMNIORB_ASSERT(biDir); connection->Shutdown(); // This would cause the giopServer to // remove this connection as well. return; // Do not delete the strand. Do so
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?