< prev index next >

src/java.base/windows/classes/sun/nio/ch/WEPollPoller.java

Print this page
*** 30,20 ***
  /**
   * Poller implementation based on wepoll.
   */
  class WEPollPoller extends Poller {
      private static final int MAX_EVENTS_TO_POLL = 256;
-     private static final int ENOENT = 2;
  
      private final long handle;
      private final int event;
      private final long address;
  
      WEPollPoller(boolean read) throws IOException {
!         this.handle = WEPoll.create();
          this.event = (read) ? EPOLLIN : EPOLLOUT;
!         this.address = WEPoll.allocatePollArray(MAX_EVENTS_TO_POLL);
      }
  
      @Override
      void implRegister(int fdVal) throws IOException {
          int err = WEPoll.ctl(handle, EPOLL_CTL_ADD, fdVal, (event | EPOLLONESHOT));
--- 30,34 ---
  /**
   * Poller implementation based on wepoll.
   */
  class WEPollPoller extends Poller {
      private static final int MAX_EVENTS_TO_POLL = 256;
  
      private final long handle;
      private final int event;
      private final long address;
  
      WEPollPoller(boolean read) throws IOException {
!         long handle =  WEPoll.create();
+         long address;
+         try {
+             address = WEPoll.allocatePollArray(MAX_EVENTS_TO_POLL);
+         } catch (Throwable e) {
+             WEPoll.close(handle);
+             throw e;
+         }
+ 
          this.event = (read) ? EPOLLIN : EPOLLOUT;
!         this.handle = handle;
+         this.address = address;
+     }
+ 
+     @Override
+     void close() {
+         WEPoll.close(handle);
+         WEPoll.freePollArray(address);
      }
  
      @Override
      void implRegister(int fdVal) throws IOException {
          int err = WEPoll.ctl(handle, EPOLL_CTL_ADD, fdVal, (event | EPOLLONESHOT));
< prev index next >