< prev index next >

src/java.base/windows/native/libnet/DualStackPlainSocketImpl.c

Print this page
rev 15720 : 8166850: No runtime error expected after calling NET_MapSocketOption
   1 /*
   2  * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 352   (JNIEnv *env, jclass clazz, jint fd) {
 353      NET_SocketClose(fd);
 354 }
 355 
 356 /*
 357  * Class:     java_net_DualStackPlainSocketImpl
 358  * Method:    shutdown0
 359  * Signature: (II)V
 360  */
 361 JNIEXPORT void JNICALL Java_java_net_DualStackPlainSocketImpl_shutdown0
 362   (JNIEnv *env, jclass clazz, jint fd, jint howto) {
 363     shutdown(fd, howto);
 364 }
 365 
 366 
 367 /*
 368  * Class:     java_net_DualStackPlainSocketImpl
 369  * Method:    setIntOption
 370  * Signature: (III)V
 371  */
 372 JNIEXPORT void JNICALL Java_java_net_DualStackPlainSocketImpl_setIntOption
 373   (JNIEnv *env, jclass clazz, jint fd, jint cmd, jint value) {
 374 

 375     int level = 0, opt = 0;
 376     struct linger linger = {0, 0};
 377     char *parg;
 378     int arglen;
 379 
 380     if (NET_MapSocketOption(cmd, &level, &opt) < 0) {
 381         JNU_ThrowByNameWithLastError(env,
 382                                      JNU_JAVANETPKG "SocketException",
 383                                      "Invalid option");
 384         return;
 385     }
 386 
 387     if (opt == java_net_SocketOptions_SO_LINGER) {
 388         parg = (char *)&linger;
 389         arglen = sizeof(linger);
 390         if (value >= 0) {
 391             linger.l_onoff = 1;
 392             linger.l_linger = (unsigned short)value;
 393         } else {
 394             linger.l_onoff = 0;
 395             linger.l_linger = 0;
 396         }
 397     } else {
 398         parg = (char *)&value;
 399         arglen = sizeof(value);
 400     }
 401 
 402     if (NET_SetSockOpt(fd, level, opt, parg, arglen) < 0) {
 403         NET_ThrowNew(env, WSAGetLastError(), "setsockopt");
 404     }
 405 }
 406 
 407 /*
 408  * Class:     java_net_DualStackPlainSocketImpl
 409  * Method:    getIntOption
 410  * Signature: (II)I
 411  */
 412 JNIEXPORT jint JNICALL Java_java_net_DualStackPlainSocketImpl_getIntOption
 413   (JNIEnv *env, jclass clazz, jint fd, jint cmd) {
 414 
 415     int level = 0, opt = 0;
 416     int result=0;
 417     struct linger linger = {0, 0};
 418     char *arg;
 419     int arglen;
 420 
 421     if (NET_MapSocketOption(cmd, &level, &opt) < 0) {
 422         JNU_ThrowByNameWithLastError(env,
 423                                      JNU_JAVANETPKG "SocketException",
 424                                      "Unsupported socket option");
 425         return -1;
 426     }
 427 
 428     if (opt == java_net_SocketOptions_SO_LINGER) {
 429         arg = (char *)&linger;
 430         arglen = sizeof(linger);
 431     } else {
 432         arg = (char *)&result;
 433         arglen = sizeof(result);
 434     }
 435 
 436     if (NET_GetSockOpt(fd, level, opt, arg, &arglen) < 0) {
 437         NET_ThrowNew(env, WSAGetLastError(), "getsockopt");
 438         return -1;
 439     }
 440 
 441     if (opt == java_net_SocketOptions_SO_LINGER)
 442         return linger.l_onoff ? linger.l_linger : -1;
 443     else
 444         return result;


   1 /*
   2  * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 352   (JNIEnv *env, jclass clazz, jint fd) {
 353      NET_SocketClose(fd);
 354 }
 355 
 356 /*
 357  * Class:     java_net_DualStackPlainSocketImpl
 358  * Method:    shutdown0
 359  * Signature: (II)V
 360  */
 361 JNIEXPORT void JNICALL Java_java_net_DualStackPlainSocketImpl_shutdown0
 362   (JNIEnv *env, jclass clazz, jint fd, jint howto) {
 363     shutdown(fd, howto);
 364 }
 365 
 366 
 367 /*
 368  * Class:     java_net_DualStackPlainSocketImpl
 369  * Method:    setIntOption
 370  * Signature: (III)V
 371  */
 372 JNIEXPORT void JNICALL
 373 Java_java_net_DualStackPlainSocketImpl_setIntOption
 374   (JNIEnv *env, jclass clazz, jint fd, jint cmd, jint value)
 375 {
 376     int level = 0, opt = 0;
 377     struct linger linger = {0, 0};
 378     char *parg;
 379     int arglen;
 380 
 381     if (NET_MapSocketOption(cmd, &level, &opt) < 0) {
 382         JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");


 383         return;
 384     }
 385 
 386     if (opt == java_net_SocketOptions_SO_LINGER) {
 387         parg = (char *)&linger;
 388         arglen = sizeof(linger);
 389         if (value >= 0) {
 390             linger.l_onoff = 1;
 391             linger.l_linger = (unsigned short)value;
 392         } else {
 393             linger.l_onoff = 0;
 394             linger.l_linger = 0;
 395         }
 396     } else {
 397         parg = (char *)&value;
 398         arglen = sizeof(value);
 399     }
 400 
 401     if (NET_SetSockOpt(fd, level, opt, parg, arglen) < 0) {
 402         NET_ThrowNew(env, WSAGetLastError(), "setsockopt");
 403     }
 404 }
 405 
 406 /*
 407  * Class:     java_net_DualStackPlainSocketImpl
 408  * Method:    getIntOption
 409  * Signature: (II)I
 410  */
 411 JNIEXPORT jint JNICALL Java_java_net_DualStackPlainSocketImpl_getIntOption
 412   (JNIEnv *env, jclass clazz, jint fd, jint cmd)
 413 {
 414     int level = 0, opt = 0;
 415     int result=0;
 416     struct linger linger = {0, 0};
 417     char *arg;
 418     int arglen;
 419 
 420     if (NET_MapSocketOption(cmd, &level, &opt) < 0) {
 421         JNU_ThrowByName(env, "java/net/SocketException", "Invalid option");


 422         return -1;
 423     }
 424 
 425     if (opt == java_net_SocketOptions_SO_LINGER) {
 426         arg = (char *)&linger;
 427         arglen = sizeof(linger);
 428     } else {
 429         arg = (char *)&result;
 430         arglen = sizeof(result);
 431     }
 432 
 433     if (NET_GetSockOpt(fd, level, opt, arg, &arglen) < 0) {
 434         NET_ThrowNew(env, WSAGetLastError(), "getsockopt");
 435         return -1;
 436     }
 437 
 438     if (opt == java_net_SocketOptions_SO_LINGER)
 439         return linger.l_onoff ? linger.l_linger : -1;
 440     else
 441         return result;


< prev index next >