Java Code Examples for org.apache.tomcat.jni.OS#IS_WIN64

The following examples show how to use org.apache.tomcat.jni.OS#IS_WIN64 . 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 Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Create the sendfile poller. With some versions of APR, the maximum
 * poller size will be 62 (recompiling APR is necessary to remove this
 * limitation).
 */
protected void init() {
    pool = Pool.create(serverSockPool);
    int size = sendfileSize;
    if (size <= 0) {
        size = (OS.IS_WIN32 || OS.IS_WIN64) ? (1 * 1024) : (16 * 1024);
    }
    sendfilePollset = allocatePoller(size, pool, getSoTimeout());
    if (sendfilePollset == 0 && size > 1024) {
        size = 1024;
        sendfilePollset = allocatePoller(size, pool, getSoTimeout());
    }
    if (sendfilePollset == 0) {
        size = 62;
        sendfilePollset = allocatePoller(size, pool, getSoTimeout());
    }
    desc = new long[size * 2];
    sendfileData = new HashMap<Long, SendfileData>(size);
    addS = new ArrayList<SendfileData>();
}
 
Example 2
Source File: AprEndpoint.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Create the sendfile poller. With some versions of APR, the maximum
 * poller size will be 62 (recompiling APR is necessary to remove this
 * limitation).
 */
protected void init() {
    pool = Pool.create(serverSockPool);
    int size = sendfileSize;
    if (size <= 0) {
        size = (OS.IS_WIN32 || OS.IS_WIN64) ? (1 * 1024) : (16 * 1024);
    }
    sendfilePollset = allocatePoller(size, pool, getSoTimeout());
    if (sendfilePollset == 0 && size > 1024) {
        size = 1024;
        sendfilePollset = allocatePoller(size, pool, getSoTimeout());
    }
    if (sendfilePollset == 0) {
        size = 62;
        sendfilePollset = allocatePoller(size, pool, getSoTimeout());
    }
    desc = new long[size * 2];
    sendfileData = new HashMap<Long, SendfileData>(size);
    addS = new ArrayList<SendfileData>();
}
 
Example 3
Source File: AprEndpoint.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Create the poller. With some versions of APR, the maximum poller size
 * will be 62 (recompiling APR is necessary to remove this limitation).
 */
protected synchronized void init() {

    pool = Pool.create(serverSockPool);

    // Single poller by default
    int defaultPollerSize = getMaxConnections();

    if ((OS.IS_WIN32 || OS.IS_WIN64) && (defaultPollerSize > 1024)) {
        // The maximum per poller to get reasonable performance is 1024
        // Adjust poller size so that it won't reach the limit. This is
        // a limitation of XP / Server 2003 that has been fixed in
        // Vista / Server 2008 onwards.
        actualPollerSize = 1024;
    } else {
        actualPollerSize = defaultPollerSize;
    }

    timeouts = new SocketTimeouts(defaultPollerSize);

    // At the moment, setting the timeout is useless, but it could get
    // used again as the normal poller could be faster using maintain.
    // It might not be worth bothering though.
    long pollset = allocatePoller(actualPollerSize, pool, -1);
    if (pollset == 0 && actualPollerSize > 1024) {
        actualPollerSize = 1024;
        pollset = allocatePoller(actualPollerSize, pool, -1);
    }
    if (pollset == 0) {
        actualPollerSize = 62;
        pollset = allocatePoller(actualPollerSize, pool, -1);
    }

    pollerCount = defaultPollerSize / actualPollerSize;
    pollerTime = pollTime / pollerCount;
    nextPollerTime = pollerTime;

    pollers = new long[pollerCount];
    pollers[0] = pollset;
    for (int i = 1; i < pollerCount; i++) {
        pollers[i] = allocatePoller(actualPollerSize, pool, -1);
    }

    pollerSpace = new int[pollerCount];
    for (int i = 0; i < pollerCount; i++) {
        pollerSpace[i] = actualPollerSize;
    }

    /*
     * x2 - One descriptor for the socket, one for the event(s).
     * x2 - Some APR implementations return multiple events for the
     *      same socket as different entries. Each socket is registered
     *      for a maximum of two events (read and write) at any one
     *      time.
     *
     * Therefore size is actual poller size *4.
     */
    desc = new long[actualPollerSize * 4];
    connectionCount.set(0);
    addList = new SocketList(defaultPollerSize);
    closeList = new SocketList(defaultPollerSize);
}
 
