Yaircc.Net.IRC.Connection.ConnectCallback C# (CSharp) Method

ConnectCallback() private method

Handles the connection request callback of the under lying socket.
private ConnectCallback ( IAsyncResult result ) : void
result IAsyncResult Represents the status of the asynchronous operation.
return void
        private void ConnectCallback(IAsyncResult result)
        {
            try
            {
                this.client.EndConnect(result);
            }
            catch (Exception ex)
            {
                this.IsConnected = false;
                if (this.connectionFailed != null)
                {
                    this.connectionFailed(this, new ConnectionFailedEventArgs(ex));
                    return;
                }
            }

            NetworkStream stream = this.client.GetStream();
            byte[] buffer = new byte[this.client.ReceiveBufferSize];

            this.IsConnected = true;
            if (this.connectionEstablished != null)
            {
                this.connectionEstablished(this, EventArgs.Empty);
            }

            stream.BeginRead(buffer, 0, buffer.Length, this.ReceiveCallback, buffer);
        }