jdk/src/windows/native/sun/nio/ch/Net.c
changeset 14025 fbebe005a3ee
parent 9035 1255eb81cc2f
child 14342 8435a30053c1
equal deleted inserted replaced
14024:694c379c2958 14025:fbebe005a3ee
    33 #include "nio.h"
    33 #include "nio.h"
    34 #include "nio_util.h"
    34 #include "nio_util.h"
    35 #include "net_util.h"
    35 #include "net_util.h"
    36 
    36 
    37 #include "sun_nio_ch_Net.h"
    37 #include "sun_nio_ch_Net.h"
       
    38 #include "sun_nio_ch_PollArrayWrapper.h"
    38 
    39 
    39 /**
    40 /**
    40  * Definitions to allow for building with older SDK include files.
    41  * Definitions to allow for building with older SDK include files.
    41  */
    42  */
    42 
    43 
   522         (jhow == sun_nio_ch_Net_SHUT_WR) ? SD_SEND : SD_BOTH;
   523         (jhow == sun_nio_ch_Net_SHUT_WR) ? SD_SEND : SD_BOTH;
   523     if (shutdown(fdval(env, fdo), how) == SOCKET_ERROR) {
   524     if (shutdown(fdval(env, fdo), how) == SOCKET_ERROR) {
   524         NET_ThrowNew(env, WSAGetLastError(), "shutdown");
   525         NET_ThrowNew(env, WSAGetLastError(), "shutdown");
   525     }
   526     }
   526 }
   527 }
       
   528 
       
   529 JNIEXPORT jint JNICALL
       
   530 Java_sun_nio_ch_Net_poll(JNIEnv* env, jclass this, jobject fdo, jint events, jlong timeout)
       
   531 {
       
   532     int rv;
       
   533     int revents = 0;
       
   534     struct timeval t;
       
   535     int lastError = 0;
       
   536     fd_set rd, wr, ex;
       
   537     jint fd = fdval(env, fdo);
       
   538 
       
   539     t.tv_sec = timeout / 1000;
       
   540     t.tv_usec = (timeout % 1000) * 1000;
       
   541 
       
   542     FD_ZERO(&rd);
       
   543     FD_ZERO(&wr);
       
   544     FD_ZERO(&ex);
       
   545     if (events & sun_nio_ch_PollArrayWrapper_POLLIN) {
       
   546         FD_SET(fd, &rd);
       
   547     }
       
   548     if (events & sun_nio_ch_PollArrayWrapper_POLLOUT ||
       
   549         events & sun_nio_ch_PollArrayWrapper_POLLCONN) {
       
   550         FD_SET(fd, &wr);
       
   551     }
       
   552     FD_SET(fd, &ex);
       
   553 
       
   554     rv = select(fd+1, &rd, &wr, &ex, &t);
       
   555 
       
   556     /* save last winsock error */
       
   557     if (rv == SOCKET_ERROR) {
       
   558         handleSocketError(env, lastError);
       
   559         return IOS_THROWN;
       
   560     } else if (rv >= 0) {
       
   561         rv = 0;
       
   562         if (FD_ISSET(fd, &rd)) {
       
   563             rv |= sun_nio_ch_PollArrayWrapper_POLLIN;
       
   564         }
       
   565         if (FD_ISSET(fd, &wr)) {
       
   566             rv |= sun_nio_ch_PollArrayWrapper_POLLOUT;
       
   567         }
       
   568         if (FD_ISSET(fd, &ex)) {
       
   569             rv |= sun_nio_ch_PollArrayWrapper_POLLERR;
       
   570         }
       
   571     }
       
   572     return rv;
       
   573 }