Example 4
Source File: AprEndpoint.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private int fillReadBuffer(boolean block, ByteBuffer to) throws IOException {
    if (closed) {
        throw new IOException(sm.getString("socket.apr.closed", getSocket()));
    }

    Lock readLock = getBlockingStatusReadLock();
    WriteLock writeLock = getBlockingStatusWriteLock();

    boolean readDone = false;
    int result = 0;
    readLock.lock();
    try {
        if (getBlockingStatus() == block) {
            if (block) {
                Socket.timeoutSet(getSocket().longValue(), getReadTimeout() * 1000);
            }
            result = Socket.recvb(getSocket().longValue(), to, to.position(),
                    to.remaining());
            readDone = true;
        }
    } finally {
        readLock.unlock();
    }

    if (!readDone) {
        writeLock.lock();
        try {
            // Set the current settings for this socket
            setBlockingStatus(block);
            if (block) {
                Socket.timeoutSet(getSocket().longValue(), getReadTimeout() * 1000);
            } else {
                Socket.timeoutSet(getSocket().longValue(), 0);
            }
            // Downgrade the lock
            readLock.lock();
            try {
                writeLock.unlock();
                result = Socket.recvb(getSocket().longValue(), to, to.position(),
                        to.remaining());
            } finally {
                readLock.unlock();
            }
        } finally {
            // Should have been released above but may not have been on some
            // exception paths
            if (writeLock.isHeldByCurrentThread()) {
                writeLock.unlock();
            }
        }
    }

    if (result > 0) {
        to.position(to.position() + result);
        return result;
    } else if (result == 0 || -result == Status.EAGAIN) {
        return 0;
    } else if ((-result) == Status.ETIMEDOUT || (-result) == Status.TIMEUP) {
        if (block) {
            throw new SocketTimeoutException(sm.getString("iib.readtimeout"));
        } else {
            // Attempting to read from the socket when the poller
            // has not signalled that there is data to read appears
            // to behave like a blocking read with a short timeout
            // on OSX rather than like a non-blocking read. If no
            // data is read, treat the resulting timeout like a
            // non-blocking read that returned no data.
            return 0;
        }
    } else if (-result == Status.APR_EOF) {
        return -1;
    } else if ((OS.IS_WIN32 || OS.IS_WIN64) &&
            (-result == Status.APR_OS_START_SYSERR + 10053)) {
        // 10053 on Windows is connection aborted
        throw new EOFException(sm.getString("socket.apr.clientAbort"));
    } else {
        throw new IOException(sm.getString("socket.apr.read.error",
                Integer.valueOf(-result), getSocket(), this));
    }
}
 
Example 5
Source File: AprEndpoint.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private void doWriteInternal(ByteBuffer from) throws IOException {
    int thisTime;

    do {
        thisTime = 0;
        if (getEndpoint().isSSLEnabled()) {
            if (sslOutputBuffer.remaining() == 0) {
                // Buffer was fully written last time around
                sslOutputBuffer.clear();
                transfer(from, sslOutputBuffer);
                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
            }
            thisTime = Socket.sendb(getSocket().longValue(), sslOutputBuffer,
                    sslOutputBuffer.position(), sslOutputBuffer.limit());
            if (thisTime > 0) {
                sslOutputBuffer.position(sslOutputBuffer.position() + thisTime);
            }
        } else {
            thisTime = Socket.sendb(getSocket().longValue(), from, from.position(),
                    from.remaining());
            if (thisTime > 0) {
                from.position(from.position() + thisTime);
            }
        }
        if (Status.APR_STATUS_IS_EAGAIN(-thisTime)) {
            thisTime = 0;
        } else if (-thisTime == Status.APR_EOF) {
            throw new EOFException(sm.getString("socket.apr.clientAbort"));
        } else if ((OS.IS_WIN32 || OS.IS_WIN64) &&
                (-thisTime == Status.APR_OS_START_SYSERR + 10053)) {
            // 10053 on Windows is connection aborted
            throw new EOFException(sm.getString("socket.apr.clientAbort"));
        } else if (thisTime < 0) {
            throw new IOException(sm.getString("socket.apr.write.error",
                    Integer.valueOf(-thisTime), getSocket(), this));
        }
    } while ((thisTime > 0 || getBlockingStatus()) && from.hasRemaining());

    // If there is data left in the buffer the socket will be registered for
    // write further up the stack. This is to ensure the socket is only
    // registered for write once as both container and user code can trigger
    // write registration.
}
 
