private int Read(ByteBuffer buf) { Debug.Assert(_fd != null); if (AssemblyUtil.IsMono) { // // Mono on Android and iOS 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); } 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); }