'\" te .\" Copyright 1989 AT&T .\" Copyright (c) 2006, Sun Microsystems, Inc., All Rights Reserved .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] .TH PUTCTL 9F "Jan 16, 2006" .SH NAME putctl \- send a control message to a queue .SH SYNOPSIS .LP .nf #include \fBint\fR \fBputctl\fR(\fBqueue_t *\fR\fIq\fR, \fBint\fR \fItype\fR); .fi .SH INTERFACE LEVEL .sp .LP Architecture independent level 1 (DDI/DKI). .SH PARAMETERS .sp .ne 2 .na \fB\fIq\fR\fR .ad .RS 8n Queue to which the message is to be sent. .RE .sp .ne 2 .na \fB\fItype\fR\fR .ad .RS 8n Message type (must be control, not data type). .RE .SH DESCRIPTION .sp .LP The \fBputctl()\fR function tests the \fItype\fR argument to make sure a data type has not been specified, and then attempts to allocate a message block. \fBputctl()\fR fails if \fItype\fR is \fBM_DATA\fR, \fBM_PROTO\fR, or \fBM_PCPROTO\fR, or if a message block cannot be allocated. If successful, \fBputctl()\fR calls the \fBput\fR(9E) routine of the queue pointed to by \fIq\fR with the newly allocated and initialized messages. .SH RETURN VALUES .sp .LP On success, \fB1\fR is returned. If \fItype\fR is a data type, or if a message block cannot be allocated, \fB0\fR is returned. .SH CONTEXT .sp .LP The \fBputctl()\fR function can be called from user, interrupt, or kernel context. .SH EXAMPLES .LP \fBExample 1 \fRUsing \fBputctl()\fR .sp .LP The \fBsend_ctl()\fR routine is used to pass control messages downstream. \fBM_BREAK\fR messages are handled with \fBputctl()\fR (line 11). \fBputctl1\fR(9F) (line 16) is used for \fBM_DELAY\fR messages, so that \fIparm\fR can be used to specify the length of the delay. In either case, if a message block cannot be allocated a variable recording the number of allocation failures is incremented (lines 12, 17). If an invalid message type is detected, \fBcmn_err\fR(9F) panics the system (line 21). .sp .in +2 .nf 1 void 2 send_ctl(wrq, type, parm) 3 queue_t *wrq; 4 uchar_t type; 5 uchar_t parm; 6 { 7 extern int num_alloc_fail; 8 9 switch (type) { 10 case M_BREAK: 11 if (!putctl(wrq->q_next, M_BREAK)) 12 num_alloc_fail++; 13 break; 14 15 case M_DELAY: 16 if (!putctl1(wrq->q_next, M_DELAY, parm)) 17 num_alloc_fail++; 18 break; 19 20 default: 21 cmn_err(CE_PANIC, "send_ctl: bad message type passed"); 22 break; 23 } 24 } .fi .in -2 .SH SEE ALSO .sp .LP \fBput\fR(9E), \fBcmn_err\fR(9F), \fBdatamsg\fR(9F), \fBputctl1\fR(9F), \fBputnextctl\fR(9F) .sp .LP \fIWriting Device Drivers\fR .sp .LP \fISTREAMS Programming Guide\fR