Пример #1
0
        private void ConnectCompleted(object sender, SocketAsyncEventArgs e)
        {
            try
            {
                if (e.SocketError != SocketError.Success)
                {
                    HandleSocketError(e.SocketError);
                    return;
                }

                Debug.Assert(e.UserToken != null);
                var token = (Tuple <bool, string, IrcRegistrationInfo>)e.UserToken;

                // Create stream for received data. Use SSL stream on top of network stream, if specified.
                this.receiveStream = new CircularBufferStream(socketReceiveBufferSize);
#if SILVERLIGHT
                this.dataStream = this.receiveStream;
#else
                this.dataStream = GetDataStream(token.Item1, token.Item2);
#endif
                this.dataStreamReader     = new StreamReader(this.dataStream, TextEncoding);
                this.dataStreamLineReader = new SafeLineReader(this.dataStreamReader);

                // Start sending and receiving data to/from server.
                this.sendTimer.Change(0, Timeout.Infinite);
                ReceiveAsync();

                HandleClientConnected(token.Item3);
            }
            catch (SocketException exSocket)
            {
                HandleSocketError(exSocket);
            }
            catch (ObjectDisposedException)
            {
                // Ignore.
            }
#if !DEBUG
            catch (Exception ex)
            {
                OnConnectFailed(new IrcErrorEventArgs(ex));
            }
#endif
            finally
            {
                e.Dispose();
            }
        }
Пример #2
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (disposing)
            {
                if (this.socket != null)
                {
                    this.socket.Dispose();
                    this.socket = null;

                    HandleClientDisconnected();
                }
                if (this.receiveStream != null)
                {
                    this.receiveStream.Dispose();
                    this.receiveStream = null;
                }
                if (this.dataStream != null)
                {
                    this.dataStream.Dispose();
                    this.dataStream = null;
                }
                if (this.dataStreamReader != null)
                {
                    this.dataStreamReader.Dispose();
                    this.dataStreamReader = null;
                }
                if (this.sendTimer != null)
                {
                    this.sendTimer.Dispose();
                    this.sendTimer = null;
                }
                if (this.disconnectedEvent != null)
                {
                    this.disconnectedEvent.Close();
                    this.disconnectedEvent = null;
                }
            }
        }
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (disposing)
            {
                if (socket != null)
                {
                    socket.Dispose();
                    socket = null;

                    HandleClientDisconnected();
                }
                if (receiveStream != null)
                {
                    receiveStream.Dispose();
                    receiveStream = null;
                }
                if (dataStream != null)
                {
                    dataStream.Dispose();
                    dataStream = null;
                }
                if (dataStreamReader != null)
                {
                    dataStreamReader.Dispose();
                    dataStreamReader = null;
                }
                if (sendTimer != null)
                {
                    sendTimer.Dispose();
                    sendTimer = null;
                }
                if (disconnectedEvent != null)
                {
                    disconnectedEvent.Close();
                    disconnectedEvent = null;
                }
            }
        }
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (disposing)
            {
                if (this.socket != null)
                {
                    this.socket.Dispose();
                    this.socket = null;

                    HandleClientDisconnected();
                }
                if (this.receiveStream != null)
                {
                    this.receiveStream.Dispose();
                    this.receiveStream = null;
                }
                if (this.dataStream != null)
                {
                    this.dataStream.Dispose();
                    this.dataStream = null;
                }
                if (this.dataStreamReader != null)
                {
                    this.dataStreamReader.Dispose();
                    this.dataStreamReader = null;
                }
                if (this.sendTimer != null)
                {
                    this.sendTimer.Dispose();
                    this.sendTimer = null;
                }
                if (this.disconnectedEvent != null)
                {
                    this.disconnectedEvent.Close();
                    this.disconnectedEvent = null;
                }
            }
        }
Пример #5
0
        private void ConnectCompleted(object sender, SocketAsyncEventArgs e)
        {
            try
            {
                if (e.SocketError != SocketError.Success)
                {
                    HandleSocketError(e.SocketError);
                    return;
                }

                Debug.Assert(e.UserToken != null);
                var token = (Tuple<bool, string, IrcRegistrationInfo>)e.UserToken;

                // Create stream for received data. Use SSL stream on top of network stream, if specified.
                this.receiveStream = new CircularBufferStream(socketReceiveBufferSize);
            #if SILVERLIGHT
                this.dataStream = this.receiveStream;
            #else
                this.dataStream = GetDataStream(token.Item1, token.Item2);
            #endif
                this.dataStreamReader = new StreamReader(this.dataStream, TextEncoding);
                this.dataStreamLineReader = new SafeLineReader(this.dataStreamReader);

                // Start sending and receiving data to/from server.
                this.sendTimer.Change(0, Timeout.Infinite);
                ReceiveAsync();

                HandleClientConnected(token.Item3);
            }
            catch (SocketException exSocket)
            {
                HandleSocketError(exSocket);
            }
            catch (ObjectDisposedException)
            {
                // Ignore.
            }
            #if !DEBUG
            catch (Exception ex)
            {
                OnConnectFailed(new IrcErrorEventArgs(ex));
            }
            #endif
            finally
            {
                e.Dispose();
            }
        }
Пример #6
0
        /// <summary>
        /// Releases all resources used by the <see cref="IrcClient"/>.
        /// </summary>
        /// <param name="disposing"><see langword="true"/> if the consumer is actively disposing the object;
        /// <see langword="false"/> if the garbage collector is finalizing the object.</param>
        protected void Dispose(bool disposing)
        {
            if (Interlocked.CompareExchange(ref this.disposedFlag, 1, 0) > 0)
                return;

            if (disposing)
            {
                if (this.socket != null)
                {
                    this.socket.Dispose();
                    this.socket = null;

                    HandleClientDisconnected();
                }
                if (this.receiveStream != null)
                {
                    this.receiveStream.Dispose();
                    this.receiveStream = null;
                }
                if (this.dataStream != null)
                {
                    this.dataStream.Dispose();
                    this.dataStream = null;
                }
                if (this.dataStreamReader != null)
                {
                    this.dataStreamReader.Dispose();
                    this.dataStreamReader = null;
                }
                if (this.sendTimer != null)
                {
                    this.sendTimer.Dispose();
                    this.sendTimer = null;
                }
                if (this.disconnectedEvent != null)
                {
                    this.disconnectedEvent.Close();
                    this.disconnectedEvent = null;
                }
            }
        }
Пример #7
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (disposing)
            {
                if (socket != null)
                {
                    socket.Dispose();
                    socket = null;

                    HandleClientDisconnected();
                }
                if (receiveStream != null)
                {
                    receiveStream.Dispose();
                    receiveStream = null;
                }
                if (dataStream != null)
                {
                    dataStream.Dispose();
                    dataStream = null;
                }
                if (dataStreamReader != null)
                {
                    dataStreamReader.Dispose();
                    dataStreamReader = null;
                }
                if (sendTimer != null)
                {
                    sendTimer.Dispose();
                    sendTimer = null;
                }
                if (disconnectedEvent != null)
                {
                    disconnectedEvent.Close();
                    disconnectedEvent = null;
                }
            }
        }