xref: /dragonfly/lib/libc/net/sockatmark.3 (revision 1b722dce)
1.\" Copyright (c) 2002 William C. Fenner.  All rights reserved.
2.\"
3.\" Redistribution and use in source and binary forms, with or without
4.\" modification, are permitted provided that the following conditions
5.\" are met:
6.\" 1. Redistributions of source code must retain the above copyright
7.\"    notice, this list of conditions and the following disclaimer.
8.\" 2. Redistributions in binary form must reproduce the above copyright
9.\"    notice, this list of conditions and the following disclaimer in the
10.\"    documentation and/or other materials provided with the distribution.
11.\"
12.\" THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
13.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
16.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22.\" SUCH DAMAGE.
23.\"
24.\" $FreeBSD: src/lib/libc/net/sockatmark.3,v 1.4 2002/12/19 09:40:22 ru Exp $
25.\"
26.Dd October 13, 2002
27.Dt SOCKATMARK 3
28.Os
29.Sh NAME
30.Nm sockatmark
31.Nd determine whether the read pointer is at the OOB mark
32.Sh LIBRARY
33.Lb libc
34.Sh SYNOPSIS
35.In sys/socket.h
36.Ft int
37.Fn sockatmark "int s"
38.Sh DESCRIPTION
39To find out if the read pointer is currently pointing at
40the mark in the data stream, the
41.Fn sockatmark
42function is provided.
43If
44.Fn sockatmark
45returns 1, the next read will return data
46after the mark.
47Otherwise (assuming out of band data has arrived),
48the next read will provide data sent by the client prior
49to transmission of the out of band signal.
50The routine used
51in the remote login process to flush output on receipt of an
52interrupt or quit signal is shown below.
53It reads the normal data up to the mark (to discard it),
54then reads the out-of-band byte.
55.Bd -literal -offset indent
56#include <sys/socket.h>
57\&...
58void
59oob(void)
60{
61	int out = FWRITE, mark;
62	char waste[BUFSIZ];
63
64	/* flush local terminal output */
65	ioctl(1, TIOCFLUSH, (char *)&out);
66	for (;;) {
67		if ((mark = sockatmark(rem)) < 0) {
68			perror("sockatmark");
69			break;
70		}
71		if (mark)
72			break;
73		read(rem, waste, sizeof (waste));
74	}
75	if (recv(rem, &mark, 1, MSG_OOB) < 0) {
76		perror("recv");
77		...
78	}
79	...
80}
81.Ed
82.Sh RETURN VALUES
83Upon successful completion, the
84.Fn sockatmark
85function returns the value 1 if the read pointer is pointing at
86the OOB mark, 0 if it is not.
87Otherwise the value \-1 is returned
88and the global variable
89.Va errno
90is set to
91indicate the error.
92.Sh ERRORS
93The
94.Fn sockatmark
95call fails if:
96.Bl -tag -width Er
97.It Bq Er EBADF
98The
99.Fa s
100argument
101is not a valid descriptor.
102.It Bq Er ENOTTY
103The
104.Fa s
105argument
106is a descriptor for a file, not a socket.
107.El
108.Sh SEE ALSO
109.Xr recv 2 ,
110.Xr send 2
111.Sh HISTORY
112The
113.Fn sockatmark
114function was introduced by
115.St -p1003.1-2001 ,
116to standardize the historical
117.Dv SIOCATMARK
118.Xr ioctl 2 .
119The
120.Er ENOTTY
121error instead of the usual
122.Er ENOTSOCK
123is to match the historical behavior of
124.Dv SIOCATMARK .
125