Beispiel #1
0
 internal WriteEventArgs(SocketClient sc, int length)
     : base(sc)
 {
     length_ = length;
 }
Beispiel #2
0
 internal DisconnectEventArgs(SocketClient sc, Exception ex)
     : base(sc)
 {
     ex_ = ex;
 }
Beispiel #3
0
 internal ConnectEventArgs(SocketClient sc, int readSize)
     : base(sc)
 {
     this.readSize_ = readSize;
 }
Beispiel #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="sc">SocketClient object</param>
 internal SocketEventArgs(SocketClient sc)
     : base()
 {
     sc_ = sc;
 }
Beispiel #5
0
        /// <summary>
        /// Handler for the connect operation
        /// </summary>
        /// <param name="ar">Result information</param>
        private void AcceptCallbackHandler(IAsyncResult ar)
        {
            // Signal the main thread to continue.
            listenInfo_.acceptingEvent_.Set();

            try
            {
                // Get the socket that handles the client request.
                Socket handler = sock_.EndAccept(ar);

                // Create the state object.
                SocketClient scNew = new SocketClient(handler);

                // Notify the client application
                ConnectEventArgs connEv = new ConnectEventArgs(scNew, listenInfo_.ReadSize);
                if (OnStartSession != null)
                {
                    try
                    {
                        OnStartSession(this, connEv);
                    }
                    catch { }
                }

                if (scNew.IsConnected)
                {
                    // If we are auto-wireup events then do so.
                    if (connEv.AutoConnect == true)
                    {
                        if (this.OnEndSession != null)
                        {
                            foreach (Delegate d in this.OnEndSession.GetInvocationList())
                            {
                                scNew.OnEndSession += (EventHandler <SocketEventArgs>)d;
                            }
                        }
                        if (this.OnFailure != null)
                        {
                            foreach (Delegate d in this.OnFailure.GetInvocationList())
                            {
                                scNew.OnFailure += (EventHandler <SocketEventArgs>)d;
                            }
                        }
                        if (this.OnReceiveData != null)
                        {
                            foreach (Delegate d in this.OnReceiveData.GetInvocationList())
                            {
                                scNew.OnReceiveData += (EventHandler <SocketEventArgs>)d;
                            }
                        }
                        if (this.OnSendDataComplete != null)
                        {
                            foreach (Delegate d in this.OnSendDataComplete.GetInvocationList())
                            {
                                scNew.OnSendDataComplete += (EventHandler <SocketEventArgs>)d;
                            }
                        }
                    }

                    if (connEv.NextReadSize > 0)
                    {
                        scNew.PostReceive(connEv.NextReadSize, true);
                    }
                }
            }
            catch (ObjectDisposedException)
            {
                // Ignore and exit.
            }
            catch (SocketException ex)
            {
                if (OnFailure != null)
                {
                    ErrorEventArgs errEv = new ErrorEventArgs(this, ErrorEventArgs.SocketOperation.Accept, ex);
                    try
                    {
                        OnFailure(this, errEv);
                    }
                    catch { }
                }
            }
        }
Beispiel #6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="sc">Socket connection reporting the error (may be closed or empty).</param>
 /// <param name="op">Operation which failed</param>
 /// <param name="ex">Exception information</param>
 internal ErrorEventArgs(SocketClient sc, SocketOperation op, Exception ex)
     : base(sc, ex)
 {
     opType_ = op;
 }