Debian Codegraph @

upstream/debian-unstable/man3/sockatmark.3

raw
1 '\" t
2 .\" Copyright 2006, Michael Kerrisk <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH sockatmark 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 sockatmark \- determine whether socket is at out-of-band mark
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <sys/socket.h>
16 .P
17 .BI "int sockatmark(int " sockfd );
18 .fi
19 .P
20 .RS -4
21 Feature Test Macro Requirements for glibc (see
22 .BR feature_test_macros (7)):
23 .RE
24 .P
25 .BR sockatmark ():
26 .nf
27 _POSIX_C_SOURCE >= 200112L
28 .fi
29 .SH DESCRIPTION
30 .BR sockatmark ()
31 returns a value indicating whether or not the socket referred
32 to by the file descriptor
33 .I sockfd
34 is at the out-of-band mark.
35 If the socket is at the mark, then 1 is returned;
36 if the socket is not at the mark, 0 is returned.
37 This function does not remove the out-of-band mark.
38 .SH RETURN VALUE
39 A successful call to
40 .BR sockatmark ()
41 returns 1 if the socket is at the out-of-band mark, or 0 if it is not.
42 On error, \-1 is returned and
43 .I errno
44 is set to indicate the error.
45 .SH ERRORS
46 .TP
47 .B EBADF
48 .I sockfd
49 is not a valid file descriptor.
50 .TP
51 .B EINVAL
52 .\" POSIX.1 says ENOTTY for this case
53 .I sockfd
54 is not a file descriptor to which
55 .BR sockatmark ()
56 can be applied.
57 .SH ATTRIBUTES
58 For an explanation of the terms used in this section, see
59 .BR attributes (7).
60 .TS
61 allbox;
62 lbx lb lb
63 l l l.
64 Interface Attribute Value
65 T{
66 .na
67 .nh
68 .BR sockatmark ()
69 T} Thread safety MT-Safe
70 .TE
71 .SH STANDARDS
72 POSIX.1-2008.
73 .SH HISTORY
74 glibc 2.2.4.
75 POSIX.1-2001.
76 .SH NOTES
77 If
78 .BR sockatmark ()
79 returns 1, then the out-of-band data can be read using the
80 .B MSG_OOB
81 flag of
82 .BR recv (2).
83 .P
84 Out-of-band data is supported only on some stream socket protocols.
85 .P
86 .BR sockatmark ()
87 can safely be called from a handler for the
88 .B SIGURG
89 signal.
90 .P
91 .BR sockatmark ()
92 is implemented using the
93 .B SIOCATMARK
94 .BR ioctl (2)
95 operation.
96 .SH BUGS
97 Prior to glibc 2.4,
98 .BR sockatmark ()
99 did not work.
100 .SH EXAMPLES
101 The following code can be used after receipt of a
102 .B SIGURG
103 signal to read (and discard) all data up to the mark,
104 and then read the byte of data at the mark:
105 .P
106 .EX
107 char buf[BUF_LEN];
108 char oobdata;
109 int atmark, s;
110 \&
111 for (;;) {
112 atmark = sockatmark(sockfd);
113 if (atmark == \-1) {
114 perror("sockatmark");
115 break;
116 }
117 \&
118 if (atmark)
119 break;
120 \&
121 s = read(sockfd, buf, BUF_LEN);
122 if (s == \-1)
123 perror("read");
124 if (s <= 0)
125 break;
126 }
127 \&
128 if (atmark == 1) {
129 if (recv(sockfd, &oobdata, 1, MSG_OOB) == \-1) {
130 perror("recv");
131 ...
132 }
133 }
134 .EE
135 .SH SEE ALSO
136 .BR fcntl (2),
137 .BR recv (2),
138 .BR send (2),
139 .BR tcp (7)