]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/sockatmark.3
log1p.3: Reformat thread-safety information
[thirdparty/man-pages.git] / man3 / sockatmark.3
CommitLineData
c11b1abf 1.\" Copyright (c) 2006, Michael Kerrisk (mtk.manpages@gmail.com)
21008754 2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
21008754
MK
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
10d76543
MK
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.
21008754
MK
20.\"
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
21008754 24.\"
662c4b2a 25.TH SOCKATMARK 3 2014-02-28 "Linux" "Linux Programmer's Manual"
21008754
MK
26.SH NAME
27sockatmark \- determine whether socket is at out-of-band mark
28.SH SYNOPSIS
29.B #include <sys/socket.h>
30.sp
c4e7b714 31.BI "int sockatmark(int " sockfd );
cc4615cc
MK
32.sp
33.in -4n
34Feature 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
21008754
MK
42.SH DESCRIPTION
43.BR sockatmark ()
c13182ef 44returns a value indicating whether or not the socket referred
21008754 45to by the file descriptor
c4e7b714 46.I sockfd
21008754
MK
47is at the out-of-band mark.
48If the socket is at the mark, then 1 is returned;
49if the socket is not at the mark, 0 is returned.
50This function does not remove the out-of-band mark.
47297adb 51.SH RETURN VALUE
21008754
MK
52A successful call to
53.BR sockatmark ()
54returns 1 if the socket is at the out-of-band mark, or 0 if it is not.
c6fa0841
MK
55On error, \-1 is returned and
56.I errno
57is set to indicate the error.
21008754
MK
58.SH ERRORS
59.TP
60.B EBADF
c4e7b714 61.I sockfd
21008754
MK
62is not a valid file descriptor.
63.TP
64.B EINVAL
65.\" POSIX.1 says ENOTTY for this case
c4e7b714 66.I sockfd
21008754
MK
67is not a file descriptor to which
68.BR sockatmark ()
69can be applied.
2b2581ee
MK
70.SH VERSIONS
71.BR sockatmark ()
72was added to glibc in version 2.2.4.
662c4b2a
PH
73.SH ATTRIBUTES
74.SS Multithreading (see pthreads(7))
75The
76.BR sockatmark ()
77function is thread-safe.
47297adb 78.SH CONFORMING TO
44a2c328 79POSIX.1-2001.
21008754
MK
80.SH NOTES
81If
82.BR sockatmark ()
c13182ef 83returns 1, then the out-of-band data can be read using the
21008754
MK
84.B MSG_OOB
85flag of
86.BR recv (2).
87
33a0ccb2 88Out-of-band data is supported only on some stream socket protocols.
21008754
MK
89
90.BR sockatmark ()
8bd58774
MK
91can safely be called from a handler for the
92.B SIGURG
93signal.
21008754
MK
94
95.BR sockatmark ()
c13182ef
MK
96is implemented using the
97.B SIOCATMARK
fb186734 98.BR ioctl (2)
21008754 99operation.
21008754
MK
100.SH BUGS
101Prior to glibc 2.4,
c13182ef 102.BR sockatmark ()
21008754
MK
103did not work.
104.SH EXAMPLE
8bd58774
MK
105The following code can be used after receipt of a
106.B SIGURG
107signal to read (and discard) all data up to the mark,
21008754
MK
108and then read the byte of data at the mark:
109.nf
110
111 char buf[BUF_LEN];
112 char oobdata;
113 int atmark, s;
114
115 for (;;) {
c4e7b714 116 atmark = sockatmark(sockfd);
21008754
MK
117 if (atmark == \-1) {
118 perror("sockatmark");
119 break;
c13182ef 120 }
7295b7ed 121
21008754
MK
122 if (atmark)
123 break;
c13182ef 124
c4e7b714 125 s = read(sockfd, buf, BUF_LEN) <= 0);
29059a65 126 if (s == \-1)
21008754 127 perror("read");
c13182ef 128 if (s <= 0)
21008754
MK
129 break;
130 }
c13182ef 131
21008754 132 if (atmark == 1) {
c4e7b714 133 if (recv(sockfd, &oobdata, 1, MSG_OOB) == \-1) {
21008754
MK
134 perror("recv");
135 ...
136 }
137 }
138.fi
47297adb 139.SH SEE ALSO
21008754
MK
140.BR fcntl (2),
141.BR recv (2),
142.BR send (2),
143.BR tcp (7)