File: mq_notify.3

package info (click to toggle)
manpages-ja 0.5.0.0.20061115-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 19,788 kB
  • ctags: 4
  • sloc: sh: 13,215; perl: 157; makefile: 117
file content (262 lines) | stat: -rw-r--r-- 7,530 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
'\" t
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Copyright (C) 2006 Michael Kerrisk <mtk-manpages@gmx.net>
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\" 
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein.  
.\" 
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI all rights reserved.
.\" Translated 2006-07-31, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\"
.TH MQ_NOTIFY 3 2006-02-25 "Linux 2.6.16" "Linux Programmer's Manual"
.SH ̾
mq_notify \- åΤԤ褦Ͽ
.SH 
.nf
.B #include <mqueue.h>
.sp
.BI "mqd_t mq_notify(mqd_t " mqdes ", const struct sigevent *" notification );
.fi
.SH 
.BR mq_notify ()
Ȥȡǥץ
.I mqdes
ǻȤΥå塼˿å夷
Ʊ (notification) Ͽ/ԤȤǤ롣

.I notification

.I sigevent
¤ΤؤΥݥ󥿤Ǥ롣
.I sigevent
¤ΤϰʲΤ褦ʴƤ:
.in +0.25i
.nf

union sigval {                /* Data passed with notification */
    int     sival_int;        /* Integer value */
    void   *sival_ptr;        /* Pointer value */
};

struct sigevent {
    int    sigev_notify;      /* Notification method */
    int    sigev_signo;       /* Notification signal */
    union sigval sigev_value; /* Data passed with notification */
    void (*sigev_notify_function) (union sigval);
                              /* Function for thread notification */
    void  *sigev_notify_attributes;
                              /* Thread function attributes */
};
.fi
.in -0.25i
.PP
.I notification
 NULL Ǥʤݥ󥿤ǤС
.BR mq_notify ()
ϥåΤ褦˸ƤӽФΥץϿ롣
.I notification
ؤ
.I sigevent

.I sigev_notify
եɤϡɤΤ褦ΤԤΤꤹ롣
ΥեɤϰʲͤΤ줫ġ
.TP
.B SIGEV_NONE
ֶ (null)פ: ƤӽФΥץΤΰȤϿ뤬
ºݤˤϥå夷Τʤ
.\" When is SIGEV_NONE useful?
.TP
.B SIGEV_SIGNAL
.I sigev_signo
ǻꤵ줿ʥäơץΤ롣
.BR sigaction (2)

.B SA_SIGINFO
ե饰Ͽ줿ʥϥɥǤΥʥ뤬ª줿硢
ʥϥɥȤϤ
.I siginfo_t
¤ΤγƥեɤϰʲΤ褦ꤵ롣
.I si_code
ˤ
.B SI_MESGQ
ꤵ롣
.I si_signo
ˤϥʥֹ椬ꤵ롣
.I si_value
ˤ
.I notification->sigev_value
ǻꤷͤꤵ롣
.\" I don't know of other implementations that set
.\" si_pid and si_uid -- MTK
.I si_pid
ˤϥåץ PID 
.I si_uid
ˤץμ¥桼 ID ꤵ롣
.BR sigwaitinfo (2)
Ȥäƥʥ⡢Ʊ롣
.TP
.B SIGEV_THREAD
åɤγϴؿȤ
.I notification->sigev_thread_function
ư뤳ȤΤԤ
ưδؿΰȤƤ
.I notification->sigev_value
Ϥ롣
.I notification->sigev_notify_attributes
ϡNULL ʳξ硢
Υåɤ°
.I pthread_attr_t
¤ΤؤΥݥ󥿤ȤʤäƤɬפ롣
.\" FIXME . add a cross reference to pthread_attr_init(3), when
.\" that page is one day written.
.PP
ĤΥå塼Τ褦ϿǤץ
ĤǤ롣

.I notification
 NULL ǡĸƤӽФΥץΥå塼
Τ˸ϿƤ硢Ͽ롣
ʹߡ̤ΥץΥå塼Τ褦
ϿǤ褦ˤʤ롣

