1 /*
2 * Copyright (c) 2009, 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
422 jlong *addr = jlong_to_ptr(address);
423 struct iovec iov[1];
424 struct msghdr msg[1];
425 char cbuf[CMSG_SPACE(sizeof (struct sctp_sndrcvinfo))];
426 int flags = peek == JNI_TRUE ? MSG_PEEK : 0;
427
428 /* Set up the msghdr structure for receiving */
429 memset(msg, 0, sizeof (*msg));
430 msg->msg_name = &sa;
431 msg->msg_namelen = sizeof(sa);
432 iov->iov_base = addr;
433 iov->iov_len = length;
434 msg->msg_iov = iov;
435 msg->msg_iovlen = 1;
436 msg->msg_control = cbuf;
437 msg->msg_controllen = sizeof(cbuf);
438 msg->msg_flags = 0;
439
440 do {
441 if ((rv = recvmsg(fd, msg, flags)) < 0) {
442 if (errno == EWOULDBLOCK) {
443 return IOS_UNAVAILABLE;
444 } else if (errno == EINTR) {
445 return IOS_INTERRUPTED;
446
447 #ifdef __linux__
448 } else if (errno == ENOTCONN) {
449 /* ENOTCONN when EOF reached */
450 rv = 0;
451 /* there will be no control data */
452 msg->msg_controllen = 0;
453 #endif /* __linux__ */
454
455 } else {
456 handleSocketError(env, errno);
457 return 0;
458 }
459 }
460
461 if (msg->msg_flags & MSG_NOTIFICATION) {
462 char *bufp = (char*)addr;
565 /* Set up the msghdr structure for sending */
566 memset(msg, 0, sizeof (*msg));
567 memset(cbuf, 0, cbuf_size);
568 msg->msg_name = &sa;
569 msg->msg_namelen = sa_len;
570 iov->iov_base = addr;
571 iov->iov_len = length;
572 msg->msg_iov = iov;
573 msg->msg_iovlen = 1;
574 msg->msg_control = cbuf;
575 msg->msg_controllen = cbuf_size;
576 msg->msg_flags = 0;
577
578 cdata->streamNumber = streamNumber;
579 cdata->assocId = assocId;
580 cdata->unordered = unordered;
581 cdata->ppid = ppid;
582 setControlData(msg, cdata);
583
584 if ((rv = sendmsg(fd, msg, 0)) < 0) {
585 if (errno == EWOULDBLOCK) {
586 return IOS_UNAVAILABLE;
587 } else if (errno == EINTR) {
588 return IOS_INTERRUPTED;
589 } else if (errno == EPIPE) {
590 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
591 "Socket is shutdown for writing");
592 } else {
593 handleSocketError(env, errno);
594 return 0;
595 }
596 }
597
598 return rv;
599 }
600
601 /*
602 * Class: sun_nio_ch_sctp_SctpChannelImpl
603 * Method: checkConnect
604 * Signature: (Ljava/io/FileDescriptor;ZZ)I
605 */
|
1 /*
2 * Copyright (c) 2009, 2018, 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
422 jlong *addr = jlong_to_ptr(address);
423 struct iovec iov[1];
424 struct msghdr msg[1];
425 char cbuf[CMSG_SPACE(sizeof (struct sctp_sndrcvinfo))];
426 int flags = peek == JNI_TRUE ? MSG_PEEK : 0;
427
428 /* Set up the msghdr structure for receiving */
429 memset(msg, 0, sizeof (*msg));
430 msg->msg_name = &sa;
431 msg->msg_namelen = sizeof(sa);
432 iov->iov_base = addr;
433 iov->iov_len = length;
434 msg->msg_iov = iov;
435 msg->msg_iovlen = 1;
436 msg->msg_control = cbuf;
437 msg->msg_controllen = sizeof(cbuf);
438 msg->msg_flags = 0;
439
440 do {
441 if ((rv = recvmsg(fd, msg, flags)) < 0) {
442 if (errno == EAGAIN || errno == EWOULDBLOCK) {
443 return IOS_UNAVAILABLE;
444 } else if (errno == EINTR) {
445 return IOS_INTERRUPTED;
446
447 #ifdef __linux__
448 } else if (errno == ENOTCONN) {
449 /* ENOTCONN when EOF reached */
450 rv = 0;
451 /* there will be no control data */
452 msg->msg_controllen = 0;
453 #endif /* __linux__ */
454
455 } else {
456 handleSocketError(env, errno);
457 return 0;
458 }
459 }
460
461 if (msg->msg_flags & MSG_NOTIFICATION) {
462 char *bufp = (char*)addr;
565 /* Set up the msghdr structure for sending */
566 memset(msg, 0, sizeof (*msg));
567 memset(cbuf, 0, cbuf_size);
568 msg->msg_name = &sa;
569 msg->msg_namelen = sa_len;
570 iov->iov_base = addr;
571 iov->iov_len = length;
572 msg->msg_iov = iov;
573 msg->msg_iovlen = 1;
574 msg->msg_control = cbuf;
575 msg->msg_controllen = cbuf_size;
576 msg->msg_flags = 0;
577
578 cdata->streamNumber = streamNumber;
579 cdata->assocId = assocId;
580 cdata->unordered = unordered;
581 cdata->ppid = ppid;
582 setControlData(msg, cdata);
583
584 if ((rv = sendmsg(fd, msg, 0)) < 0) {
585 if (errno == EAGAIN || errno == EWOULDBLOCK) {
586 return IOS_UNAVAILABLE;
587 } else if (errno == EINTR) {
588 return IOS_INTERRUPTED;
589 } else if (errno == EPIPE) {
590 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
591 "Socket is shutdown for writing");
592 } else {
593 handleSocketError(env, errno);
594 return 0;
595 }
596 }
597
598 return rv;
599 }
600
601 /*
602 * Class: sun_nio_ch_sctp_SctpChannelImpl
603 * Method: checkConnect
604 * Signature: (Ljava/io/FileDescriptor;ZZ)I
605 */
|