org.apache.tomcat.jni.File Java Examples

The following examples show how to use org.apache.tomcat.jni.File. 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: AprEndpoint.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Add the sendfile data to the sendfile poller. Note that in most cases,
 * the initial non blocking calls to sendfile will return right away, and
 * will be handled asynchronously inside the kernel. As a result,
 * the poller will never be used.
 *
 * @param data containing the reference to the data which should be snet
 * @return true if all the data has been sent right away, and false
 *              otherwise
 */
public SendfileState add(SendfileData data) {
    // Initialize fd from data given
    try {
        data.fdpool = Socket.pool(data.socket);
        data.fd = File.open
            (data.fileName, File.APR_FOPEN_READ
             | File.APR_FOPEN_SENDFILE_ENABLED | File.APR_FOPEN_BINARY,
             0, data.fdpool);
        // Set the socket to nonblocking mode
        Socket.timeoutSet(data.socket, 0);
        while (sendfileRunning) {
            long nw = Socket.sendfilen(data.socket, data.fd,
                                       data.pos, data.length, 0);
            if (nw < 0) {
                if (!(-nw == Status.EAGAIN)) {
                    Pool.destroy(data.fdpool);
                    data.socket = 0;
                    return SendfileState.ERROR;
                } else {
                    // Break the loop and add the socket to poller.
                    break;
                }
            } else {
                data.pos += nw;
                data.length -= nw;
                if (data.length == 0) {
                    // Entire file has been sent
                    Pool.destroy(data.fdpool);
                    // Set back socket to blocking mode
                    Socket.timeoutSet(data.socket, getConnectionTimeout() * 1000);
                    return SendfileState.DONE;
                }
            }
        }
    } catch (Exception e) {
        log.warn(sm.getString("endpoint.sendfile.error"), e);
        return SendfileState.ERROR;
    }
    // Add socket to the list. Newly added sockets will wait
    // at most for pollTime before being polled
    synchronized (this) {
        addS.add(data);
        this.notify();
    }
    return SendfileState.PENDING;
}
 
Example #2
Source File: AprEndpoint.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Add the sendfile data to the sendfile poller. Note that in most cases,
 * the initial non blocking calls to sendfile will return right away, and
 * will be handled asynchronously inside the kernel. As a result,
 * the poller will never be used.
 *
 * @param data containing the reference to the data which should be snet
 * @return true if all the data has been sent right away, and false
 *              otherwise
 */
public boolean add(SendfileData data) {
    // Initialize fd from data given
    try {
        data.fdpool = Socket.pool(data.socket);
        data.fd = File.open
            (data.fileName, File.APR_FOPEN_READ
             | File.APR_FOPEN_SENDFILE_ENABLED | File.APR_FOPEN_BINARY,
             0, data.fdpool);
        data.pos = data.start;
        // Set the socket to nonblocking mode
        Socket.timeoutSet(data.socket, 0);
        while (true) {
            long nw = Socket.sendfilen(data.socket, data.fd,
                                       data.pos, data.end - data.pos, 0);
            if (nw < 0) {
                if (!(-nw == Status.EAGAIN)) {
                    Pool.destroy(data.fdpool);
                    data.socket = 0;
                    return false;
                } else {
                    // Break the loop and add the socket to poller.
                    break;
                }
            } else {
                data.pos = data.pos + nw;
                if (data.pos >= data.end) {
                    // Entire file has been sent
                    Pool.destroy(data.fdpool);
                    // Set back socket to blocking mode
                    Socket.timeoutSet(
                            data.socket, getSoTimeout() * 1000);
                    return true;
                }
            }
        }
    } catch (Exception e) {
        log.warn(sm.getString("endpoint.sendfile.error"), e);
        return false;
    }
    // Add socket to the list. Newly added sockets will wait
    // at most for pollTime before being polled
    synchronized (this) {
        addS.add(data);
        this.notify();
    }
    return false;
}
 
Example #3
Source File: AprEndpoint.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Add the sendfile data to the sendfile poller. Note that in most cases,
 * the initial non blocking calls to sendfile will return right away, and
 * will be handled asynchronously inside the kernel. As a result,
 * the poller will never be used.
 *
 * @param data containing the reference to the data which should be snet
 * @return true if all the data has been sent right away, and false
 *              otherwise
 */
public boolean add(SendfileData data) {
    // Initialize fd from data given
    try {
        data.fdpool = Socket.pool(data.socket);
        data.fd = File.open
            (data.fileName, File.APR_FOPEN_READ
             | File.APR_FOPEN_SENDFILE_ENABLED | File.APR_FOPEN_BINARY,
             0, data.fdpool);
        data.pos = data.start;
        // Set the socket to nonblocking mode
        Socket.timeoutSet(data.socket, 0);
        while (true) {
            long nw = Socket.sendfilen(data.socket, data.fd,
                                       data.pos, data.end - data.pos, 0);
            if (nw < 0) {
                if (!(-nw == Status.EAGAIN)) {
                    Pool.destroy(data.fdpool);
                    data.socket = 0;
                    return false;
                } else {
                    // Break the loop and add the socket to poller.
                    break;
                }
            } else {
                data.pos = data.pos + nw;
                if (data.pos >= data.end) {
                    // Entire file has been sent
                    Pool.destroy(data.fdpool);
                    // Set back socket to blocking mode
                    Socket.timeoutSet(
                            data.socket, getSoTimeout() * 1000);
                    return true;
                }
            }
        }
    } catch (Exception e) {
        log.warn(sm.getString("endpoint.sendfile.error"), e);
        return false;
    }
    // Add socket to the list. Newly added sockets will wait
    // at most for pollTime before being polled
    synchronized (this) {
        addS.add(data);
        this.notify();
    }
    return false;
}