OLD | NEW |
| (Empty) |
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 package org.apache.tomcat.jni; | |
18 | |
19 /** Poll | |
20 * | |
21 * @author Mladen Turk | |
22 */ | |
23 public class Poll { | |
24 | |
25 /** | |
26 * Poll return values | |
27 */ | |
28 /** Can read without blocking */ | |
29 public static final int APR_POLLIN = 0x001; | |
30 /** Priority data available */ | |
31 public static final int APR_POLLPRI = 0x002; | |
32 /** Can write without blocking */ | |
33 public static final int APR_POLLOUT = 0x004; | |
34 /** Pending error */ | |
35 public static final int APR_POLLERR = 0x010; | |
36 /** Hangup occurred */ | |
37 public static final int APR_POLLHUP = 0x020; | |
38 /** Descriptor invalid */ | |
39 public static final int APR_POLLNVAL = 0x040; | |
40 | |
41 /** | |
42 * Pollset Flags | |
43 */ | |
44 /** Adding or Removing a Descriptor is thread safe */ | |
45 public static final int APR_POLLSET_THREADSAFE = 0x001; | |
46 | |
47 | |
48 /** Used in apr_pollfd_t to determine what the apr_descriptor is | |
49 * apr_datatype_e enum | |
50 */ | |
51 public static final int APR_NO_DESC = 0; /** nothing here */ | |
52 public static final int APR_POLL_SOCKET = 1; /** descriptor refers to a so
cket */ | |
53 public static final int APR_POLL_FILE = 2; /** descriptor refers to a fi
le */ | |
54 public static final int APR_POLL_LASTDESC = 3; /** descriptor is the last on
e in the list */ | |
55 | |
56 /** | |
57 * Setup a pollset object. | |
58 * If flags equals APR_POLLSET_THREADSAFE, then a pollset is | |
59 * created on which it is safe to make concurrent calls to | |
60 * apr_pollset_add(), apr_pollset_remove() and apr_pollset_poll() from | |
61 * separate threads. This feature is only supported on some | |
62 * platforms; the apr_pollset_create() call will fail with | |
63 * APR_ENOTIMPL on platforms where it is not supported. | |
64 * @param size The maximum number of descriptors that this pollset can hold | |
65 * @param p The pool from which to allocate the pollset | |
66 * @param flags Optional flags to modify the operation of the pollset. | |
67 * @param ttl Maximum time to live for a particular socket. | |
68 * @return The pointer in which to return the newly created object | |
69 */ | |
70 public static native long create(int size, long p, int flags, long ttl) | |
71 throws Error; | |
72 /** | |
73 * Destroy a pollset object | |
74 * @param pollset The pollset to destroy | |
75 */ | |
76 public static native int destroy(long pollset); | |
77 | |
78 /** | |
79 * Add a socket to a pollset with the default timeout. | |
80 * @param pollset The pollset to which to add the socket | |
81 * @param sock The sockets to add | |
82 * @param reqevents requested events | |
83 */ | |
84 public static native int add(long pollset, long sock, | |
85 int reqevents); | |
86 | |
87 /** | |
88 * Add a socket to a pollset with a specific timeout. | |
89 * @param pollset The pollset to which to add the socket | |
90 * @param sock The sockets to add | |
91 * @param reqevents requested events | |
92 * @param timeout requested timeout in microseconds (-1 for infinite) | |
93 */ | |
94 public static native int addWithTimeout(long pollset, long sock, | |
95 int reqevents, long timeout); | |
96 | |
97 /** | |
98 * Remove a descriptor from a pollset | |
99 * @param pollset The pollset from which to remove the descriptor | |
100 * @param sock The socket to remove | |
101 */ | |
102 public static native int remove(long pollset, long sock); | |
103 | |
104 /** | |
105 * Block for activity on the descriptor(s) in a pollset | |
106 * @param pollset The pollset to use | |
107 * @param timeout Timeout in microseconds | |
108 * @param descriptors Array of signaled descriptors (output parameter) | |
109 * The descriptor array must be two times the size of pollset. | |
110 * and are populated as follows: | |
111 * <PRE> | |
112 * descriptors[2n + 0] -> returned events | |
113 * descriptors[2n + 1] -> socket | |
114 * </PRE> | |
115 * @param remove Remove signaled descriptors from pollset | |
116 * @return Number of signaled descriptors (output parameter) | |
117 * or negative APR error code. | |
118 */ | |
119 public static native int poll(long pollset, long timeout, | |
120 long [] descriptors, boolean remove); | |
121 | |
122 /** | |
123 * Maintain on the descriptor(s) in a pollset | |
124 * @param pollset The pollset to use | |
125 * @param descriptors Array of signaled descriptors (output parameter) | |
126 * The descriptor array must be the size of pollset. | |
127 * and are populated as follows: | |
128 * <PRE> | |
129 * descriptors[n] -> socket | |
130 * </PRE> | |
131 * @param remove Remove signaled descriptors from pollset | |
132 * @return Number of signaled descriptors (output parameter) | |
133 * or negative APR error code. | |
134 */ | |
135 public static native int maintain(long pollset, long [] descriptors, | |
136 boolean remove); | |
137 | |
138 /** | |
139 * Set the socket time to live. | |
140 * @param pollset The pollset to use | |
141 * @param ttl Timeout in microseconds | |
142 */ | |
143 public static native void setTtl(long pollset, long ttl); | |
144 | |
145 /** | |
146 * Get the socket time to live. | |
147 * @param pollset The pollset to use | |
148 * @return Timeout in microseconds | |
149 */ | |
150 public static native long getTtl(long pollset); | |
151 | |
152 /** | |
153 * Return all descriptor(s) in a pollset | |
154 * @param pollset The pollset to use | |
155 * @param descriptors Array of descriptors (output parameter) | |
156 * The descriptor array must be two times the size of pollset. | |
157 * and are populated as follows: | |
158 * <PRE> | |
159 * descriptors[2n + 0] -> returned events | |
160 * descriptors[2n + 1] -> socket | |
161 * </PRE> | |
162 * @return Number of descriptors (output parameter) in the Poll | |
163 * or negative APR error code. | |
164 */ | |
165 public static native int pollset(long pollset, long [] descriptors); | |
166 | |
167 /** | |
168 * Make poll() return. | |
169 * | |
170 * @param pollset | |
171 * @return Negative APR error code | |
172 */ | |
173 public static native int interrupt(long pollset); | |
174 | |
175 /** | |
176 * Check if interrupt() is allowed. | |
177 * | |
178 * @param pollset | |
179 * @return <code>true</code> if {@link #interrupt(long)} is allowed, else | |
180 * <code>false</code> | |
181 */ | |
182 public static native boolean wakeable(long pollset); | |
183 } | |
OLD | NEW |