001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.tomcat.jni;
019:
020: /** Poll
021: *
022: * @author Mladen Turk
023: * @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
024: */
025:
026: public class Poll {
027:
028: /**
029: * Poll options
030: */
031: public static final int APR_POLLIN = 0x001;
032: /** Can read without blocking */
033: public static final int APR_POLLPRI = 0x002;
034: /** Priority data available */
035: public static final int APR_POLLOUT = 0x004;
036: /** Can write without blocking */
037: public static final int APR_POLLERR = 0x010;
038: /** Pending error */
039: public static final int APR_POLLHUP = 0x020;
040: /** Hangup occurred */
041: public static final int APR_POLLNVAL = 0x040;
042: /** Descriptior invalid */
043:
044: /**
045: * Pollset Flags
046: */
047: /** Adding or Removing a Descriptor is thread safe */
048: public static final int APR_POLLSET_THREADSAFE = 0x001;
049:
050: /** Used in apr_pollfd_t to determine what the apr_descriptor is
051: * apr_datatype_e enum
052: */
053: public static final int APR_NO_DESC = 0;
054: /** nothing here */
055: public static final int APR_POLL_SOCKET = 1;
056: /** descriptor refers to a socket */
057: public static final int APR_POLL_FILE = 2;
058: /** descriptor refers to a file */
059: public static final int APR_POLL_LASTDESC = 3;
060:
061: /** descriptor is the last one in the list */
062:
063: /**
064: * Setup a pollset object.
065: * If flags equals APR_POLLSET_THREADSAFE, then a pollset is
066: * created on which it is safe to make concurrent calls to
067: * apr_pollset_add(), apr_pollset_remove() and apr_pollset_poll() from
068: * separate threads. This feature is only supported on some
069: * platforms; the apr_pollset_create() call will fail with
070: * APR_ENOTIMPL on platforms where it is not supported.
071: * @param size The maximum number of descriptors that this pollset can hold
072: * @param p The pool from which to allocate the pollset
073: * @param flags Optional flags to modify the operation of the pollset.
074: * @param ttl Maximum time to live for a particular socket.
075: * @return The pointer in which to return the newly created object
076: */
077: public static native long create(int size, long p, int flags,
078: long ttl) throws Error;
079:
080: /**
081: * Destroy a pollset object
082: * @param pollset The pollset to destroy
083: */
084: public static native int destroy(long pollset);
085:
086: /**
087: * Add a socket or to a pollset
088: * If you set client_data in the descriptor, that value
089: * will be returned in the client_data field whenever this
090: * descriptor is signalled in apr_pollset_poll().
091: * @param pollset The pollset to which to add the descriptor
092: * @param sock The sockets to add
093: * @param data Client data to add
094: * @param reqevents requested events
095: */
096: public static native int add(long pollset, long sock, int reqevents);
097:
098: /**
099: * Remove a descriptor from a pollset
100: * @param pollset The pollset from which to remove the descriptor
101: * @param sock The socket to remove
102: */
103: public static native int remove(long pollset, long sock);
104:
105: /**
106: * Block for activity on the descriptor(s) in a pollset
107: * @param pollset The pollset to use
108: * @param timeout Timeout in microseconds
109: * @param descriptors Array of signalled descriptors (output parameter)
110: * The desctiptor array must be two times the size of pollset.
111: * and are populated as follows:
112: * <PRE>
113: * descriptors[n + 0] -> returned events
114: * descriptors[n + 1] -> socket
115: * </PRE>
116: * @param remove Remove signaled descriptors from pollset
117: * @return Number of signalled descriptors (output parameter)
118: * or negative APR error code.
119: */
120: public static native int poll(long pollset, long timeout,
121: long[] descriptors, boolean remove);
122:
123: /**
124: * Maintain on the descriptor(s) in a pollset
125: * @param pollset The pollset to use
126: * @param descriptors Array of signalled descriptors (output parameter)
127: * The desctiptor array must be the size of pollset.
128: * and are populated as follows:
129: * <PRE>
130: * descriptors[n] -> socket
131: * </PRE>
132: * @param remove Remove signaled descriptors from pollset
133: * @return Number of signalled descriptors (output parameter)
134: * or negative APR error code.
135: */
136: public static native int maintain(long pollset, long[] descriptors,
137: boolean remove);
138:
139: /**
140: * Set the socket time to live.
141: * @param pollset The pollset to use
142: * @param ttl Timeout in microseconds
143: */
144: public static native void setTtl(long pollset, long ttl);
145:
146: /**
147: * Get the socket time to live.
148: * @param pollset The pollset to use
149: * @return Timeout in microseconds
150: */
151: public static native long getTtl(long pollset);
152:
153: /**
154: * Return all descriptor(s) in a pollset
155: * @param pollset The pollset to use
156: * @param descriptors Array of descriptors (output parameter)
157: * The desctiptor array must be two times the size of pollset.
158: * and are populated as follows:
159: * <PRE>
160: * descriptors[n + 0] -> returned events
161: * descriptors[n + 1] -> socket
162: * </PRE>
163: * @return Number of descriptors (output parameter) in the Poll
164: * or negative APR error code.
165: */
166: public static native int pollset(long pollset, long[] descriptors);
167:
168: }
|