示例#1
0
文件: Buffer.cs 项目: Crysty-Yui/ice
 public Buffer(ByteBuffer data, ByteBuffer.ByteOrder order)
 {
     b = data;
     b.order(order);
     _size = data.remaining();
     _capacity = 0;
     _order = order;
 }
示例#2
0
        private int read(ByteBuffer buf)
        {
            Debug.Assert(_fd != null);
            int read = 0;

            while (buf.hasRemaining())
            {
                try
                {
                    int ret = _fd.Receive(buf.rawBytes(), buf.position(), buf.remaining(), SocketFlags.None);
                    if (ret == 0)
                    {
                        throw new Ice.ConnectionLostException();
                    }
                    read += ret;
                    buf.position(buf.position() + ret);
                }
                catch (SocketException ex)
                {
                    if (Network.wouldBlock(ex))
                    {
                        return(read);
                    }
                    else if (Network.interrupted(ex))
                    {
                        continue;
                    }
                    else if (Network.connectionLost(ex))
                    {
                        throw new Ice.ConnectionLostException(ex);
                    }

                    throw new Ice.SocketException(ex);
                }
            }
            return(read);
        }
示例#3
0
        private int write(ByteBuffer buf)
        {
            Debug.Assert(_fd != null);

#if COMPACT || SILVERLIGHT
            //
            // Silverlight and the Compact .NET Frameworks don't
            // support the use of synchronous socket operations on a
            // non-blocking socket. Returning 0 here forces the caller
            // to schedule an asynchronous operation.
            //
            return 0;
#else

            int packetSize = buf.remaining();
            if(AssemblyUtil.platform_ == AssemblyUtil.Platform.Windows)
            {
                //
                // On Windows, limiting the buffer size is important to prevent
                // poor throughput performances when transfering large amount of
                // data. See Microsoft KB article KB823764.
                //
                if(_maxSendPacketSize > 0 && packetSize > _maxSendPacketSize / 2)
                {
                    packetSize = _maxSendPacketSize / 2;
                }
            }

            int sent = 0;
            while(buf.hasRemaining())
            {
                try
                {
                    int ret = _fd.Send(buf.rawBytes(), buf.position(), packetSize, SocketFlags.None);
                    Debug.Assert(ret > 0);

                    sent += ret;
                    buf.position(buf.position() + ret);
                    if(packetSize > buf.remaining())
                    {
                        packetSize = buf.remaining();
                    }
                }
                catch(SocketException ex)
                {
                    if(Network.wouldBlock(ex))
                    {
                        return sent;
                    }
                    else if(Network.connectionLost(ex))
                    {
                        throw new Ice.ConnectionLostException(ex);
                    }
                    throw new Ice.SocketException(ex);
                }
            }
            return sent;
#endif
        }
示例#4
0
        private int read(ByteBuffer buf)
        {
            Debug.Assert(_fd != null);

#if COMPACT || SILVERLIGHT
            //
            // Silverlight and the Compact .NET Framework don't
            // support the use of synchronous socket operations on a
            // non-blocking socket. Returning 0 here forces the caller
            // to schedule an asynchronous operation.
            //
            return 0;
#else
            int read = 0;
            while(buf.hasRemaining())
            {
                try
                {
                    int ret = _fd.Receive(buf.rawBytes(), buf.position(), buf.remaining(), SocketFlags.None);
                    if(ret == 0)
                    {
                        throw new Ice.ConnectionLostException();
                    }
                    read += ret;
                    buf.position(buf.position() + ret);
                }
                catch(SocketException ex)
                {
                    if(Network.wouldBlock(ex))
                    {
                        return read;
                    }
                    else if(Network.interrupted(ex))
                    {
                        continue;
                    }
                    else if(Network.connectionLost(ex))
                    {
                        throw new Ice.ConnectionLostException(ex);
                    }

                    throw new Ice.SocketException(ex);
                }
            }
            return read;
#endif
        }
示例#5
0
        private int write(ByteBuffer buf)
        {
            Debug.Assert(_fd != null);

            int packetSize = buf.remaining();
            if(AssemblyUtil.platform_ == AssemblyUtil.Platform.Windows)
            {
                //
                // On Windows, limiting the buffer size is important to prevent
                // poor throughput performances when transfering large amount of
                // data. See Microsoft KB article KB823764.
                //
                if(_maxSendPacketSize > 0 && packetSize > _maxSendPacketSize / 2)
                {
                    packetSize = _maxSendPacketSize / 2;
                }
            }

            int sent = 0;
            while(buf.hasRemaining())
            {
                try
                {
                    int ret = _fd.Send(buf.rawBytes(), buf.position(), packetSize, SocketFlags.None);
                    Debug.Assert(ret > 0);

                    sent += ret;
                    buf.position(buf.position() + ret);
                    if(packetSize > buf.remaining())
                    {
                        packetSize = buf.remaining();
                    }
                }
                catch(SocketException ex)
                {
                    if(Network.wouldBlock(ex))
                    {
                        return sent;
                    }
                    else if(Network.connectionLost(ex))
                    {
                        throw new Ice.ConnectionLostException(ex);
                    }
                    throw new Ice.SocketException(ex);
                }
            }
            return sent;
        }
示例#6
0
        private int read(ByteBuffer buf)
        {
            Debug.Assert(_fd != null);
            int read = 0;
            while(buf.hasRemaining())
            {
                try
                {
                    int ret = _fd.Receive(buf.rawBytes(), buf.position(), buf.remaining(), SocketFlags.None);
                    if(ret == 0)
                    {
                        throw new Ice.ConnectionLostException();
                    }
                    read += ret;
                    buf.position(buf.position() + ret);
                }
                catch(SocketException ex)
                {
                    if(Network.wouldBlock(ex))
                    {
                        return read;
                    }
                    else if(Network.interrupted(ex))
                    {
                        continue;
                    }
                    else if(Network.connectionLost(ex))
                    {
                        throw new Ice.ConnectionLostException(ex);
                    }

                    throw new Ice.SocketException(ex);
                }
            }
            return read;
        }
示例#7
0
 public ByteBuffer put(ByteBuffer buf)
 {
     int len = buf.remaining();
     checkOverflow(len);
     System.Buffer.BlockCopy(buf._bytes, buf._position, _bytes, _position, len);
     _position += len;
     return this;
 }