NetCoreServer icon indicating copy to clipboard operation
NetCoreServer copied to clipboard

Where is the right place to config socket buffer size

Open cuiliang opened this issue 4 years ago • 3 comments

When ssl session was created, It will have 3 buffer, which size are 65k. Where should I change the default size? Thank you.

cuiliang avatar Apr 18 '20 05:04 cuiliang

You can use OptionReceiveBufferSize and OptionSendBufferSize options in Client/Session for your case:

            // Prepare receive & send buffers
            _receiveBuffer.Reserve(OptionReceiveBufferSize);
            _sendBufferMain.Reserve(OptionSendBufferSize);
            _sendBufferFlush.Reserve(OptionSendBufferSize);

chronoxor avatar Apr 18 '20 14:04 chronoxor

I'v seen this code. but the problem is, these value are using Socket.ReceiveBufferSize and Socket.SendBufferSize, when SslSession is created, the Socket object is not there. The socket was given in Connect method, in the same method, buffer Reserved. There is no chance to set OptionReceiveBufferSize before Buffer.Reserve was called.

public int OptionReceiveBufferSize
        {
            get => Socket.ReceiveBufferSize;
            set => Socket.ReceiveBufferSize = value;
        }
.....
.....
internal void Connect(Socket socket)
        {
            Socket = socket;

            // Update the session socket disposed flag
            IsSocketDisposed = false;

            // Setup buffers
            _receiveBuffer = new Buffer();
            _sendBufferMain = new Buffer();
            _sendBufferFlush = new Buffer();

            // Apply the option: keep alive
            if (Server.OptionKeepAlive)
                Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
            // Apply the option: no delay
            if (Server.OptionNoDelay)
                Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);

            // Prepare receive & send buffers
            _receiveBuffer.Reserve(OptionReceiveBufferSize);
            _sendBufferMain.Reserve(OptionSendBufferSize);
            _sendBufferFlush.Reserve(OptionSendBufferSize);

cuiliang avatar Apr 18 '20 14:04 cuiliang

aah ok, I understand the issue. Will fix it soon!

chronoxor avatar Apr 18 '20 14:04 chronoxor