162 } finally { |
162 } finally { |
163 readLock.unlock(); |
163 readLock.unlock(); |
164 } |
164 } |
165 } |
165 } |
166 |
166 |
167 public boolean translateReadyOps(int ops, int initialOps, |
167 public boolean translateReadyOps(int ops, int initialOps, SelectionKeyImpl ski) { |
168 SelectionKeyImpl sk) { |
168 int intOps = ski.nioInterestOps(); |
169 int intOps = sk.nioInterestOps(); // Do this just once, it synchronizes |
169 int oldOps = ski.nioReadyOps(); |
170 int oldOps = sk.nioReadyOps(); |
|
171 int newOps = initialOps; |
170 int newOps = initialOps; |
172 |
171 |
173 if ((ops & Net.POLLNVAL) != 0) |
172 if ((ops & Net.POLLNVAL) != 0) |
174 throw new Error("POLLNVAL detected"); |
173 throw new Error("POLLNVAL detected"); |
175 |
174 |
176 if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) { |
175 if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) { |
177 newOps = intOps; |
176 newOps = intOps; |
178 sk.nioReadyOps(newOps); |
177 ski.nioReadyOps(newOps); |
179 return (newOps & ~oldOps) != 0; |
178 return (newOps & ~oldOps) != 0; |
180 } |
179 } |
181 |
180 |
182 if (((ops & Net.POLLIN) != 0) && |
181 if (((ops & Net.POLLIN) != 0) && |
183 ((intOps & SelectionKey.OP_READ) != 0)) |
182 ((intOps & SelectionKey.OP_READ) != 0)) |
184 newOps |= SelectionKey.OP_READ; |
183 newOps |= SelectionKey.OP_READ; |
185 |
184 |
186 sk.nioReadyOps(newOps); |
185 ski.nioReadyOps(newOps); |
187 return (newOps & ~oldOps) != 0; |
186 return (newOps & ~oldOps) != 0; |
188 } |
187 } |
189 |
188 |
190 public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk) { |
189 public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski) { |
191 return translateReadyOps(ops, sk.nioReadyOps(), sk); |
190 return translateReadyOps(ops, ski.nioReadyOps(), ski); |
192 } |
191 } |
193 |
192 |
194 public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl sk) { |
193 public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl ski) { |
195 return translateReadyOps(ops, 0, sk); |
194 return translateReadyOps(ops, 0, ski); |
196 } |
195 } |
197 |
196 |
198 public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk) { |
197 public int translateInterestOps(int ops) { |
|
198 int newOps = 0; |
199 if (ops == SelectionKey.OP_READ) |
199 if (ops == SelectionKey.OP_READ) |
200 ops = Net.POLLIN; |
200 newOps |= Net.POLLIN; |
201 sk.selector.putEventOps(sk, ops); |
201 return newOps; |
202 } |
202 } |
203 |
203 |
204 /** |
204 /** |
205 * Marks the beginning of a read operation that might block. |
205 * Marks the beginning of a read operation that might block. |
206 * |
206 * |