ilb_comm.c revision dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * CDDL HEADER START
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * The contents of this file are subject to the terms of the
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Common Development and Distribution License (the "License").
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * You may not use this file except in compliance with the License.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * or http://www.opensolaris.org/os/licensing.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * See the License for the specific language governing permissions
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * and limitations under the License.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * When distributing Covered Code, include this CDDL HEADER in each
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * If applicable, add the following below this CDDL HEADER, with the
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * fields enclosed by brackets "[]" replaced with your own identifying
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * information: Portions Copyright [yyyy] [name of copyright owner]
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * CDDL HEADER END
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Use is subject to license terms.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra/* Assertion: the calling thread has a hold on the handle */
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misrai_ilb_socket_set_err(ilb_handle_t h, ilb_status_t err)
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra ilb_handle_impl_t *hi = (ilb_handle_impl_t *)h;
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra struct sockaddr_un sa = {AF_UNIX, SOCKET_PATH};
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra if (cond_init(&hi->h_cv, USYNC_THREAD, NULL) != 0) {
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra if (mutex_init(&hi->h_lock, USYNC_THREAD | LOCK_ERRORCHECK, NULL)
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra if ((s = socket(PF_UNIX, SOCK_SEQPACKET, 0)) == -1 ||
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra connect(s, (struct sockaddr *)&sa, sizeof (sa.sun_path))
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra /* The socket buffer must be at least the max size of a message */
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, &sobufsz,
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra sizeof (sobufsz)) != 0) {
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &sobufsz,
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra sizeof (sobufsz)) != 0) {
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra ilb_handle_impl_t *hi = (ilb_handle_impl_t *)h;
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra /* Somebody has done a close, no need to do anything. */
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra /* Wait until there is nobody waiting. */
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra if (cond_wait(&hi->h_cv, &hi->h_lock) != 0) {
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra /* No one is waiting, proceed to free the handle. */
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * Unified routine to communicate with ilbd.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * If ic is non-NULL, it means that the caller wants to send something
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * to ilbd and expects a reply. If ic is NULL, it means that the caller
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * only expects to receive from ilbd.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * The rbuf is the buffer supplied by the caller for receiving. If it
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * is NULL, it means that there is no reply expected.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * This function will not close() the socket to kernel unless there is
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * an error. If the transaction only consists of one exchange, the caller
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra * can use i_ilb_close_comm() to close() the socket when done.
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misrai_ilb_do_comm(ilb_handle_t h, ilb_comm_t *ic, size_t ic_sz, ilb_comm_t *rbuf,
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra ilb_handle_impl_t *hi = (ilb_handle_impl_t *)h;
dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9Sangeeta Misra if (cond_wait(&hi->h_cv, &hi->h_lock) != 0) {