1227 } |
1227 } |
1228 |
1228 |
1229 /** |
1229 /** |
1230 * Translates native poll revent set into a ready operation set |
1230 * Translates native poll revent set into a ready operation set |
1231 */ |
1231 */ |
1232 public boolean translateReadyOps(int ops, int initialOps, |
1232 public boolean translateReadyOps(int ops, int initialOps, SelectionKeyImpl ski) { |
1233 SelectionKeyImpl sk) { |
1233 int intOps = ski.nioInterestOps(); |
1234 int intOps = sk.nioInterestOps(); // Do this just once, it synchronizes |
1234 int oldOps = ski.nioReadyOps(); |
1235 int oldOps = sk.nioReadyOps(); |
|
1236 int newOps = initialOps; |
1235 int newOps = initialOps; |
1237 |
1236 |
1238 if ((ops & Net.POLLNVAL) != 0) { |
1237 if ((ops & Net.POLLNVAL) != 0) { |
1239 // This should only happen if this channel is pre-closed while a |
1238 // This should only happen if this channel is pre-closed while a |
1240 // selection operation is in progress |
1239 // selection operation is in progress |
1242 return false; |
1241 return false; |
1243 } |
1242 } |
1244 |
1243 |
1245 if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) { |
1244 if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) { |
1246 newOps = intOps; |
1245 newOps = intOps; |
1247 sk.nioReadyOps(newOps); |
1246 ski.nioReadyOps(newOps); |
1248 return (newOps & ~oldOps) != 0; |
1247 return (newOps & ~oldOps) != 0; |
1249 } |
1248 } |
1250 |
1249 |
1251 if (((ops & Net.POLLIN) != 0) && |
1250 if (((ops & Net.POLLIN) != 0) && |
1252 ((intOps & SelectionKey.OP_READ) != 0)) |
1251 ((intOps & SelectionKey.OP_READ) != 0)) |
1254 |
1253 |
1255 if (((ops & Net.POLLOUT) != 0) && |
1254 if (((ops & Net.POLLOUT) != 0) && |
1256 ((intOps & SelectionKey.OP_WRITE) != 0)) |
1255 ((intOps & SelectionKey.OP_WRITE) != 0)) |
1257 newOps |= SelectionKey.OP_WRITE; |
1256 newOps |= SelectionKey.OP_WRITE; |
1258 |
1257 |
1259 sk.nioReadyOps(newOps); |
1258 ski.nioReadyOps(newOps); |
1260 return (newOps & ~oldOps) != 0; |
1259 return (newOps & ~oldOps) != 0; |
1261 } |
1260 } |
1262 |
1261 |
1263 public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk) { |
1262 public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski) { |
1264 return translateReadyOps(ops, sk.nioReadyOps(), sk); |
1263 return translateReadyOps(ops, ski.nioReadyOps(), ski); |
1265 } |
1264 } |
1266 |
1265 |
1267 public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl sk) { |
1266 public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl ski) { |
1268 return translateReadyOps(ops, 0, sk); |
1267 return translateReadyOps(ops, 0, ski); |
1269 } |
1268 } |
1270 |
1269 |
1271 /** |
1270 /** |
1272 * Poll this channel's socket for reading up to the given timeout. |
1271 * Poll this channel's socket for reading up to the given timeout. |
1273 * @return {@code true} if the socket is polled |
1272 * @return {@code true} if the socket is polled |
1293 } |
1292 } |
1294 |
1293 |
1295 /** |
1294 /** |
1296 * Translates an interest operation set into a native poll event set |
1295 * Translates an interest operation set into a native poll event set |
1297 */ |
1296 */ |
1298 public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk) { |
1297 public int translateInterestOps(int ops) { |
1299 int newOps = 0; |
1298 int newOps = 0; |
1300 |
|
1301 if ((ops & SelectionKey.OP_READ) != 0) |
1299 if ((ops & SelectionKey.OP_READ) != 0) |
1302 newOps |= Net.POLLIN; |
1300 newOps |= Net.POLLIN; |
1303 if ((ops & SelectionKey.OP_WRITE) != 0) |
1301 if ((ops & SelectionKey.OP_WRITE) != 0) |
1304 newOps |= Net.POLLOUT; |
1302 newOps |= Net.POLLOUT; |
1305 if ((ops & SelectionKey.OP_CONNECT) != 0) |
1303 if ((ops & SelectionKey.OP_CONNECT) != 0) |
1306 newOps |= Net.POLLIN; |
1304 newOps |= Net.POLLIN; |
1307 sk.selector.putEventOps(sk, newOps); |
1305 return newOps; |
1308 } |
1306 } |
1309 |
1307 |
1310 public FileDescriptor getFD() { |
1308 public FileDescriptor getFD() { |
1311 return fd; |
1309 return fd; |
1312 } |
1310 } |