예제 #1
0
        /// <summary>
        /// Read in message lines from the IRC server
        /// and send them to a parser for processing.
        /// Discard CTCP and DCC messages if these protocols
        /// are not enabled.
        /// </summary>
        internal void ReceiveIRCMessages()
        {
            Debug.WriteLineIf(Rfc2812Util.IrcTrace.TraceInfo, "[" + Thread.CurrentThread.Name + "] Connection::ReceiveIRCMessages()");
            string line;

            try
            {
                while ((line = reader.ReadLine()) != null)
                {
                    try
                    {
                        Debug.WriteLineIf(Rfc2812Util.IrcTrace.TraceVerbose, "[" + Thread.CurrentThread.Name + "] Connection::ReceiveIRCMessages() rec'd:" + line);
                        //Try any custom parsers first
                        if (CustomParse(line))
                        {
                            //One of the custom parsers handled this message so
                            //we go back to listening
                            continue;
                        }
                        if (IsDccRequest(line))
                        {
                            continue;
                        }
                        if (IsCtcpMessage(line))
                        {
                            continue;
                        }

                        listener.Parse(line);
                        if (OnRawMessageReceived != null)
                        {
                            OnRawMessageReceived(line);
                        }
                    }
                    catch (ThreadAbortException e)
                    {
                        Thread.ResetAbort();
                        //This exception is raised when the Thread
                        //is stopped at user request, i.e. via Disconnect()
                        //This will stop the read loop and close the connection.
                        break;
                    }
                }
            }
            catch (IOException e)
            {
                //Trap a connection failure
                Debug.WriteLineIf(Rfc2812Util.IrcTrace.TraceWarning, "[" + Thread.CurrentThread.Name + "] Connection::ReceiveIRCMessages() IO Error while listening for messages " + e);
                listener.Error(ReplyCode.ConnectionFailed, "Connection to server unexpectedly failed.");
            }
            finally
            {
                //The connection to the IRC server has been closed either
                //by client request or the server itself closed the connection.
                client.Close();
                registered = false;
                connected  = false;
                listener.Disconnected();
            }
        }
예제 #2
0
 private void ListenForMessages()
 {
     while (m_listenerActive)
     {
         // receive messages
         SecureTcpClient client = null;
         try {
             client = m_listener.AcceptTcpClient();
             if (client != null)   // everything ok
             // disable Nagle algorithm, to reduce delay
             {
                 client.NoDelay = true;
                 // now process the message of this client
                 SslServerTransport transport = new SslServerTransport(client);
                 m_clientAcceptCallback(transport);
             }
             else
             {
                 Trace.WriteLine("acceptTcpClient hasn't worked");
             }
         } catch (Exception e) {
             Debug.WriteLine("Exception in server listener thread: " + e);
             if (client != null)
             {
                 client.Close();
             }
         }
     }
 }
예제 #3
0
        /// <summary>
        /// Read in message lines from the IRC server
        /// and send them to a parser for processing.
        /// Discard CTCP and DCC messages if these protocols
        /// are not enabled.
        /// </summary>
        internal void ReceiveIRCMessages()
        {
            string line;

            try
            {
                while ((line = reader.ReadLine()) != null)
                {
                    try
                    {
                        if (IsDccRequest(line))
                        {
                            continue;
                        }
                        if (IsCtcpMessage(line))
                        {
                            continue;
                        }

                        listener.Parse(line);
                        if (OnRawMessageReceived != null)
                        {
                            OnRawMessageReceived(line);
                        }
                    }
                    catch (ThreadAbortException)
                    {
                        Thread.ResetAbort();
                        //This exception is raised when the Thread
                        //is stopped at user request, i.e. via Disconnect()
                        //This will stop the read loop and close the connection.
                        break;
                    }
                }
            }
            catch (IOException)
            {
                //Trap a connection failure
                listener.Error(ReplyCode.ConnectionFailed, "Connection to server unexpectedly failed.");
            }
            finally
            {
                //The connection to the IRC server has been closed either
                //by client request or the server itself closed the connection.
                client.Close();
                registered = false;
                connected  = false;
                listener.Disconnected();
            }
        }
예제 #4
0
 /// <summary><see cref="Ch.Elca.Iiop.ITranport.CloseConnection/></summary>
 public void CloseConnection()
 {
     try {
         if (m_socket != null)
         {
             m_socket.Close();
         }
     } catch {
         // ignore
     }
     m_socket = null;
     try {
         if (m_stream != null)
         {
             m_stream.Close(); // close the stream and the socket.
         }
     } catch {
         // ignore
     }
     m_stream = null;
 }