Java Code Examples for sun.misc.IoTrace#socketWriteEnd()

The following examples show how to use sun.misc.IoTrace#socketWriteEnd() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SocketOutputStream.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Writes to the socket with appropriate locking of the
 * FileDescriptor.
 * @param b the data to be written
 * @param off the start offset in the data
 * @param len the number of bytes that are written
 * @exception IOException If an I/O error has occurred.
 */
private void socketWrite(byte b[], int off, int len) throws IOException {

    if (len <= 0 || off < 0 || off + len > b.length) {
        if (len == 0) {
            return;
        }
        throw new ArrayIndexOutOfBoundsException();
    }

    Object traceContext = IoTrace.socketWriteBegin();
    int bytesWritten = 0;
    FileDescriptor fd = impl.acquireFD();
    try {
        socketWrite0(fd, b, off, len);
        bytesWritten = len;
    } catch (SocketException se) {
        if (se instanceof sun.net.ConnectionResetException) {
            impl.setConnectionResetPending();
            se = new SocketException("Connection reset");
        }
        if (impl.isClosedOrPending()) {
            throw new SocketException("Socket closed");
        } else {
            throw se;
        }
    } finally {
        impl.releaseFD();
        IoTrace.socketWriteEnd(traceContext, impl.address, impl.port, bytesWritten);
    }
}
 
Example 2
Source File: SocketOutputStream.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Writes to the socket with appropriate locking of the
 * FileDescriptor.
 * @param b the data to be written
 * @param off the start offset in the data
 * @param len the number of bytes that are written
 * @exception IOException If an I/O error has occurred.
 */
private void socketWrite(byte b[], int off, int len) throws IOException {

    if (len <= 0 || off < 0 || off + len > b.length) {
        if (len == 0) {
            return;
        }
        throw new ArrayIndexOutOfBoundsException();
    }

    Object traceContext = IoTrace.socketWriteBegin();
    int bytesWritten = 0;
    FileDescriptor fd = impl.acquireFD();
    try {
        BlockGuard.getThreadPolicy().onNetwork();
        socketWrite0(fd, b, off, len);
        bytesWritten = len;
    } catch (SocketException se) {
        if (se instanceof sun.net.ConnectionResetException) {
            impl.setConnectionResetPending();
            se = new SocketException("Connection reset");
        }
        if (impl.isClosedOrPending()) {
            throw new SocketException("Socket closed");
        } else {
            throw se;
        }
    } finally {
        IoTrace.socketWriteEnd(traceContext, impl.address, impl.port, bytesWritten);
    }
}