jdk/src/windows/native/sun/nio/ch/SocketDispatcher.c
changeset 5804 faf9bd47d6ce
parent 5506 202f599c92aa
child 7668 d4a77089c587
equal deleted inserted replaced
5803:c3ddaebe216b 5804:faf9bd47d6ce
    48     DWORD read = 0;
    48     DWORD read = 0;
    49     DWORD flags = 0;
    49     DWORD flags = 0;
    50     jint fd = fdval(env, fdo);
    50     jint fd = fdval(env, fdo);
    51     WSABUF buf;
    51     WSABUF buf;
    52 
    52 
       
    53     /* limit size */
       
    54     if (len > MAX_BUFFER_SIZE)
       
    55         len = MAX_BUFFER_SIZE;
       
    56 
    53     /* destination buffer and size */
    57     /* destination buffer and size */
    54     buf.buf = (char *)address;
    58     buf.buf = (char *)address;
    55     buf.len = (u_long)len;
    59     buf.len = (u_long)len;
    56 
    60 
    57     /* read into the buffers */
    61     /* read into the buffers */
    84     DWORD read = 0;
    88     DWORD read = 0;
    85     DWORD flags = 0;
    89     DWORD flags = 0;
    86     jint fd = fdval(env, fdo);
    90     jint fd = fdval(env, fdo);
    87     struct iovec *iovp = (struct iovec *)address;
    91     struct iovec *iovp = (struct iovec *)address;
    88     WSABUF *bufs = malloc(len * sizeof(WSABUF));
    92     WSABUF *bufs = malloc(len * sizeof(WSABUF));
       
    93     jint rem = MAX_BUFFER_SIZE;
    89 
    94 
    90     if (bufs == 0) {
    95     if (bufs == 0) {
    91         JNU_ThrowOutOfMemoryError(env, 0);
    96         JNU_ThrowOutOfMemoryError(env, 0);
    92         return IOS_THROWN;
    97         return IOS_THROWN;
    93     }
    98     }
    96         len = 16;
   101         len = 16;
    97     }
   102     }
    98 
   103 
    99     /* copy iovec into WSABUF */
   104     /* copy iovec into WSABUF */
   100     for(i=0; i<len; i++) {
   105     for(i=0; i<len; i++) {
       
   106         jint iov_len = iovp[i].iov_len;
       
   107         if (iov_len > rem)
       
   108             iov_len = rem;
   101         bufs[i].buf = (char *)iovp[i].iov_base;
   109         bufs[i].buf = (char *)iovp[i].iov_base;
   102         bufs[i].len = (u_long)iovp[i].iov_len;
   110         bufs[i].len = (u_long)iov_len;
       
   111         rem -= iov_len;
       
   112         if (rem == 0) {
       
   113             len = i+1;
       
   114             break;
       
   115         }
   103     }
   116     }
   104 
   117 
   105     /* read into the buffers */
   118     /* read into the buffers */
   106     i = WSARecv((SOCKET)fd, /* Socket */
   119     i = WSARecv((SOCKET)fd, /* Socket */
   107             bufs,           /* pointers to the buffers */
   120             bufs,           /* pointers to the buffers */
   134     int i = 0;
   147     int i = 0;
   135     DWORD written = 0;
   148     DWORD written = 0;
   136     jint fd = fdval(env, fdo);
   149     jint fd = fdval(env, fdo);
   137     WSABUF buf;
   150     WSABUF buf;
   138 
   151 
       
   152     /* limit size */
       
   153     if (len > MAX_BUFFER_SIZE)
       
   154         len = MAX_BUFFER_SIZE;
       
   155 
   139     /* copy iovec into WSABUF */
   156     /* copy iovec into WSABUF */
   140     buf.buf = (char *)address;
   157     buf.buf = (char *)address;
   141     buf.len = (u_long)len;
   158     buf.len = (u_long)len;
   142 
   159 
   143     /* read into the buffers */
   160     /* read into the buffers */
   169     int i = 0;
   186     int i = 0;
   170     DWORD written = 0;
   187     DWORD written = 0;
   171     jint fd = fdval(env, fdo);
   188     jint fd = fdval(env, fdo);
   172     struct iovec *iovp = (struct iovec *)address;
   189     struct iovec *iovp = (struct iovec *)address;
   173     WSABUF *bufs = malloc(len * sizeof(WSABUF));
   190     WSABUF *bufs = malloc(len * sizeof(WSABUF));
       
   191     jint rem = MAX_BUFFER_SIZE;
   174 
   192 
   175     if (bufs == 0) {
   193     if (bufs == 0) {
   176         JNU_ThrowOutOfMemoryError(env, 0);
   194         JNU_ThrowOutOfMemoryError(env, 0);
   177         return IOS_THROWN;
   195         return IOS_THROWN;
   178     }
   196     }
   181         len = 16;
   199         len = 16;
   182     }
   200     }
   183 
   201 
   184     /* copy iovec into WSABUF */
   202     /* copy iovec into WSABUF */
   185     for(i=0; i<len; i++) {
   203     for(i=0; i<len; i++) {
       
   204         jint iov_len = iovp[i].iov_len;
       
   205         if (iov_len > rem)
       
   206             iov_len = rem;
   186         bufs[i].buf = (char *)iovp[i].iov_base;
   207         bufs[i].buf = (char *)iovp[i].iov_base;
   187         bufs[i].len = (u_long)iovp[i].iov_len;
   208         bufs[i].len = (u_long)iov_len;
       
   209         rem -= iov_len;
       
   210         if (rem == 0) {
       
   211             len = i+1;
       
   212             break;
       
   213         }
   188     }
   214     }
   189 
   215 
   190     /* read into the buffers */
   216     /* read into the buffers */
   191     i = WSASend((SOCKET)fd, /* Socket */
   217     i = WSASend((SOCKET)fd, /* Socket */
   192             bufs,           /* pointers to the buffers */
   218             bufs,           /* pointers to the buffers */