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); }
//********************************************************************* // 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); }
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; }
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; }
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); }
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); }
//********************************************************************* // 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); }
//********************************************************************* // 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); } }