OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / original / man3 / sockatmark.3
1 .\" Copyright (c) 2006, Michael Kerrisk (mtk.manpages@gmail.com)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .TH SOCKATMARK 3 2008-12-03 "Linux" "Linux Programmer's Manual"
24 .SH NAME
25 sockatmark \- determine whether socket is at out-of-band mark
26 .SH SYNOPSIS
27 .B #include <sys/socket.h>
28 .sp
29 .BI "int sockatmark(int " sockfd );
30 .sp
31 .in -4n
32 Feature Test Macro Requirements for glibc (see
33 .BR feature_test_macros (7)):
34 .in
35 .sp
36 .ad l
37 .BR sockatmark ():
38 _POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600
39 .ad b
40 .SH DESCRIPTION
41 .BR sockatmark ()
42 returns a value indicating whether or not the socket referred
43 to by the file descriptor
44 .I sockfd
45 is at the out-of-band mark.
46 If the socket is at the mark, then 1 is returned;
47 if the socket is not at the mark, 0 is returned.
48 This function does not remove the out-of-band mark.
49 .SH "RETURN VALUE"
50 A successful call to
51 .BR sockatmark ()
52 returns 1 if the socket is at the out-of-band mark, or 0 if it is not.
53 On error, \-1 is returned and \fIerrno\fP is set to indicate the error.
54 .SH ERRORS
55 .TP
56 .B EBADF
57 .I sockfd
58 is not a valid file descriptor.
59 .TP
60 .B EINVAL
61 .\" POSIX.1 says ENOTTY for this case
62 .I sockfd
63 is not a file descriptor to which
64 .BR sockatmark ()
65 can be applied.
66 .SH VERSIONS
67 .BR sockatmark ()
68 was added to glibc in version 2.2.4.
69 .SH "CONFORMING TO"
70 POSIX.1-2001.
71 .SH NOTES
72 If
73 .BR sockatmark ()
74 returns 1, then the out-of-band data can be read using the
75 .B MSG_OOB
76 flag of
77 .BR recv (2).
78
79 Out-of-band data is only supported on some stream socket protocols.
80
81 .BR sockatmark ()
82 can safely be called from a handler for the
83 .B SIGURG
84 signal.
85
86 .BR sockatmark ()
87 is implemented using the
88 .B SIOCATMARK
89 .BR ioctl (2)
90 operation.
91 .SH BUGS
92 Prior to glibc 2.4,
93 .BR sockatmark ()
94 did not work.
95 .SH EXAMPLE
96 The following code can be used after receipt of a
97 .B SIGURG
98 signal to read (and discard) all data up to the mark,
99 and then read the byte of data at the mark:
100 .nf
101
102     char buf[BUF_LEN];
103     char oobdata;
104     int atmark, s;
105
106     for (;;) {
107         atmark = sockatmark(sockfd);
108         if (atmark == \-1) {
109             perror("sockatmark");
110             break;
111         }
112
113         if (atmark)
114             break;
115
116         s = read(sockfd, buf, BUF_LEN) <= 0);
117         if (s == \-1)
118             perror("read");
119         if (s <= 0)
120             break;
121     }
122
123     if (atmark == 1) {
124         if (recv(sockfd, &oobdata, 1, MSG_OOB) == \-1) {
125             perror("recv");
126             ...
127         }
128     }
129 .fi
130 .SH "SEE ALSO"
131 .BR fcntl (2),
132 .BR recv (2),
133 .BR send (2),
134 .BR tcp (7)