4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include <sys/types.h>
27 #include <sys/t_lock.h>
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/buf.h>
31 #include <sys/vfs.h>
32 #include <sys/vnode.h>
33 #include <sys/debug.h>
34 #include <sys/errno.h>
35 #include <sys/stropts.h>
36 #include <sys/cmn_err.h>
37 #include <sys/sysmacros.h>
38 #include <sys/policy.h>
39
40 #include <sys/filio.h>
41 #include <sys/sockio.h>
42
43 #include <sys/project.h>
1077 short origevents = events;
1078 int so_state;
1079
1080 so_state = so->so_state;
1081
1082 ASSERT(so->so_version != SOV_STREAM);
1083
1084 if (!(so_state & SS_ISCONNECTED) && (so->so_type == SOCK_STREAM)) {
1085 /*
1086 * Not connected yet - turn off write side events
1087 */
1088 events &= ~(POLLOUT|POLLWRBAND);
1089 }
1090
1091 /*
1092 * Check for errors
1093 */
1094 if (so->so_error != 0 &&
1095 ((POLLIN|POLLRDNORM|POLLOUT) & origevents) != 0) {
1096 *reventsp = (POLLIN|POLLRDNORM|POLLOUT) & origevents;
1097 return (0);
1098 }
1099
1100 *reventsp = 0;
1101
1102 /*
1103 * Don't mark socket as writable until TX queued data is
1104 * below watermark.
1105 */
1106 if (so->so_type == SOCK_STREAM) {
1107 if (sdp_polldata(
1108 (struct sdp_conn_struct_t *)so->so_proto_handle,
1109 SDP_XMIT)) {
1110 *reventsp |= POLLOUT & events;
1111 }
1112 } else {
1113 *reventsp = 0;
1114 goto done;
1115 }
1116
1117 if (sdp_polldata((struct sdp_conn_struct_t *)so->so_proto_handle,
1118 SDP_READ)) {
1119 *reventsp |= (POLLIN|POLLRDNORM) & events;
1120 }
1121
1122 if ((so_state & SS_CANTRCVMORE) || (so->so_acceptq_len > 0)) {
1123 *reventsp |= (POLLIN|POLLRDNORM) & events;
1124 }
1125
1126 done:
1127 if (!*reventsp && !anyyet) {
1128 *phpp = &so->so_poll_list;
1129 }
1130
1131 return (0);
1132 }
1133
1134 /* ARGSUSED */
1135 static int
1136 sosdp_close(struct sonode *so, int flag, struct cred *cr)
1137 {
1138 int error = 0;
1139
1140 mutex_enter(&so->so_lock);
1141 so_lock_single(so);
1142 /*
1143 * Need to set flags as there might be ops in progress on
1144 * this socket.
1145 *
1146 * If socket already disconnected/disconnecting,
1147 * don't send signal (again).
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2017 Joyent, Inc.
25 */
26
27 #include <sys/types.h>
28 #include <sys/t_lock.h>
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/buf.h>
32 #include <sys/vfs.h>
33 #include <sys/vnode.h>
34 #include <sys/debug.h>
35 #include <sys/errno.h>
36 #include <sys/stropts.h>
37 #include <sys/cmn_err.h>
38 #include <sys/sysmacros.h>
39 #include <sys/policy.h>
40
41 #include <sys/filio.h>
42 #include <sys/sockio.h>
43
44 #include <sys/project.h>
1078 short origevents = events;
1079 int so_state;
1080
1081 so_state = so->so_state;
1082
1083 ASSERT(so->so_version != SOV_STREAM);
1084
1085 if (!(so_state & SS_ISCONNECTED) && (so->so_type == SOCK_STREAM)) {
1086 /*
1087 * Not connected yet - turn off write side events
1088 */
1089 events &= ~(POLLOUT|POLLWRBAND);
1090 }
1091
1092 /*
1093 * Check for errors
1094 */
1095 if (so->so_error != 0 &&
1096 ((POLLIN|POLLRDNORM|POLLOUT) & origevents) != 0) {
1097 *reventsp = (POLLIN|POLLRDNORM|POLLOUT) & origevents;
1098 goto done;
1099 }
1100
1101 *reventsp = 0;
1102 if (so->so_type != SOCK_STREAM) {
1103 goto done;
1104 }
1105
1106 /*
1107 * Don't mark socket writable until TX queued data is below watermark.
1108 */
1109 if (sdp_polldata((struct sdp_conn_struct_t *)so->so_proto_handle,
1110 SDP_XMIT)) {
1111 *reventsp |= POLLOUT & events;
1112 }
1113
1114 if (sdp_polldata((struct sdp_conn_struct_t *)so->so_proto_handle,
1115 SDP_READ)) {
1116 *reventsp |= (POLLIN|POLLRDNORM) & events;
1117 }
1118
1119 if ((so_state & SS_CANTRCVMORE) || (so->so_acceptq_len > 0)) {
1120 *reventsp |= (POLLIN|POLLRDNORM) & events;
1121 }
1122
1123 done:
1124 if ((*reventsp == 0 && !anyyet) || (events & POLLET)) {
1125 *phpp = &so->so_poll_list;
1126 }
1127
1128 return (0);
1129 }
1130
1131 /* ARGSUSED */
1132 static int
1133 sosdp_close(struct sonode *so, int flag, struct cred *cr)
1134 {
1135 int error = 0;
1136
1137 mutex_enter(&so->so_lock);
1138 so_lock_single(so);
1139 /*
1140 * Need to set flags as there might be ops in progress on
1141 * this socket.
1142 *
1143 * If socket already disconnected/disconnecting,
1144 * don't send signal (again).
|