41 Pollset.init(); /* Dynamically loads pollset C functions */
42 MAX_EVENTS_TO_POLL = 512;
43 }
44
45 private final int event;
46 private final int setid;
47 private final long pollBuffer;
48
49 PollsetPoller(boolean read) throws IOException {
50 this.event = (read) ? Net.POLLIN : Net.POLLOUT;
51 this.setid = Pollset.pollsetCreate();
52 this.pollBuffer = Pollset.allocatePollArray(MAX_EVENTS_TO_POLL);
53 }
54
55 @Override
56 int fdVal() {
57 return setid;
58 }
59
60 @Override
61 void implRegister(int fd) throws IOException {
62 int ret = Pollset.pollsetCtl(setid, Pollset.PS_MOD, fd, Pollset.PS_POLLPRI | event);
63 if (ret != 0) {
64 throw new IOException("Unable to register fd " + fd);
65 }
66 }
67
68 @Override
69 void implDeregister(int fd, boolean polled) {
70 int ret = Pollset.pollsetCtl(setid, Pollset.PS_DELETE, fd, 0);
71 assert ret == 0;
72 }
73
74 /**
75 * Main poll method. The AIX Pollset library does not appear to pick up changes to the pollset
76 * (the set of fds being polled) while blocked on a call to this method. These changes happen
77 * regularly in the poll-loop thread and update thread from Poller.java.
78 * To address this difficulty, we break poll calls into 100ms sub-calls and emulate the timout.
79 */
80 @Override
81 int poll(int timeout) throws IOException {
82 int n;
83 switch (timeout) {
84 case 0:
85 n = pollInner(0);
86 break;
87 case Pollset.PS_NO_TIMEOUT:
88 do { n = pollInner(100); } while (n == 0);
89 break;
|
41 Pollset.init(); /* Dynamically loads pollset C functions */
42 MAX_EVENTS_TO_POLL = 512;
43 }
44
45 private final int event;
46 private final int setid;
47 private final long pollBuffer;
48
49 PollsetPoller(boolean read) throws IOException {
50 this.event = (read) ? Net.POLLIN : Net.POLLOUT;
51 this.setid = Pollset.pollsetCreate();
52 this.pollBuffer = Pollset.allocatePollArray(MAX_EVENTS_TO_POLL);
53 }
54
55 @Override
56 int fdVal() {
57 return setid;
58 }
59
60 @Override
61 void implStartPoll(int fd) throws IOException {
62 int ret = Pollset.pollsetCtl(setid, Pollset.PS_MOD, fd, Pollset.PS_POLLPRI | event);
63 if (ret != 0) {
64 throw new IOException("Unable to register fd " + fd);
65 }
66 }
67
68 @Override
69 void implStopPoll(int fd, boolean polled) {
70 int ret = Pollset.pollsetCtl(setid, Pollset.PS_DELETE, fd, 0);
71 assert ret == 0;
72 }
73
74 /**
75 * Main poll method. The AIX Pollset library does not appear to pick up changes to the pollset
76 * (the set of fds being polled) while blocked on a call to this method. These changes happen
77 * regularly in the poll-loop thread and update thread from Poller.java.
78 * To address this difficulty, we break poll calls into 100ms sub-calls and emulate the timout.
79 */
80 @Override
81 int poll(int timeout) throws IOException {
82 int n;
83 switch (timeout) {
84 case 0:
85 n = pollInner(0);
86 break;
87 case Pollset.PS_NO_TIMEOUT:
88 do { n = pollInner(100); } while (n == 0);
89 break;
|