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