åΤϡޤǶΥ塼˿å夷
ˤΤ߹Ԥ롣
.BR mq_notify ()
ƤӽФ줿ˤΥ塼Ǥʤ硢
Υ塼ˤʤꡢθ忷å夷
ΤԤ뤳Ȥˤʤ롣

̤Υץ䥹åɤ
.BR mq_receive ()
ȤäơΥ塼åɤ߽ФԤäƤ硢
åΤϿ̵뤵롣
å
.BR mq_receive ()
ƤӽФƤץ䥹åɤ졢
åΤϿϸϤäޤޤȤʤ롣

Τϰ٤Ԥ롣Τ줿ϡ׵ϿϺ졢
̤ΥץåΤ褦ϿǤ褦ˤʤ롣
ΤץΤϡ
.BR mq_notify ()
ȤäƤθΤ褦׵᤹뤳ȤǤ롣
.BR mq_notify ()
ٸƤӽФΤϡɤ߽ФƤʤåɤ߽Ф
塼ˤʤˤ٤Ǥ
(塼Υåɤ߽Ф򥭥塼ˤʤä
 (block) ˹Ԥˤϡ塼ߥ⡼ (non-blocking mode)
ꤷƤȤ褤)
.SH ֤
ȡ
.BR mq_notify ()
 0 ֤顼ξ硢\-1 ֤
.I errno
򥨥顼򼨤ͤꤹ롣
.SH 顼
.TP
.B EBADF
.I mqdes
˻ꤵ줿ǥץǤ롣
.TP
.B EBUSY
̤ΥץǤ
Υå塼ФΤ褦ϿƤ롣
.TP
.B EINVAL
.I notification->sigev_notify
Ĥ줿ͤΤǤʤ⤷
.I notification->sigev_notify

.B SIGEV_SIGNAL

.I notification->sigev_signo
ͭʥʥֹǤϤʤ
.TP
.B ENOMEM
ɬפʥ꤬ʤä
.SH 
POSIX.1-2001.
.SH 
ʲΥץϡ
ޥɥ饤ǻꤵ줿̾Υå塼ؤ
׵ϿΤϥåɤκǹԤ롣
ΥåɤϡΥ塼åɤ߽ФƤ顢
ץλؿ¹Ԥ롣
.nf

#include <pthread.h>
#include <mqueue.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define die(msg) { perror(msg); exit(EXIT_FAILURE); }

static void                     /* åɳϴؿ */
tfunc(union sigval sv)
{
    struct mq_attr attr;
    ssize_t nr;
    void *buf;
    mqd_t mqdes = *((mqd_t *) sv.sival_ptr);

    /* åꤷ
       åѤΥХåեݤ */

    if (mq_getattr(mqdes, &attr) == -1) die("mq_getattr");
    buf = malloc(attr.mq_msgsize);
    if (buf == NULL) die("malloc");

    nr = mq_receive(mqdes, buf, attr.mq_msgsize, NULL);
    if (nr == -1) die("mq_receive");

    printf("Read %ld bytes from MQ\n", (long) nr);
    free(buf);
    exit(EXIT_SUCCESS);         /* ץλ */
}

int
main(int argc, char *argv[])
{
    mqd_t mqdes;
    struct sigevent not;

    assert(argc == 2);

    mqdes = mq_open(argv[1], O_RDONLY);
    if (mqdes == (mqd_t) -1) die("mq_open");

    not.sigev_notify = SIGEV_THREAD;
    not.sigev_notify_function = tfunc;
    not.sigev_notify_attributes = NULL;
    not.sigev_value.sival_ptr = &mqdes;   /* åɴؿϤ */
    if (mq_notify(mqdes, &not) == -1) die("mq_notify");

    pause();    /* ץϥåɴؿˤ꽪λ */
}
.fi
.SH Ϣ
.BR mq_close (3),
.BR mq_getattr (3),
.BR mq_open (3),
.BR mq_receive (3),
.BR mq_send (3),
.BR mq_unlink (3),
.BR mq_overview (7)