OSDN Git Service

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