Esempio n. 1
0
 public ServerSocket(string name, IPEndPoint listeningEndPoint, FregataOptions fregataOptions, IBufferPool receivedBufferPool, IBufferPool sendBufferPool, ITcpConnectionServerHandler tcpConnectionServerHandler)
 {
     if (string.IsNullOrWhiteSpace(name))
     {
         ThrowHelper.ThrowServerNameNotBeNullErrorException();
     }
     if (listeningEndPoint == null)
     {
         ThrowHelper.ThrowListenEndPointNotBeNullErrorException();
     }
     Id   = SnowflakeId.Default().NextId();
     Name = name;
     ListeningEndPoint                       = listeningEndPoint;
     Setting                                 = fregataOptions;
     _receivedBufferPool                     = receivedBufferPool ?? throw new ArgumentNullException("receivedBufferPool");
     _sendBufferPool                         = sendBufferPool ?? throw new ArgumentNullException("sendBufferPool");
     _tcpConnectionServerHandler             = tcpConnectionServerHandler ?? throw new ArgumentNullException("tcpConnectionServerHandler");
     tcpConnectionServerHandler.ServerSocket = this;
     Socket                       = SocketUtil.CreateSocket(listeningEndPoint, fregataOptions.SendMaxSize, fregataOptions.ReceiveMaxSize);
     _connectionDict              = new ConcurrentDictionary <long, ITcpConnection>();
     _connectionEventListeners    = new List <ITcpConnectionEventListener>();
     _serverScoketEventListeners  = new List <IServerScoketEventListener>();
     _acceptSocketArgs            = new SocketAsyncEventArgs();
     _acceptSocketArgs.Completed += AcceptCompleted;
     _connectionEventListeners.Add(new ServerTcpConnectionEventListener(this));
 }
Esempio n. 2
0
 public ClientSocket(string name, EndPoint serverEndPoint, FregataOptions fregataOptions, IBufferPool receivedBufferPool, IBufferPool sendBufferPool, ITcpConnectionHandler tcpConnectionHandler)
 {
     Id                           = SnowflakeId.Default().NextId();
     Name                         = name ?? throw new ArgumentNullException(nameof(name));
     ServerEndPoint               = serverEndPoint ?? throw new ArgumentNullException(nameof(serverEndPoint));
     Setting                      = fregataOptions ?? throw new ArgumentNullException(nameof(fregataOptions));
     _receivedBufferPool          = receivedBufferPool ?? throw new ArgumentNullException(nameof(receivedBufferPool));
     _sendBufferPool              = sendBufferPool ?? throw new ArgumentNullException(nameof(sendBufferPool));
     _waitConnectHandle           = new ManualResetEvent(false);
     Socket                       = SocketUtil.CreateSocket(serverEndPoint, fregataOptions.SendMaxSize, fregataOptions.ReceiveMaxSize);
     _tcpConnectionHandler        = tcpConnectionHandler;
     _tcpConnectionEventListeners = new List <ITcpConnectionEventListener>();
 }
Esempio n. 3
0
        public TcpConnection(string name, Socket socket, FregataOptions fregataOptions, IBufferPool receivedBufferPool, IBufferPool sendBufferPool, ITcpConnectionHandler tcpConnectionHandler)
        {
            Id                           = SnowflakeId.Default().NextId();
            Name                         = name;
            Socket                       = socket;
            LocalEndPoint                = socket.LocalEndPoint;
            RemotingEndPoint             = socket.RemoteEndPoint;
            Setting                      = fregataOptions;
            _tcpConnectionEventListeners = new List <ITcpConnectionEventListener>();

            _tcpConnectionHandler = tcpConnectionHandler;

            _messageFramer = new LengthPrefixMessageFramer(Setting);
            _messageFramer.RegisterMessageArrivedCallback(OnMessageArrived);
            _receiveBuufferPipeline = new BufferPipeline(bufferPool: receivedBufferPool, littelEndian: fregataOptions.LittleEndian, coding: fregataOptions.Encode, writerFlushCompleted: null);

            _sendBuufferPipeline = new BufferPipeline(bufferPool: sendBufferPool, littelEndian: fregataOptions.LittleEndian, coding: fregataOptions.Encode, writerFlushCompleted: null);
            Task.Run(() => TryReceiveAsync());
        }
 public LengthPrefixMessageFramerTest()
 {
     _fregataOptions = new FregataOptions();
 }
Esempio n. 5
0
 public LengthPrefixMessageFramer(FregataOptions fregataOptions)
 {
     _headerSize = fregataOptions.LengthField;
 }