<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- permission is obtained from the copyright holder. -->
|
<!-- permission is obtained from the copyright holder. -->
|
<HTML
|
<HTML
|
><HEAD
|
><HEAD
|
><TITLE
|
><TITLE
|
>accept</TITLE
|
>accept</TITLE
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
<META
|
<META
|
NAME="GENERATOR"
|
NAME="GENERATOR"
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
"><LINK
|
"><LINK
|
REL="HOME"
|
REL="HOME"
|
TITLE="eCos Reference Manual"
|
TITLE="eCos Reference Manual"
|
HREF="ecos-ref.html"><LINK
|
HREF="ecos-ref.html"><LINK
|
REL="UP"
|
REL="UP"
|
TITLE="TCP/IP Library Reference"
|
TITLE="TCP/IP Library Reference"
|
HREF="tcpip-library-reference.html"><LINK
|
HREF="tcpip-library-reference.html"><LINK
|
REL="PREVIOUS"
|
REL="PREVIOUS"
|
TITLE="resolver"
|
TITLE="resolver"
|
HREF="net-common-tcpip-manpages-resolver.html"><LINK
|
HREF="net-common-tcpip-manpages-resolver.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="bind"
|
TITLE="bind"
|
HREF="net-common-tcpip-manpages-bind.html"></HEAD
|
HREF="net-common-tcpip-manpages-bind.html"></HEAD
|
><BODY
|
><BODY
|
CLASS="SECT1"
|
CLASS="SECT1"
|
BGCOLOR="#FFFFFF"
|
BGCOLOR="#FFFFFF"
|
TEXT="#000000"
|
TEXT="#000000"
|
LINK="#0000FF"
|
LINK="#0000FF"
|
VLINK="#840084"
|
VLINK="#840084"
|
ALINK="#0000FF"
|
ALINK="#0000FF"
|
><DIV
|
><DIV
|
CLASS="NAVHEADER"
|
CLASS="NAVHEADER"
|
><TABLE
|
><TABLE
|
SUMMARY="Header navigation table"
|
SUMMARY="Header navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TH
|
><TH
|
COLSPAN="3"
|
COLSPAN="3"
|
ALIGN="center"
|
ALIGN="center"
|
>eCos Reference Manual</TH
|
>eCos Reference Manual</TH
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-resolver.html"
|
HREF="net-common-tcpip-manpages-resolver.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="80%"
|
WIDTH="80%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
>Chapter 38. TCP/IP Library Reference</TD
|
>Chapter 38. TCP/IP Library Reference</TD
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-bind.html"
|
HREF="net-common-tcpip-manpages-bind.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"></DIV
|
WIDTH="100%"></DIV
|
><DIV
|
><DIV
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><H1
|
><H1
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><A
|
><A
|
NAME="NET-COMMON-TCPIP-MANPAGES-ACCEPT">accept</H1
|
NAME="NET-COMMON-TCPIP-MANPAGES-ACCEPT">accept</H1
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="SCREEN"
|
CLASS="SCREEN"
|
>ACCEPT(2) System Calls Manual ACCEPT(2)
|
>ACCEPT(2) System Calls Manual ACCEPT(2)
|
|
|
NAME
|
NAME
|
accept - accept a connection on a socket
|
accept - accept a connection on a socket
|
|
|
SYNOPSIS
|
SYNOPSIS
|
#include <sys/types.h>
|
#include <sys/types.h>
|
#include <sys/socket.h>
|
#include <sys/socket.h>
|
|
|
int
|
int
|
accept(int s, struct sockaddr *addr, socklen_t *addrlen);
|
accept(int s, struct sockaddr *addr, socklen_t *addrlen);
|
|
|
DESCRIPTION
|
DESCRIPTION
|
The argument s is a socket that has been created with socket(2), bound to
|
The argument s is a socket that has been created with socket(2), bound to
|
an address with bind(2), and is listening for connections after a
|
an address with bind(2), and is listening for connections after a
|
listen(2). The accept() argument extracts the first connection request
|
listen(2). The accept() argument extracts the first connection request
|
on the queue of pending connections, creates a new socket with the same
|
on the queue of pending connections, creates a new socket with the same
|
properties of s, and allocates a new file descriptor for the socket. If
|
properties of s, and allocates a new file descriptor for the socket. If
|
no pending connections are present on the queue, and the socket is not
|
no pending connections are present on the queue, and the socket is not
|
marked as non-blocking, accept() blocks the caller until a connection is
|
marked as non-blocking, accept() blocks the caller until a connection is
|
present. If the socket is marked non-blocking and no pending connections
|
present. If the socket is marked non-blocking and no pending connections
|
are present on the queue, accept() returns an error as described below.
|
are present on the queue, accept() returns an error as described below.
|
The accepted socket may not be used to accept more connections. The
|
The accepted socket may not be used to accept more connections. The
|
original socket s remains open.
|
original socket s remains open.
|
|
|
The argument addr is a result parameter that is filled in with the
|
The argument addr is a result parameter that is filled in with the
|
address of the connecting entity as known to the communications layer.
|
address of the connecting entity as known to the communications layer.
|
The exact format of the addr parameter is determined by the domain in
|
The exact format of the addr parameter is determined by the domain in
|
which the communication is occurring. The addrlen is a value-result
|
which the communication is occurring. The addrlen is a value-result
|
parameter; it should initially contain the amount of space pointed to by
|
parameter; it should initially contain the amount of space pointed to by
|
addr; on return it will contain the actual length (in bytes) of the
|
addr; on return it will contain the actual length (in bytes) of the
|
address returned. This call is used with connection-based socket types,
|
address returned. This call is used with connection-based socket types,
|
currently with SOCK_STREAM.
|
currently with SOCK_STREAM.
|
|
|
It is possible to select(2) or poll(2) a socket for the purposes of doing
|
It is possible to select(2) or poll(2) a socket for the purposes of doing
|
an accept() by selecting it for read.
|
an accept() by selecting it for read.
|
|
|
For certain protocols which require an explicit confirmation, such as ISO
|
For certain protocols which require an explicit confirmation, such as ISO
|
or DATAKIT, accept() can be thought of as merely dequeuing the next con-
|
or DATAKIT, accept() can be thought of as merely dequeuing the next con-
|
nection request and not implying confirmation. Confirmation can be
|
nection request and not implying confirmation. Confirmation can be
|
implied by a normal read or write on the new file descriptor, and rejec-
|
implied by a normal read or write on the new file descriptor, and rejec-
|
tion can be implied by closing the new socket.
|
tion can be implied by closing the new socket.
|
|
|
One can obtain user connection request data without confirming the con-
|
One can obtain user connection request data without confirming the con-
|
nection by issuing a recvmsg(2) call with an msg_iovlen of 0 and a non-
|
nection by issuing a recvmsg(2) call with an msg_iovlen of 0 and a non-
|
zero msg_controllen, or by issuing a getsockopt(2) request. Similarly,
|
zero msg_controllen, or by issuing a getsockopt(2) request. Similarly,
|
one can provide user connection rejection information by issuing a
|
one can provide user connection rejection information by issuing a
|
sendmsg(2) call with providing only the control information, or by call-
|
sendmsg(2) call with providing only the control information, or by call-
|
ing setsockopt(2).
|
ing setsockopt(2).
|
|
|
RETURN VALUES
|
RETURN VALUES
|
The call returns -1 on error. If it succeeds, it returns a non-negative
|
The call returns -1 on error. If it succeeds, it returns a non-negative
|
integer that is a descriptor for the accepted socket.
|
integer that is a descriptor for the accepted socket.
|
|
|
ERRORS
|
ERRORS
|
The accept() will fail if:
|
The accept() will fail if:
|
|
|
[EBADF] The descriptor is invalid.
|
[EBADF] The descriptor is invalid.
|
|
|
[ENOTSOCK] The descriptor references a file, not a socket.
|
[ENOTSOCK] The descriptor references a file, not a socket.
|
|
|
[EOPNOTSUPP] The referenced socket is not of type SOCK_STREAM.
|
[EOPNOTSUPP] The referenced socket is not of type SOCK_STREAM.
|
|
|
[EINVAL] The referenced socket is not listening for connections
|
[EINVAL] The referenced socket is not listening for connections
|
(that is, listen(2) has not yet been called).
|
(that is, listen(2) has not yet been called).
|
|
|
[EFAULT] The addr parameter is not in a writable part of the
|
[EFAULT] The addr parameter is not in a writable part of the
|
user address space.
|
user address space.
|
|
|
[EWOULDBLOCK] The socket is marked non-blocking and no connections
|
[EWOULDBLOCK] The socket is marked non-blocking and no connections
|
are present to be accepted.
|
are present to be accepted.
|
|
|
[EMFILE] The per-process descriptor table is full.
|
[EMFILE] The per-process descriptor table is full.
|
|
|
[ENFILE] The system file table is full.
|
[ENFILE] The system file table is full.
|
|
|
[ECONNABORTED] A connection has been aborted.
|
[ECONNABORTED] A connection has been aborted.
|
|
|
SEE ALSO
|
SEE ALSO
|
bind(2), connect(2), listen(2), poll(2), select(2), poll(2), socket(2)
|
bind(2), connect(2), listen(2), poll(2), select(2), poll(2), socket(2)
|
|
|
HISTORY
|
HISTORY
|
The accept() function appeared in 4.2BSD.
|
The accept() function appeared in 4.2BSD.
|
|
|
BSD February 15, 1999 BSD
|
BSD February 15, 1999 BSD
|
</PRE
|
</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="NAVFOOTER"
|
CLASS="NAVFOOTER"
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"><TABLE
|
WIDTH="100%"><TABLE
|
SUMMARY="Footer navigation table"
|
SUMMARY="Footer navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-resolver.html"
|
HREF="net-common-tcpip-manpages-resolver.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="ecos-ref.html"
|
HREF="ecos-ref.html"
|
ACCESSKEY="H"
|
ACCESSKEY="H"
|
>Home</A
|
>Home</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-bind.html"
|
HREF="net-common-tcpip-manpages-bind.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
>resolver</TD
|
>resolver</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="tcpip-library-reference.html"
|
HREF="tcpip-library-reference.html"
|
ACCESSKEY="U"
|
ACCESSKEY="U"
|
>Up</A
|
>Up</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
>bind</TD
|
>bind</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|