Beispiel #1
0
        } // InitializeSocketTimeoutHandler

        private static void TimeoutConnections(Object state, Boolean wasSignalled)
        {
            DateTime currentTime = DateTime.UtcNow;

            lock (_connections)
            {
                foreach (DictionaryEntry entry in _connections)
                {
                    PortConnection connection = (PortConnection)entry.Value;
                    if (DateTime.Now - connection.LastUsed > _portLifetime)
                    {
                        connection.Port.Dispose();
                    }
                }
            }

            _registeredWaitHandle.Unregister(null);
            _registeredWaitHandle =
                ThreadPool.UnsafeRegisterWaitForSingleObject(
                    _socketTimeoutWaitHandle,
                    _socketTimeoutDelegate,
                    "IpcConnectionTimeout",
                    _socketTimeoutPollTime,
                    true); // execute only once
        } // TimeoutConnections
 public void ReleaseConnection(IpcPort port)
 {
     string name = port.Name;
     PortConnection connection = (PortConnection) _connections[name];
     if (port.Cacheable && ((connection == null) || connection.Port.IsDisposed))
     {
         lock (_connections)
         {
             _connections[name] = new PortConnection(port);
             return;
         }
     }
     port.Dispose();
 }
        public void ReleaseConnection(IpcPort port)
        {
            string         name       = port.Name;
            PortConnection connection = (PortConnection)_connections[name];

            if (port.Cacheable && ((connection == null) || connection.Port.IsDisposed))
            {
                lock (_connections)
                {
                    _connections[name] = new PortConnection(port);
                    return;
                }
            }
            port.Dispose();
        }
Beispiel #4
0
        } // GetSocket

        public void ReleaseConnection(IpcPort port)
        {
            string         portName   = port.Name;
            PortConnection connection = (PortConnection)_connections[portName];

            if (port.Cacheable && (connection == null || connection.Port.IsDisposed))
            {
                lock (_connections)
                {
                    _connections[portName] = new PortConnection(port);
                }
            }
            else
            {
                // there should have been a connection, so let's just close
                //   this socket.
                port.Dispose();
            }
        } // ReleasePort
        public IpcPort GetConnection(string portName, bool secure, TokenImpersonationLevel level, int timeout)
        {
            PortConnection connection = null;

            lock (_connections)
            {
                bool flag = true;
                if (secure)
                {
                    try
                    {
                        WindowsIdentity current = WindowsIdentity.GetCurrent(true);
                        if (current != null)
                        {
                            flag = false;
                            current.Dispose();
                        }
                    }
                    catch (Exception)
                    {
                        flag = false;
                    }
                }
                if (flag)
                {
                    connection = (PortConnection)_connections[portName];
                }
                if ((connection == null) || connection.Port.IsDisposed)
                {
                    connection = new PortConnection(IpcPort.Connect(portName, secure, level, timeout))
                    {
                        Port = { Cacheable = flag }
                    };
                }
                else
                {
                    _connections.Remove(portName);
                }
            }
            return(connection.Port);
        }
Beispiel #6
0
        } // TimeoutConnections

        // The key is expected to of the form portName
        public IpcPort GetConnection(String portName, bool secure, TokenImpersonationLevel level, int timeout)
        {
            PortConnection connection = null;

            lock (_connections)
            {
                bool cacheable = true;
                if (secure)
                {
                    try
                    {
                        WindowsIdentity currentId = WindowsIdentity.GetCurrent(true /*ifImpersonating*/);
                        if (currentId != null)
                        {
                            cacheable = false;
                            currentId.Dispose();
                        }
                    }
                    catch (Exception)
                    {
                        cacheable = false;
                    }
                }

                if (cacheable)
                {
                    connection = (PortConnection)_connections[portName];
                }
                if (connection == null || connection.Port.IsDisposed)
                {
                    connection = new PortConnection(IpcPort.Connect(portName, secure, level, timeout));
                    connection.Port.Cacheable = cacheable;
                }
                else
                {
                    // Remove the connection from the cache
                    _connections.Remove(portName);
                }
            }
            return(connection.Port);
        } // GetSocket
 public IpcPort GetConnection(string portName, bool secure, TokenImpersonationLevel level, int timeout)
 {
     PortConnection connection = null;
     lock (_connections)
     {
         bool flag = true;
         if (secure)
         {
             try
             {
                 WindowsIdentity current = WindowsIdentity.GetCurrent(true);
                 if (current != null)
                 {
                     flag = false;
                     current.Dispose();
                 }
             }
             catch (Exception)
             {
                 flag = false;
             }
         }
         if (flag)
         {
             connection = (PortConnection) _connections[portName];
         }
         if ((connection == null) || connection.Port.IsDisposed)
         {
             connection = new PortConnection(IpcPort.Connect(portName, secure, level, timeout)) {
                 Port = { Cacheable = flag }
             };
         }
         else
         {
             _connections.Remove(portName);
         }
     }
     return connection.Port;
 }
        } // TimeoutConnections
        
        // The key is expected to of the form portName
        public IpcPort GetConnection(String portName, bool secure, TokenImpersonationLevel level, int timeout)
        {
            PortConnection connection = null;
            lock (_connections)
            {
                bool cacheable = true;
                if (secure)
                {
                  try
                  {
                    WindowsIdentity currentId = WindowsIdentity.GetCurrent(true/*ifImpersonating*/);
                    if (currentId != null)
                    {
                      cacheable = false;
                      currentId.Dispose();
                    }
                  }
                  catch(Exception)
                  {
                      cacheable = false;
                  }
                }

                if (cacheable)
                {
                    connection = (PortConnection)_connections[portName];
                }
                if (connection == null || connection.Port.IsDisposed)
                {
                    connection = new PortConnection(IpcPort.Connect(portName, secure, level, timeout));
                    connection.Port.Cacheable = cacheable;
                }
                else
                {
                    // Remove the connection from the cache
                    _connections.Remove(portName); 
                }
            }
            return connection.Port;
        } // GetSocket
        } // GetSocket

        public void ReleaseConnection(IpcPort port)
        {
            string portName = port.Name;
            PortConnection connection = (PortConnection)_connections[portName];
            if (port.Cacheable && (connection == null || connection.Port.IsDisposed))
            {
                lock(_connections)
                {
                    _connections[portName] = new PortConnection(port);
                }
            }
            else
            {
                // there should have been a connection, so let's just close
                //   this socket.
                port.Dispose();
            }
        } // ReleasePort