예제 #1
0
        private static void Send(ClientManager clientManager, byte[] buffer, int count)
        {
            int bytesSent = 0;
            lock (clientManager.SendMutex)
            {
                while (bytesSent < count)
                {
                    try
                    {
                        clientManager.ResetAsyncSendTime();

                        bytesSent += clientManager.ClientSocket.Send(buffer, bytesSent, count - bytesSent, SocketFlags.None);

                        clientManager.AddToClientsBytesSent(bytesSent);
                        if (SocketServer.IsServerCounterEnabled) clientManager.ConnectionManager.PerfStatsColl.IncrementBytesSentPerSecStats(bytesSent);
                    }
                    catch (SocketException e)
                    {

                        if (e.SocketErrorCode == SocketError.NoBufferSpaceAvailable)
                            continue;
                        else throw;
                    }
                }

                clientManager.ResetAsyncSendTime();
            }
        }
예제 #2
0
        private static void AssureSendOld(ClientManager clientManager, byte[] buffer, int count, SendContext context)
        {
            TimeSpan tempTaken;

            try
            {
                Send(clientManager, buffer, count);
                SendContext opContext = null;

                do
                {
                    opContext = null;
                    lock (clientManager)
                    {
                        if (clientManager.PendingSendOperationQueue.Count > 0)
                        {
                            object operation = clientManager.PendingSendOperationQueue.remove();
                            opContext = (SendContext)operation;
                            clientManager.ResetAsyncSendTime();

                            if (SocketServer.IsServerCounterEnabled) clientManager.ConnectionManager.PerfStatsColl.DecrementResponsesQueueCountStats();
                            if (SocketServer.IsServerCounterEnabled) clientManager.ConnectionManager.PerfStatsColl.DecrementResponsesQueueSizeStats(opContext.expectedSize);
                        }
                    }

                    if (opContext != null)
                    {
                        Send(opContext.clientManager, opContext.buffer, opContext.expectedSize);
                    }

                    lock (clientManager)
                    {
                        if (clientManager.PendingSendOperationQueue.Count == 0)
                        {
                            clientManager.DeMarkOperationInProcess();
                            return;
                        }
                    }

                } while (clientManager.PendingSendOperationQueue.Count > 0);

            }
            catch (Exception e)
            {
                if (SocketServer.Logger != null && SocketServer.Logger.IsErrorLogsEnabled)
                    SocketServer.Logger.NCacheLog.Error("ConnectionManager.AssureSend", e.ToString());

                DisposeClient(clientManager);
            }
        }