/// <summary> /// Writes to the socket with appropriate locking of the /// FileDescriptor. </summary> /// <param name="b"> the data to be written </param> /// <param name="off"> the start offset in the data </param> /// <param name="len"> the number of bytes that are written </param> /// <exception cref="IOException"> If an I/O error has occurred. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void socketWrite(byte b[] , int off, int len) throws java.io.IOException private void SocketWrite(sbyte[] b, int off, int len) { if (len <= 0 || off < 0 || off + len > b.Length) { if (len == 0) { return; } throw new ArrayIndexOutOfBoundsException(); } FileDescriptor fd = Impl.AcquireFD(); try { socketWrite0(fd, b, off, len); } catch (SocketException se) { if (se is sun.net.ConnectionResetException) { Impl.SetConnectionResetPending(); se = new SocketException("Connection reset"); } if (Impl.ClosedOrPending) { throw new SocketException("Socket closed"); } else { throw se; } } finally { Impl.ReleaseFD(); } }
internal override FileDescriptor AcquireFD() { return(Impl.AcquireFD()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: int read(byte b[] , int off, int length, int timeout) throws java.io.IOException internal virtual int Read(sbyte[] b, int off, int length, int timeout) { int n; // EOF already encountered if (Eof) { return(-1); } // connection reset if (Impl.ConnectionReset) { throw new SocketException("Connection reset"); } // bounds check if (length <= 0 || off < 0 || off + length > b.Length) { if (length == 0) { return(0); } throw new ArrayIndexOutOfBoundsException(); } bool gotReset = false; // acquire file descriptor and do the read FileDescriptor fd = Impl.AcquireFD(); try { n = SocketRead(fd, b, off, length, timeout); if (n > 0) { return(n); } } catch (ConnectionResetException) { gotReset = true; } finally { Impl.ReleaseFD(); } /* * We receive a "connection reset" but there may be bytes still * buffered on the socket */ if (gotReset) { Impl.SetConnectionResetPending(); Impl.AcquireFD(); try { n = SocketRead(fd, b, off, length, timeout); if (n > 0) { return(n); } } catch (ConnectionResetException) { } finally { Impl.ReleaseFD(); } } /* * If we get here we are at EOF, the socket has been closed, * or the connection has been reset. */ if (Impl.ClosedOrPending) { throw new SocketException("Socket closed"); } if (Impl.ConnectionResetPending) { Impl.SetConnectionReset(); } if (Impl.ConnectionReset) { throw new SocketException("Connection reset"); } Eof = true; return(-1); }