socknotify.c revision 0f1702c5201310f0529cd5abb77652e5e9b241b6
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * CDDL HEADER START
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * The contents of this file are subject to the terms of the
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Common Development and Distribution License (the "License").
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * You may not use this file except in compliance with the License.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * See the License for the specific language governing permissions
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * and limitations under the License.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * When distributing Covered Code, include this CDDL HEADER in each
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * If applicable, add the following below this CDDL HEADER, with the
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * fields enclosed by brackets "[]" replaced with your own identifying
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * information: Portions Copyright [yyyy] [name of copyright owner]
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * CDDL HEADER END
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Use is subject to license terms.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * There can only be a single thread waiting for data (enforced by
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * so_lock_read()), whereas for write there might be multiple threads
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * waiting for transmit buffers. So therefore we use cv_broadcast for
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * write and cv_signal for read.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningstatic int i_so_notify_last_rx(struct sonode *, int *, int *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningstatic int i_so_notify_last_tx(struct sonode *, int *, int *);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * The notification functions must be called with so_lock held,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * and they will all *drop* so_lock before returning.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Wake up anyone waiting for the connection to be established.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * The socket is disconnecting, so no more data can be sent. Wake up
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * anyone that is waiting to send data.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning } else if (i_so_notify_last_tx(so, &pollev, &sigev)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * The socket is disconnected, so not more data can be sent or received.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Wake up anyone that is waiting to send or receive data.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningso_notify_disconnected(struct sonode *so, int error)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (void) i_so_notify_last_tx(so, &pollev, &sigev);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (void) i_so_notify_last_rx(so, &pollev, &sigev);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * The socket is writeable. Wake up anyone waiting to send data.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Data is available, so wake up anyone waiting for data.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so->so_pollev & (SO_POLLEV_IN|SO_POLLEV_ALWAYS)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning pollwakeup(&so->so_poll_list, POLLIN|POLLRDNORM);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Transient error. Wake up anyone waiting to send or receive data.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning socket_sendsig(so, SOCKETSIG_WRITE|SOCKETSIG_READ);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning pollwakeup(&so->so_poll_list, POLLOUT|POLLIN|POLLRDNORM);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Out-of-band data is incoming, notify any interested parties.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Received out-of-band data. If the OOB data is delivered inline, then
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * in addition of regular OOB notification, anyone waiting for normal
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * data is also notified.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningso_notify_oobdata(struct sonode *so, boolean_t oob_inline)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * End-of-file has been reach, so peer will send no new data. Wake up
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * anyone that is waiting for data.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (void) i_so_notify_last_rx(so, &pollev, &sigev);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Wake up anyone waiting for a new connection.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning KSOCKET_CALLBACK(so, newconn, so->so_rcv_queued);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so->so_pollev & (SO_POLLEV_IN|SO_POLLEV_ALWAYS)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning pollwakeup(&so->so_poll_list, POLLIN|POLLRDNORM);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * User initated shutdown/close, wake anyone that is trying to do
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * an operation that is no longer possible.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_state & (SS_CANTSENDMORE|SS_CANTRCVMORE));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (void) i_so_notify_last_tx(so, &pollev, &sigev);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (void) i_so_notify_last_rx(so, &pollev, &sigev);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * No more data will be coming in, and this will be the last notification
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningi_so_notify_last_rx(struct sonode *so, int *pollev, int *sigev)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * The socket is un-writeable. Make one last notification.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningi_so_notify_last_tx(struct sonode *so, int *pollev, int *sigev)