]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/sockatmark.3
dlopen.3: tfix
[thirdparty/man-pages.git] / 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 2017-09-15 "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 .PP
31 .BI "int sockatmark(int " sockfd );
32 .PP
33 .in -4n
34 Feature Test Macro Requirements for glibc (see
35 .BR feature_test_macros (7)):
36 .in
37 .PP
38 .ad l
39 .BR sockatmark ():
40 _POSIX_C_SOURCE\ >=\ 200112L
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
56 .I errno
57 is set to indicate the error.
58 .SH ERRORS
59 .TP
60 .B EBADF
61 .I sockfd
62 is not a valid file descriptor.
63 .TP
64 .B EINVAL
65 .\" POSIX.1 says ENOTTY for this case
66 .I sockfd
67 is not a file descriptor to which
68 .BR sockatmark ()
69 can be applied.
70 .SH VERSIONS
71 .BR sockatmark ()
72 was added to glibc in version 2.2.4.
73 .SH ATTRIBUTES
74 For an explanation of the terms used in this section, see
75 .BR attributes (7).
76 .TS
77 allbox;
78 lb lb lb
79 l l l.
80 Interface Attribute Value
81 T{
82 .BR sockatmark ()
83 T} Thread safety MT-Safe
84 .TE
85 .SH CONFORMING TO
86 POSIX.1-2001, POSIX.1-2008.
87 .SH NOTES
88 If
89 .BR sockatmark ()
90 returns 1, then the out-of-band data can be read using the
91 .B MSG_OOB
92 flag of
93 .BR recv (2).
94 .PP
95 Out-of-band data is supported only on some stream socket protocols.
96 .PP
97 .BR sockatmark ()
98 can safely be called from a handler for the
99 .B SIGURG
100 signal.
101 .PP
102 .BR sockatmark ()
103 is implemented using the
104 .B SIOCATMARK
105 .BR ioctl (2)
106 operation.
107 .SH BUGS
108 Prior to glibc 2.4,
109 .BR sockatmark ()
110 did not work.
111 .SH EXAMPLE
112 The following code can be used after receipt of a
113 .B SIGURG
114 signal to read (and discard) all data up to the mark,
115 and then read the byte of data at the mark:
116 .PP
117 .EX
118 char buf[BUF_LEN];
119 char oobdata;
120 int atmark, s;
121
122 for (;;) {
123 atmark = sockatmark(sockfd);
124 if (atmark == \-1) {
125 perror("sockatmark");
126 break;
127 }
128
129 if (atmark)
130 break;
131
132 s = read(sockfd, buf, BUF_LEN);
133 if (s == \-1)
134 perror("read");
135 if (s <= 0)
136 break;
137 }
138
139 if (atmark == 1) {
140 if (recv(sockfd, &oobdata, 1, MSG_OOB) == \-1) {
141 perror("recv");
142 ...
143 }
144 }
145 .EE
146 .SH SEE ALSO
147 .BR fcntl (2),
148 .BR recv (2),
149 .BR send (2),
150 .BR tcp (7)