Example 6
Source File: TestXxxEndpoint.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
private long createAprSocket(int port, long pool)
             throws Exception {
    /**
     * Server socket "pointer".
     */
    long serverSock = 0;

    String address = InetAddress.getByName("localhost").getHostAddress();

    // Create the APR address that will be bound
    int family = Socket.APR_INET;
    if (Library.APR_HAVE_IPV6) {
        if (!OS.IS_BSD && !OS.IS_WIN32 && !OS.IS_WIN64)
            family = Socket.APR_UNSPEC;
     }

    long inetAddress = 0;
    try {
        inetAddress = Address.info(address, family,
                                   port, 0, pool);
        // Create the APR server socket
        serverSock = Socket.create(Address.getInfo(inetAddress).family,
                                   Socket.SOCK_STREAM,
                                   Socket.APR_PROTO_TCP, pool);
    } catch (Exception ex) {
        log.error("Could not create socket for address '" + address + "'");
        return 0;
    }

    if (OS.IS_UNIX) {
        Socket.optSet(serverSock, Socket.APR_SO_REUSEADDR, 1);
    }
    // Deal with the firewalls that tend to drop the inactive sockets
    Socket.optSet(serverSock, Socket.APR_SO_KEEPALIVE, 1);
    // Bind the server socket
    int ret = Socket.bind(serverSock, inetAddress);
    if (ret != 0) {
        log.error("Could not bind: " + Error.strerror(ret));
        throw (new Exception(Error.strerror(ret)));
    }
    return serverSock;
}
 
Example 7
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 8
Source File: AprServletInputStream.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
protected int doRead(boolean block, byte[] b, int off, int len)
        throws IOException {

    if (closed) {
        throw new IOException(sm.getString("apr.closed", Long.valueOf(socket)));
    }

    Lock readLock = wrapper.getBlockingStatusReadLock();
    WriteLock writeLock = wrapper.getBlockingStatusWriteLock();

    boolean readDone = false;
    int result = 0;
    try {
        readLock.lock();
        if (wrapper.getBlockingStatus() == block) {
            result = Socket.recv(socket, b, off, len);
            readDone = true;
        }
    } finally {
        readLock.unlock();
    }

    if (!readDone) {
        try {
            writeLock.lock();
            wrapper.setBlockingStatus(block);
            // Set the current settings for this socket
            Socket.optSet(socket, Socket.APR_SO_NONBLOCK, (block ? 0 : 1));
            // Downgrade the lock
            try {
                readLock.lock();
                writeLock.unlock();
                result = Socket.recv(socket, b, off, len);
            } finally {
                readLock.unlock();
            }
        } finally {
            // Should have been released above but may not have been on some
            // exception paths
            if (writeLock.isHeldByCurrentThread()) {
                writeLock.unlock();
            }
        }
    }

    if (result > 0) {
        eagain = false;
        return result;
    } else if (-result == Status.EAGAIN) {
        eagain = true;
        return 0;
    } else if (-result == Status.APR_EGENERAL && wrapper.isSecure()) {
        // Not entirely sure why this is necessary. Testing to date has not
        // identified any issues with this but log it so it can be tracked
        // if it is suspected of causing issues in the future.
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("apr.read.sslGeneralError",
                    Long.valueOf(socket), wrapper));
        }
        eagain = true;
        return 0;
    } else if (-result == Status.APR_EOF) {
        throw new EOFException(sm.getString("apr.clientAbort"));
    } else if ((OS.IS_WIN32 || OS.IS_WIN64) &&
            (-result == Status.APR_OS_START_SYSERR + 10053)) {
        // 10053 on Windows is connection aborted
        throw new EOFException(sm.getString("apr.clientAbort"));
    } else {
        throw new IOException(sm.getString("apr.read.error",
                Integer.valueOf(-result), Long.valueOf(socket), wrapper));
    }
}
 
Example 9
Source File: AprEndpoint.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Create the poller. With some versions of APR, the maximum poller size
 * will be 62 (recompiling APR is necessary to remove this limitation).
 */
