capacity() public method

public capacity ( ) : int
return int
コード例 #1
0
        public int read(ByteBuffer dst)
        {
            int toRead = dst.capacity();

            byte[] message = new byte[toRead];

            int readBytes = 0;
            int waitTime  = 0;

            lock (this) {
                while (readBytes < toRead && waitTime < readTimeout_ms)
                {
                    if (theStream.DataAvailable)                       // read if something to do
                    {
                        readBytes += theStream.Read(message, readBytes, toRead - readBytes);
                    }
                    else                         // prevent live-lock
                    {
                        waitTime += 2;
                        System.Threading.Thread.Sleep(2);
                    }
                }
            }
            dst.put(message, 0, readBytes);
            return(readBytes);
        }
コード例 #2
0
ファイル: BufferClient.cs プロジェクト: abzaloid/buffer-bci
        //*********************************************************************
        //		protected methods and variables from here on
        //*********************************************************************

        protected ByteBuffer readAll(ByteBuffer dst)
        {
            int cap = dst.capacity();

            while (cap > 0)
            {
                int now = sockChan.read(dst);
                cap -= now;
            }
            return(dst);
        }
コード例 #3
0
ファイル: SocketChannel.cs プロジェクト: jadref/buffer_bci
        public int read(ByteBuffer dst)
        {
            int toRead = dst.capacity();
             		byte[] message = new byte[toRead];

             		int readBytes = 0;
             		while(readBytes<toRead){
             			readBytes += theStream.Read(message, readBytes, toRead-readBytes);
             		}
             		dst.put(message);
             		return readBytes;
        }
コード例 #4
0
ファイル: SocketChannel.cs プロジェクト: Wieke/buffer_bci
        public int read(ByteBuffer dst)
        {
            int toRead = dst.capacity();
             		byte[] message = new byte[toRead];

             		int readBytes = 0;
             		//while(readBytes<toRead){ // this loop is uncessary -- we return number bytes read anyway...
             			readBytes += theStream.Read(message, readBytes, toRead-readBytes);
             		//}
             		dst.put(message);
             		return readBytes;
        }
コード例 #5
0
ファイル: SocketChannel.cs プロジェクト: giulio93/buffer_bci
        public int read(ByteBuffer dst)
        {
            int toRead = dst.capacity();

            byte[] message = new byte[toRead];

            int readBytes = 0;

            //while(readBytes<toRead){ // this loop is uncessary -- we return number bytes read anyway...
            readBytes += theStream.Read(message, readBytes, toRead - readBytes);
            //}
            dst.put(message);
            return(readBytes);
        }
コード例 #6
0
ファイル: SocketChannel.cs プロジェクト: fbedada991/BCI
        public int read(ByteBuffer dst)
        {
            int toRead = dst.capacity();

            byte[] message = new byte[toRead];

            int readBytes = 0;

            while (readBytes < toRead)
            {
                readBytes += theStream.Read(message, readBytes, toRead - readBytes);
            }
            dst.put(message);
            return(readBytes);
        }
コード例 #7
0
        //*********************************************************************
        //		protected methods and variables from here on
        //*********************************************************************

        protected ByteBuffer readAll(ByteBuffer dst)
        {
            int cap = dst.capacity();
            int now = 0;

            while (cap > 0)
            {
                now = sockChan.read(dst);
                if (now < 0)
                {
                    //System.Console.WriteLine("Read here ");
                    throw new IOException("Remote side closed connection!");
                }
                cap -= now;
            }
            return(dst);
        }
コード例 #8
0
        //*********************************************************************
        //		protected methods and variables from here on
        //*********************************************************************

        protected ByteBuffer readAll(ByteBuffer dst)
        {
            lock (this) {
                // Implement our own read-time-out for when the connection goes down....
                int cap = dst.capacity();
                while (cap > 0 && sockChan.isConnected())
                {
                    int now = sockChan.read(dst);
                    if (now == 0)
                    {
                        return(dst);                        // read failed = abort
                    }
                    cap -= now;
                }
                return(dst);
            }
        }