KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > jni > Poll


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.tomcat.jni;
19
20 /** Poll
21  *
22  * @author Mladen Turk
23  * @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
24  */

25
26 public class Poll {
27
28     /**
29      * Poll options
30      */

31     public static final int APR_POLLIN = 0x001; /** Can read without blocking */
32     public static final int APR_POLLPRI = 0x002; /** Priority data available */
33     public static final int APR_POLLOUT = 0x004; /** Can write without blocking */
34     public static final int APR_POLLERR = 0x010; /** Pending error */
35     public static final int APR_POLLHUP = 0x020; /** Hangup occurred */
36     public static final int APR_POLLNVAL = 0x040; /** Descriptior invalid */
37
38     /**
39      * Pollset Flags
40      */

41     /** Adding or Removing a Descriptor is thread safe */
42     public static final int APR_POLLSET_THREADSAFE = 0x001;
43
44
45     /** Used in apr_pollfd_t to determine what the apr_descriptor is
46      * apr_datatype_e enum
47      */

48     public static final int APR_NO_DESC = 0; /** nothing here */
49     public static final int APR_POLL_SOCKET = 1; /** descriptor refers to a socket */
50     public static final int APR_POLL_FILE = 2; /** descriptor refers to a file */
51     public static final int APR_POLL_LASTDESC = 3; /** descriptor is the last one in the list */
52
53     /**
54      * Setup a pollset object.
55      * If flags equals APR_POLLSET_THREADSAFE, then a pollset is
56      * created on which it is safe to make concurrent calls to
57      * apr_pollset_add(), apr_pollset_remove() and apr_pollset_poll() from
58      * separate threads. This feature is only supported on some
59      * platforms; the apr_pollset_create() call will fail with
60      * APR_ENOTIMPL on platforms where it is not supported.
61      * @param size The maximum number of descriptors that this pollset can hold
62      * @param p The pool from which to allocate the pollset
63      * @param flags Optional flags to modify the operation of the pollset.
64      * @param ttl Maximum time to live for a particular socket.
65      * @return The pointer in which to return the newly created object
66      */

67     public static native long create(int size, long p, int flags, long ttl)
68         throws Error JavaDoc;
69     /**
70      * Destroy a pollset object
71      * @param pollset The pollset to destroy
72      */

73     public static native int destroy(long pollset);
74
75     /**
76      * Add a socket or to a pollset
77      * If you set client_data in the descriptor, that value
78      * will be returned in the client_data field whenever this
79      * descriptor is signalled in apr_pollset_poll().
80      * @param pollset The pollset to which to add the descriptor
81      * @param sock The sockets to add
82      * @param data Client data to add
83      * @param reqevents requested events
84      */

85     public static native int add(long pollset, long sock,
86                                  int reqevents);
87
88     /**
89      * Remove a descriptor from a pollset
90      * @param pollset The pollset from which to remove the descriptor
91      * @param sock The socket to remove
92      */

93     public static native int remove(long pollset, long sock);
94
95     /**
96      * Block for activity on the descriptor(s) in a pollset
97      * @param pollset The pollset to use
98      * @param timeout Timeout in microseconds
99      * @param descriptors Array of signalled descriptors (output parameter)
100      * The desctiptor array must be two times the size of pollset.
101      * and are populated as follows:
102      * <PRE>
103      * descriptors[n + 0] -> returned events
104      * descriptors[n + 1] -> socket
105      * </PRE>
106      * @param remove Remove signaled descriptors from pollset
107      * @return Number of signalled descriptors (output parameter)
108      * or negative APR error code.
109      */

110     public static native int poll(long pollset, long timeout,
111                                   long [] descriptors, boolean remove);
112
113     /**
114      * Maintain on the descriptor(s) in a pollset
115      * @param pollset The pollset to use
116      * @param descriptors Array of signalled descriptors (output parameter)
117      * The desctiptor array must be the size of pollset.
118      * and are populated as follows:
119      * <PRE>
120      * descriptors[n] -> socket
121      * </PRE>
122      * @param remove Remove signaled descriptors from pollset
123      * @return Number of signalled descriptors (output parameter)
124      * or negative APR error code.
125      */

126     public static native int maintain(long pollset, long [] descriptors,
127                                       boolean remove);
128
129     /**
130      * Set the socket time to live.
131      * @param pollset The pollset to use
132      * @param ttl Timeout in microseconds
133      */

134     public static native void setTtl(long pollset, long ttl);
135
136     /**
137      * Get the socket time to live.
138      * @param pollset The pollset to use
139      * @return Timeout in microseconds
140      */

141     public static native long getTtl(long pollset);
142
143     /**
144      * Return all descriptor(s) in a pollset
145      * @param pollset The pollset to use
146      * @param descriptors Array of descriptors (output parameter)
147      * The desctiptor array must be two times the size of pollset.
148      * and are populated as follows:
149      * <PRE>
150      * descriptors[n + 0] -> returned events
151      * descriptors[n + 1] -> socket
152      * </PRE>
153      * @return Number of descriptors (output parameter) in the Poll
154      * or negative APR error code.
155      */

156     public static native int pollset(long pollset, long [] descriptors);
157
158 }
159
Popular Tags