protected void init() {

    pool = Pool.create(serverSockPool);

    // Single poller by default
    int defaultPollerSize = getMaxConnections();

    if ((OS.IS_WIN32 || OS.IS_WIN64) && (defaultPollerSize > 1024)) {
        // The maximum per poller to get reasonable performance is 1024
        // Adjust poller size so that it won't reach the limit. This is
        // a limitation of XP / Server 2003 that has been fixed in
        // Vista / Server 2008 onwards.
        actualPollerSize = 1024;
    } else {
        actualPollerSize = defaultPollerSize;
    }

    timeouts = new SocketTimeouts(defaultPollerSize);

    // At the moment, setting the timeout is useless, but it could get
    // used again as the normal poller could be faster using maintain.
    // It might not be worth bothering though.
    long pollset = allocatePoller(actualPollerSize, pool, -1);
    if (pollset == 0 && actualPollerSize > 1024) {
        actualPollerSize = 1024;
        pollset = allocatePoller(actualPollerSize, pool, -1);
    }
    if (pollset == 0) {
        actualPollerSize = 62;
        pollset = allocatePoller(actualPollerSize, pool, -1);
    }

    pollerCount = defaultPollerSize / actualPollerSize;
    pollerTime = pollTime / pollerCount;
    nextPollerTime = pollerTime;

    pollers = new long[pollerCount];
    pollers[0] = pollset;
    for (int i = 1; i < pollerCount; i++) {
        pollers[i] = allocatePoller(actualPollerSize, pool, -1);
    }

    pollerSpace = new int[pollerCount];
    for (int i = 0; i < pollerCount; i++) {
        pollerSpace[i] = actualPollerSize;
    }

    desc = new long[actualPollerSize * 2];
    connectionCount.set(0);
    addList = new SocketList(defaultPollerSize);
    closeList = new SocketList(defaultPollerSize);
}
 
Example 10
Source File: TestXxxEndpoint.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
private long createAprSocket(int port, long pool)
             throws Exception {
    /**
     * Server socket "pointer".
     */
    long serverSock = 0;

    String address = InetAddress.getByName("localhost").getHostAddress();

    // Create the APR address that will be bound
    int family = Socket.APR_INET;
    if (Library.APR_HAVE_IPV6) {
        if (!OS.IS_BSD && !OS.IS_WIN32 && !OS.IS_WIN64)
            family = Socket.APR_UNSPEC;
     }

    long inetAddress = 0;
    try {
        inetAddress = Address.info(address, family,
                                   port, 0, pool);
        // Create the APR server socket
        serverSock = Socket.create(Address.getInfo(inetAddress).family,
                                   Socket.SOCK_STREAM,
                                   Socket.APR_PROTO_TCP, pool);
    } catch (Exception ex) {
        log.error("Could not create socket for address '" + address + "'");
        return 0;
    }

    if (OS.IS_UNIX) {
        Socket.optSet(serverSock, Socket.APR_SO_REUSEADDR, 1);
    }
    // Deal with the firewalls that tend to drop the inactive sockets
    Socket.optSet(serverSock, Socket.APR_SO_KEEPALIVE, 1);
    // Bind the server socket
    int ret = Socket.bind(serverSock, inetAddress);
    if (ret != 0) {
        log.error("Could not bind: " + Error.strerror(ret));
        throw (new Exception(Error.strerror(ret)));
    }
    return serverSock;
}
 
Example 11
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;
    }
 
Example 12
Source File: AprServletInputStream.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
protected int doRead(boolean block, byte[] b, int off, int len)
        throws IOException {

    if (closed) {
        throw new IOException(sm.getString("apr.closed", Long.valueOf(socket)));
    }

    Lock readLock = wrapper.getBlockingStatusReadLock();
    WriteLock writeLock = wrapper.getBlockingStatusWriteLock();

    boolean readDone = false;
    int result = 0;
    try {
        readLock.lock();
        if (wrapper.getBlockingStatus() == block) {
            result = Socket.recv(socket, b, off, len);
            readDone = true;
        }
    } finally {
        readLock.unlock();
    }

    if (!readDone) {
        try {
            writeLock.lock();
            wrapper.setBlockingStatus(block);
            // Set the current settings for this socket
            Socket.optSet(socket, Socket.APR_SO_NONBLOCK, (block ? 0 : 1));
            // Downgrade the lock
            try {
                readLock.lock();
                writeLock.unlock();
                result = Socket.recv(socket, b, off, len);
            } finally {
                readLock.unlock();
            }
        } finally {
            // Should have been released above but may not have been on some
            // exception paths
            if (writeLock.isHeldByCurrentThread()) {
                writeLock.unlock();
            }
        }
    }

    if (result > 0) {
        eagain = false;
        return result;
    } else if (-result == Status.EAGAIN) {
        eagain = true;
        return 0;
    } else if (-result == Status.APR_EGENERAL && wrapper.isSecure()) {
        // Not entirely sure why this is necessary. Testing to date has not
        // identified any issues with this but log it so it can be tracked
        // if it is suspected of causing issues in the future.
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("apr.read.sslGeneralError",
                    Long.valueOf(socket), wrapper));
        }
        eagain = true;
        return 0;
    } else if (-result == Status.APR_EOF) {
        throw new EOFException(sm.getString("apr.clientAbort"));
    } else if ((OS.IS_WIN32 || OS.IS_WIN64) &&
            (-result == Status.APR_OS_START_SYSERR + 10053)) {
        // 10053 on Windows is connection aborted
        throw new EOFException(sm.getString("apr.clientAbort"));
    } else {
        throw new IOException(sm.getString("apr.read.error",
                Integer.valueOf(-result), Long.valueOf(socket), wrapper));
    }
}
 
