Beispiel #1
0
 internal abstract void BeginSendToAll(ServerSocketConnection connection, byte[] buffer, bool includeMe);
Beispiel #2
0
 internal override void BeginSendToAll(ServerSocketConnection connection, byte[] buffer, bool includeMe)
 {
 }
Beispiel #3
0
        /// <summary>
        /// Accept callback!
        /// </summary>
        internal void BeginAcceptCallback(object state)
        {
            SocketAsyncEventArgs e = (SocketAsyncEventArgs)state;

            if (Disposed)
                return;

            SocketListener listener = null;
            Socket acceptedSocket = null;
            BaseSocketConnection connection = null;

            listener = (SocketListener)e.UserToken;

            if (e.SocketError == SocketError.Success)
            {
                try
                {
                    //----- Get accepted socket!
                    acceptedSocket = e.AcceptSocket;

                    //----- Adjust buffer size!
                    acceptedSocket.ReceiveBufferSize = Context.Host.Context.SocketBufferSize;
                    acceptedSocket.SendBufferSize = Context.Host.Context.SocketBufferSize;

                    connection = new ServerSocketConnection(Context.Host, listener, acceptedSocket);

                    //----- Initialize!
                    Context.Host.AddSocketConnection(connection);
                    connection.Active = true;

                    Context.Host.InitializeConnection(connection);
                }
                catch
                {
                    if (connection != null)
                    {
                        if (Context.Host != null)
                        {
                            Context.Host.DisposeConnection(connection);
                            Context.Host.RemoveSocketConnection(connection);
                        }

                        connection = null;
                    }
                }
            }

            //---- Continue to accept!
            SocketAsyncEventArgs e2 = new SocketAsyncEventArgs();
            e2.UserToken = listener;
            e2.Completed += new EventHandler<SocketAsyncEventArgs>(BeginAcceptCallbackAsync);

            if (!listener.Socket.AcceptAsync(e2))
            {
                BeginAcceptCallbackAsync(this, e2);
            }

            e.UserToken = null;
            e.Dispose();
            e = null;
        }
Beispiel #4
0
        internal override void BeginSendToAll(ServerSocketConnection connection, byte[] buffer, bool includeMe)
        {
            if (Disposed)
                return;

            BaseSocketConnection[] items = GetSocketConnections();

            if (items != null)
            {
                int loopSleep = 0;

                foreach (BaseSocketConnection cnn in items)
                {
                    if (Disposed)
                    {
                        break;
                    }

                    try
                    {
                        if (includeMe || connection != cnn)
                        {
                            byte[] localBuffer = new byte[buffer.Length];
                            Buffer.BlockCopy(buffer, 0, localBuffer, 0, buffer.Length);

                            BeginSend(cnn, localBuffer, true);
                        }
                    }
                    finally
                    {
                        ThreadEx.LoopSleep(ref loopSleep);
                    }
                }
            }
        }