Create() private static method

private static Create ( ByteString1 b, ByteStrings bs ) : ByteString
b ByteString1
bs ByteStrings
return ByteString
コード例 #1
0
        private void DoReceive(ChannelRegistration registration, IActorRef handler)
        {
            Action <int, ByteBuffer> innerReceive = null;

            innerReceive = (readsLeft, buffer) =>
            {
                buffer.Clear();
                buffer.Limit(_udp.Setting.DirectBufferSize);

                var sender = Channel.Receive(buffer);
                if (sender != null)
                {
                    buffer.Flip();
                    handler.Tell(new Udp.Received(ByteString.Create(buffer), sender));
                    if (readsLeft > 0)
                    {
                        innerReceive(readsLeft - 1, buffer);
                    }
                }
            };

            var buffr = _udp.BufferPool.Acquire();

            try
            {
                innerReceive(_udp.Setting.BatchReceiveLimit, buffr);
            }
            finally
            {
                _udp.BufferPool.Release(buffr);
                registration.EnableInterest(SocketAsyncOperation.Receive);
            }
        }
コード例 #2
0
        private void DoRead(ChannelRegistration registration, IActorRef handler)
        {
            Action <int, ByteBuffer> innerRead = null;

            innerRead = (readsLeft, buffer) =>
            {
                buffer.Clear();
                buffer.Limit(_udpConn.Settings.DirectBufferSize);
                if (_channel.Read(buffer) > 0)
                {
                    buffer.Flip();
                    handler.Tell(new UdpConnected.Received(ByteString.Create(buffer)));
                    innerRead(readsLeft - 1, buffer);
                }
            };
            var buffr = _udpConn.BufferPool.Acquire();

            try
            {
                innerRead(_udpConn.Settings.BatchReceiveLimit, buffr);
            }
            finally
            {
                registration.EnableInterest(SocketAsyncOperation.Receive);
                _udpConn.BufferPool.Release(buffr);
            }
        }
コード例 #3
0
ファイル: TcpConnection.cs プロジェクト: zhanjian/akka.net
        private void DoRead(ConnectionInfo info, IActorRef closeCommander)
        {
            if (!_readingSuspended)
            {
                Func <ByteBuffer, int, ReadResult> innerRead = null;
                innerRead = (buffer, remainingLimit) =>
                {
                    if (remainingLimit > 0)
                    {
                        buffer.Clear();
                        var maxBufferSpace = Math.Min(_tcp.Settings.DirectBufferSize, remainingLimit);
                        buffer.Limit(maxBufferSpace);
                        var readBytes = Channel.Read(buffer);
                        buffer.Flip();

                        if (_tcp.Settings.TraceLogging)
                        {
                            _log.Debug("Read [{0}] bytes.", readBytes);
                        }
                        if (readBytes > 0)
                        {
                            info.Handler.Tell(new Tcp.Received(ByteString.Create(buffer)));
                        }

                        if (readBytes == maxBufferSpace)
                        {
                            return(_pullMode
                                ? MoreDataWaiting.Instance
                                : innerRead(buffer, remainingLimit - maxBufferSpace));
                        }
                        if (readBytes >= 0)
                        {
                            return(AllRead.Instance);
                        }
                        if (readBytes == -1)
                        {
                            return(EndOfStream.Instance);
                        }

                        throw new IllegalStateException("Unexpected value returned from read: " + readBytes);
                    }
                    return(MoreDataWaiting.Instance);
                };
                var buffr = _tcp.BufferPool.Acquire();
                try
                {
                    var read = innerRead(buffr, _tcp.Settings.ReceivedMessageSizeLimit);
                    if (read is AllRead)
                    {
                        if (!_pullMode)
                        {
                            info.Registration.EnableInterest(SocketAsyncOperation.Receive);
                        }
                    }
                    if (read is MoreDataWaiting)
                    {
                        if (!_pullMode)
                        {
                            Self.Tell(SelectionHandler.ChannelReadable.Instance);
                        }
                    }

                    // TODO: Port. Socket does not seem to expose (isOutputShutdown). It is passed as 'how' argument to Socket.Shutdown, but not exposed.
                    // case EndOfStream if channel.socket.isOutputShutdown ⇒
                    //    if (TraceLogging) log.debug("Read returned end-of-stream, our side already closed")
                    //    doCloseConnection(info.handler, closeCommander, ConfirmedClosed)

                    if (read is EndOfStream)
                    {
                        if (_tcp.Settings.TraceLogging)
                        {
                            _log.Debug("Read returned end-of-stream, our side not yet closed");
                        }
                        HandleClose(info, closeCommander, IO.Tcp.PeerClosed.Instance);
                    }
                }
                catch (SocketException e)
                {
                    HandleError(info.Handler, e);
                }
                finally
                {
                    Tcp.BufferPool.Release(buffr);
                }
            }
        }