Example 13
Source File: AprEndpoint.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Create the poller. With some versions of APR, the maximum poller size
 * will be 62 (recompiling APR is necessary to remove this limitation).
 */
protected void init() {

    pool = Pool.create(serverSockPool);

    // Single poller by default
    int defaultPollerSize = getMaxConnections();

    if ((OS.IS_WIN32 || OS.IS_WIN64) && (defaultPollerSize > 1024)) {
        // The maximum per poller to get reasonable performance is 1024
        // Adjust poller size so that it won't reach the limit. This is
        // a limitation of XP / Server 2003 that has been fixed in
        // Vista / Server 2008 onwards.
        actualPollerSize = 1024;
    } else {
        actualPollerSize = defaultPollerSize;
    }

    timeouts = new SocketTimeouts(defaultPollerSize);

    // At the moment, setting the timeout is useless, but it could get
    // used again as the normal poller could be faster using maintain.
    // It might not be worth bothering though.
    long pollset = allocatePoller(actualPollerSize, pool, -1);
    if (pollset == 0 && actualPollerSize > 1024) {
        actualPollerSize = 1024;
        pollset = allocatePoller(actualPollerSize, pool, -1);
    }
    if (pollset == 0) {
        actualPollerSize = 62;
        pollset = allocatePoller(actualPollerSize, pool, -1);
    }

    pollerCount = defaultPollerSize / actualPollerSize;
    pollerTime = pollTime / pollerCount;
    nextPollerTime = pollerTime;

    pollers = new long[pollerCount];
    pollers[0] = pollset;
    for (int i = 1; i < pollerCount; i++) {
        pollers[i] = allocatePoller(actualPollerSize, pool, -1);
    }

    pollerSpace = new int[pollerCount];
    for (int i = 0; i < pollerCount; i++) {
        pollerSpace[i] = actualPollerSize;
    }

    desc = new long[actualPollerSize * 2];
    connectionCount.set(0);
    addList = new SocketList(defaultPollerSize);
    closeList = new SocketList(defaultPollerSize);
}
 
Example 14
Source File: TestXxxEndpoint.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private long createAprSocket(int port, long pool)
             throws Exception {
    /**
     * Server socket "pointer".
     */
    long serverSock = 0;

    String address = InetAddress.getByName("localhost").getHostAddress();

    // Create the APR address that will be bound
    int family = Socket.APR_INET;
    if (Library.APR_HAVE_IPV6) {
        if (!OS.IS_BSD && !OS.IS_WIN32 && !OS.IS_WIN64)
            family = Socket.APR_UNSPEC;
     }

    long inetAddress = 0;
    try {
        inetAddress = Address.info(address, family,
                                   port, 0, pool);
        // Create the APR server socket
        serverSock = Socket.create(Address.getInfo(inetAddress).family,
                                   Socket.SOCK_STREAM,
                                   Socket.APR_PROTO_TCP, pool);
    } catch (Exception ex) {
        log.error("Could not create socket for address '" + address + "'");
        return 0;
    }

    if (OS.IS_UNIX) {
        Socket.optSet(serverSock, Socket.APR_SO_REUSEADDR, 1);
    }
    // Deal with the firewalls that tend to drop the inactive sockets
    Socket.optSet(serverSock, Socket.APR_SO_KEEPALIVE, 1);
    // Bind the server socket
    int ret = Socket.bind(serverSock, inetAddress);
    if (ret != 0) {
        log.error("Could not bind: " + Error.strerror(ret));
        throw (new Exception(Error.strerror(ret)));
    }
    return serverSock;
}