コード例 #1
0
        private bool HandleNewConnection(SocketAsyncEventArgs e)
        {
            if (e.SocketError != SocketError.Success)
            {
                e.Dispose();
                return(false);
            }

            // Ok to create new event args on accept because we assume a connection to be long-running
            var receiveEventArgs = new SocketAsyncEventArgs();
            var bufferSize       = BufferSizeUtils.ClientBufferSize(maxSizeSettings);
            var buffer           = new byte[bufferSize];

            receiveEventArgs.SetBuffer(buffer, 0, bufferSize);

            var(store, functionsGen, serializer) = ((FasterKV <Key, Value>, Func <WireFormat, Functions>, ParameterSerializer))e.UserToken;

            var args = new ConnectionArgs <Key, Value, Input, Output, Functions, ParameterSerializer>
            {
                socket          = e.AcceptSocket,
                store           = store,
                functionsGen    = functionsGen,
                serializer      = serializer,
                maxSizeSettings = maxSizeSettings
            };

            receiveEventArgs.UserToken  = args;
            receiveEventArgs.Completed += ServerSessionBase <Key, Value, Input, Output, Functions, ParameterSerializer> .RecvEventArg_Completed;

            e.AcceptSocket.NoDelay = true;
            // If the client already have packets, avoid handling it here on the handler so we don't block future accepts.
            if (!e.AcceptSocket.ReceiveAsync(receiveEventArgs))
            {
                Task.Run(() => ServerSessionBase <Key, Value, Input, Output, Functions, ParameterSerializer> .RecvEventArg_Completed(null, receiveEventArgs));
            }
            return(true);
        }
コード例 #2
0
 public ServerFunctions(Functions functions, ServerSessionBase <Key, Value, Input, Output, Functions, ParameterSerializer> serverNetworkSession)
 {
     this.functions            = functions;
     this.serverNetworkSession = serverNetworkSession;
 }