Java Code Examples for org.apache.tomcat.jni.Socket#send()

The following examples show how to use org.apache.tomcat.jni.Socket#send() . 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: AprSocketSink.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
/**
 * Send incoming data to stream.
 */
@Override
public void handleData(ByteBuffer buf, Link link) {
    if (buf == null)
        return;

    if (socketWrapper.shutdown)
        return;

    try {
        if (verbose)
            System.out.println("[" + this + "] INFO: Writing data to stream: " + buf + ".");

        // FIXME: If pull is destroyed or socket is closed, segfault will happen here
        Socket.send(socket, buf.data, buf.offset, buf.length);
    } catch (Exception e) {
        System.err.println("[" + this + "] ERROR: " + e.getMessage());
        closeStream();
    }
}
 
Example 2
Source File: UpgradeAprProcessor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void write(int b) throws IOException {
    int result = Socket.send(socket, new byte[] {(byte) b}, 0, 1);
    if (result != 1) {
        throw new IOException(sm.getString("apr.write.error",
                Integer.valueOf(-result)));
    }
}
 
Example 3
Source File: UpgradeAprProcessor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void write(byte[]b, int off, int len) throws IOException {
    int result = Socket.send(socket, b, off, len);
    if (result != len) {
        throw new IOException(sm.getString("apr.write.error",
                Integer.valueOf(-result)));
    }
}
 
Example 4
Source File: InternalAprOutputBuffer.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Send an acknowledgment.
 */
@Override
public void sendAck()
    throws IOException {

    if (!committed) {
        if (Socket.send(socket, Constants.ACK_BYTES, 0, Constants.ACK_BYTES.length) < 0)
            throw new IOException(sm.getString("iib.failedwrite"));
    }

}
 
Example 5
Source File: UpgradeAprProcessor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void write(int b) throws IOException {
    int result = Socket.send(socket, new byte[] {(byte) b}, 0, 1);
    if (result != 1) {
        throw new IOException(sm.getString("apr.write.error",
                Integer.valueOf(-result)));
    }
}
 
Example 6
Source File: UpgradeAprProcessor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void write(byte[]b, int off, int len) throws IOException {
    int result = Socket.send(socket, b, off, len);
    if (result != len) {
        throw new IOException(sm.getString("apr.write.error",
                Integer.valueOf(-result)));
    }
}
 
Example 7
Source File: InternalAprOutputBuffer.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Send an acknowledgment.
 */
@Override
public void sendAck()
    throws IOException {

    if (!committed) {
        if (Socket.send(socket, Constants.ACK_BYTES, 0, Constants.ACK_BYTES.length) < 0)
            throw new IOException(sm.getString("iib.failedwrite"));
    }

}
 
Example 8
Source File: AprServletOutputStream.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
private int doWriteInternal(byte[] b, int off, int len) throws IOException {

        int start = off;
        int left = len;
        int written;

        do {
            if (endpoint.isSSLEnabled()) {
                if (sslOutputBuffer.remaining() == 0) {
                    // Buffer was fully written last time around
                    sslOutputBuffer.clear();
                    if (left < SSL_OUTPUT_BUFFER_SIZE) {
                        sslOutputBuffer.put(b, start, left);
                    } else {
                        sslOutputBuffer.put(b, start, SSL_OUTPUT_BUFFER_SIZE);
                    }
                    sslOutputBuffer.flip();
                } else {
                    // Buffer still has data from previous attempt to write
                    // APR + SSL requires that exactly the same parameters are
                    // passed when re-attempting the write
                }
                written = Socket.sendb(socket, sslOutputBuffer,
                        sslOutputBuffer.position(), sslOutputBuffer.limit());
                if (written > 0) {
                    sslOutputBuffer.position(
                            sslOutputBuffer.position() + written);
                }
            } else {
                written = Socket.send(socket, b, start, left);
            }
            if (Status.APR_STATUS_IS_EAGAIN(-written)) {
                written = 0;
            } else if (-written == Status.APR_EOF) {
                throw new EOFException(sm.getString("apr.clientAbort"));
            } else if ((OS.IS_WIN32 || OS.IS_WIN64) &&
                    (-written == Status.APR_OS_START_SYSERR + 10053)) {
                // 10053 on Windows is connection aborted
                throw new EOFException(sm.getString("apr.clientAbort"));
            } else if (written < 0) {
                throw new IOException(sm.getString("apr.write.error",
                        Integer.valueOf(-written), Long.valueOf(socket), wrapper));
            }
            start += written;
            left -= written;
        } while (written > 0 && left > 0);

        if (left > 0) {
            endpoint.getPoller().add(socket, -1, false, true);
        }
        return len - left;
    }
 
Example 9
Source File: AprServletOutputStream.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private int doWriteInternal(byte[] b, int off, int len) throws IOException {

        int start = off;
        int left = len;
        int written;

        do {
            if (endpoint.isSSLEnabled()) {
                if (sslOutputBuffer.remaining() == 0) {
                    // Buffer was fully written last time around
                    sslOutputBuffer.clear();
                    if (left < SSL_OUTPUT_BUFFER_SIZE) {
                        sslOutputBuffer.put(b, start, left);
                    } else {
                        sslOutputBuffer.put(b, start, SSL_OUTPUT_BUFFER_SIZE);
                    }
                    sslOutputBuffer.flip();
                } else {
                    // Buffer still has data from previous attempt to write
                    // APR + SSL requires that exactly the same parameters are
                    // passed when re-attempting the write
                }
                written = Socket.sendb(socket, sslOutputBuffer,
                        sslOutputBuffer.position(), sslOutputBuffer.limit());
                if (written > 0) {
                    sslOutputBuffer.position(
                            sslOutputBuffer.position() + written);
                }
            } else {
                written = Socket.send(socket, b, start, left);
            }
            if (Status.APR_STATUS_IS_EAGAIN(-written)) {
                written = 0;
            } else if (-written == Status.APR_EOF) {
                throw new EOFException(sm.getString("apr.clientAbort"));
            } else if ((OS.IS_WIN32 || OS.IS_WIN64) &&
                    (-written == Status.APR_OS_START_SYSERR + 10053)) {
                // 10053 on Windows is connection aborted
                throw new EOFException(sm.getString("apr.clientAbort"));
            } else if (written < 0) {
                throw new IOException(sm.getString("apr.write.error",
                        Integer.valueOf(-written), Long.valueOf(socket), wrapper));
            }
            start += written;
            left -= written;
        } while (written > 0 && left > 0);

        if (left > 0) {
            endpoint.getPoller().add(socket, -1, false, true);
        }
        return len - left;
    }