system call is unmount not umount
[unix-history] / usr / src / lib / libc / sys / accept.2
CommitLineData
da268306
KB
1.\" Copyright (c) 1983 The Regents of the University of California.
2.\" All rights reserved.
95f52c01 3.\"
da268306
KB
4.\" Redistribution and use in source and binary forms are permitted
5.\" provided that the above copyright notice and this paragraph are
6.\" duplicated in all such forms and that any documentation,
7.\" advertising materials, and other materials related to such
8.\" distribution and use acknowledge that the software was developed
9.\" by the University of California, Berkeley. The name of the
10.\" University may not be used to endorse or promote products derived
11.\" from this software without specific prior written permission.
12.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15.\"
16.\" @(#)accept.2 6.4 (Berkeley) %G%
95f52c01 17.\"
f850922e 18.TH ACCEPT 2 ""
95f52c01
KM
19.UC 5
20.SH NAME
21accept \- accept a connection on a socket
22.SH SYNOPSIS
23.ft B
24.nf
25#include <sys/types.h>
26#include <sys/socket.h>
27.PP
28.ft B
29ns = accept(s, addr, addrlen)
30int ns, s;
31struct sockaddr *addr;
32int *addrlen;
33.fi
34.SH DESCRIPTION
35The argument
36.I s
a9f72a26 37is a socket that has been created with
95f52c01
KM
38.IR socket (2),
39bound to an address with
40.IR bind (2),
41and is listening for connections after a
42.IR listen (2).
43.I Accept
44extracts the first connection
45on the queue of pending connections, creates
46a new socket with the same properties of
47.I s
48and allocates a new file descriptor,
49.IR ns ,
50for the socket. If no pending connections are
51present on the queue, and the socket is not marked
52as non-blocking,
53.I accept
54blocks the caller until a connection is present.
55If the socket is marked non-blocking and no pending
56connections are present on the queue,
57.I accept
58returns an error as described below.
59The accepted socket,
60.IR ns ,
61may not be used
62to accept more connections. The original socket
63.I s
64remains open.
65.PP
66The argument
67.I addr
a9f72a26 68is a result parameter that is filled in with
95f52c01
KM
69the address of the connecting entity,
70as known to the communications layer.
71The exact format of the
72.I addr
73parameter is determined by the domain in which the communication
74is occurring.
75The
76.I addrlen
77is a value-result parameter; it should initially contain the
78amount of space pointed to by
79.IR addr ;
80on return it will contain the actual length (in bytes) of the
81address returned.
82This call
83is used with connection-based socket types, currently with SOCK_STREAM.
84.PP
85It is possible to
86.IR select (2)
87a socket for the purposes of doing an
88.I accept
89by selecting it for read.
90.SH "RETURN VALUE
bdad3a5a 91The call returns \-1 on error. If it succeeds, it returns a non-negative
a9f72a26 92integer that is a descriptor for the accepted socket.
95f52c01
KM
93.SH ERRORS
94The \fIaccept\fP will fail if:
95.TP 20
96[EBADF]
97The descriptor is invalid.
98.TP 20
99[ENOTSOCK]
100The descriptor references a file, not a socket.
101.TP 20
102[EOPNOTSUPP]
103The referenced socket is not of type SOCK_STREAM.
104.TP 20
105[EFAULT]
106The \fIaddr\fP parameter is not in a writable part of the
107user address space.
108.TP 20
109[EWOULDBLOCK]
110The socket is marked non-blocking and no connections
111are present to be accepted.
112.SH SEE ALSO
113bind(2), connect(2), listen(2), select(2), socket(2)