Merge commit '9276b3991ba20d5a5660887ba81b0bc7bed25a0c'
[unleashed.git] / share / man / man9f / putctl.9f
blobc0ba830f3e09567bea53b331ab0c048fdc1f86d1
1 '\" te
2 .\"  Copyright 1989 AT&T
3 .\"  Copyright (c) 2006, Sun Microsystems, Inc.,  All Rights Reserved
4 .\" 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.
5 .\" 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.
6 .\" 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]
7 .TH PUTCTL 9F "Jan 16, 2006"
8 .SH NAME
9 putctl \- send a control message to a queue
10 .SH SYNOPSIS
11 .LP
12 .nf
13 #include <sys/stream.h>
17 \fBint\fR \fBputctl\fR(\fBqueue_t *\fR\fIq\fR, \fBint\fR \fItype\fR);
18 .fi
20 .SH INTERFACE LEVEL
21 .sp
22 .LP
23 Architecture independent level 1 (DDI/DKI).
24 .SH PARAMETERS
25 .sp
26 .ne 2
27 .na
28 \fB\fIq\fR\fR
29 .ad
30 .RS 8n
31 Queue to which the message is to be sent.
32 .RE
34 .sp
35 .ne 2
36 .na
37 \fB\fItype\fR\fR
38 .ad
39 .RS 8n
40 Message type (must be control, not data type).
41 .RE
43 .SH DESCRIPTION
44 .sp
45 .LP
46 The \fBputctl()\fR function tests the \fItype\fR argument to make sure a data
47 type has not been specified, and then attempts to allocate a message block.
48 \fBputctl()\fR fails if \fItype\fR is \fBM_DATA\fR, \fBM_PROTO\fR, or
49 \fBM_PCPROTO\fR, or if a message block cannot be allocated. If successful,
50 \fBputctl()\fR calls the \fBput\fR(9E) routine of the queue pointed to by
51 \fIq\fR with the newly allocated and initialized messages.
52 .SH RETURN VALUES
53 .sp
54 .LP
55 On success, \fB1\fR is returned. If \fItype\fR is a data type, or if a message
56 block cannot be allocated, \fB0\fR is returned.
57 .SH CONTEXT
58 .sp
59 .LP
60 The \fBputctl()\fR function can be called from user, interrupt, or kernel
61 context.
62 .SH EXAMPLES
63 .LP
64 \fBExample 1 \fRUsing \fBputctl()\fR
65 .sp
66 .LP
67 The \fBsend_ctl()\fR routine is used to pass control messages downstream.
68 \fBM_BREAK\fR messages are handled with \fBputctl()\fR (line 11).
69 \fBputctl1\fR(9F) (line 16) is used for \fBM_DELAY\fR messages, so that
70 \fIparm\fR can be used to specify the length of the delay. In either case, if a
71 message block cannot be allocated a variable recording the number of allocation
72 failures is incremented (lines 12, 17). If an invalid message type is detected,
73 \fBcmn_err\fR(9F) panics the system (line 21).
75 .sp
76 .in +2
77 .nf
78 1  void
79  2  send_ctl(wrq, type, parm)
80  3      queue_t *wrq;
81  4      uchar_t type;
82  5      uchar_t parm;
83  6  {
84  7            extern int num_alloc_fail;
85  8
86  9       switch (type) {
87 10            case M_BREAK:
88 11             if (!putctl(wrq->q_next, M_BREAK))
89 12                      num_alloc_fail++;
90 13                  break;
92 15       case M_DELAY:
93 16             if (!putctl1(wrq->q_next, M_DELAY, parm))
94 17                      num_alloc_fail++;
95 18             break;
97 20       default:
98 21             cmn_err(CE_PANIC, "send_ctl: bad message type passed");
99 22                  break;
100 23            }
101 24  }
103 .in -2
105 .SH SEE ALSO
108 \fBput\fR(9E), \fBcmn_err\fR(9F), \fBdatamsg\fR(9F), \fBputctl1\fR(9F),
109 \fBputnextctl\fR(9F)
112 \fIWriting Device Drivers\fR
115 \fISTREAMS Programming Guide\fR