예제 #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;
                }
            }
        }