|
|
1.1 ! root 1: .\" Copyright (c) 1983, 1990 The Regents of the University of California. ! 2: .\" All rights reserved. ! 3: .\" ! 4: .\" Redistribution and use in source and binary forms are permitted ! 5: .\" provided that: (1) source distributions retain this entire copyright ! 6: .\" notice and comment, and (2) distributions including binaries display ! 7: .\" the following acknowledgement: ``This product includes software ! 8: .\" developed by the University of California, Berkeley and its contributors'' ! 9: .\" in the documentation or other materials provided with the distribution ! 10: .\" and in all advertising materials mentioning features or use of this ! 11: .\" software. Neither the name of the University nor the names of its ! 12: .\" contributors may be used to endorse or promote products derived ! 13: .\" from this software without specific prior written permission. ! 14: .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 15: .\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 16: .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 17: .\" ! 18: .\" @(#)accept.2 6.5 (Berkeley) 5/30/90 ! 19: .\" ! 20: .TH ACCEPT 2 "May 30, 1990" ! 21: .UC 5 ! 22: .SH NAME ! 23: accept \- accept a connection on a socket ! 24: .SH SYNOPSIS ! 25: .ft B ! 26: .nf ! 27: #include <sys/types.h> ! 28: #include <sys/socket.h> ! 29: .PP ! 30: .ft B ! 31: ns = accept(s, addr, addrlen) ! 32: int ns, s; ! 33: struct sockaddr *addr; ! 34: int *addrlen; ! 35: .fi ! 36: .SH DESCRIPTION ! 37: The argument ! 38: .I s ! 39: is a socket that has been created with ! 40: .IR socket (2), ! 41: bound to an address with ! 42: .IR bind (2), ! 43: and is listening for connections after a ! 44: .IR listen (2). ! 45: .I Accept ! 46: extracts the first connection request ! 47: on the queue of pending connections, creates ! 48: a new socket with the same properties of ! 49: .I s ! 50: and allocates a new file descriptor, ! 51: .IR ns , ! 52: for the socket. If no pending connections are ! 53: present on the queue, and the socket is not marked ! 54: as non-blocking, ! 55: .I accept ! 56: blocks the caller until a connection is present. ! 57: If the socket is marked non-blocking and no pending ! 58: connections are present on the queue, ! 59: .I accept ! 60: returns an error as described below. ! 61: The accepted socket, ! 62: .IR ns , ! 63: may not be used ! 64: to accept more connections. The original socket ! 65: .I s ! 66: remains open. ! 67: .PP ! 68: The argument ! 69: .I addr ! 70: is a result parameter that is filled in with ! 71: the address of the connecting entity, ! 72: as known to the communications layer. ! 73: The exact format of the ! 74: .I addr ! 75: parameter is determined by the domain in which the communication ! 76: is occurring. ! 77: The ! 78: .I addrlen ! 79: is a value-result parameter; it should initially contain the ! 80: amount of space pointed to by ! 81: .IR addr ; ! 82: on return it will contain the actual length (in bytes) of the ! 83: address returned. ! 84: This call ! 85: is used with connection-based socket types, currently with SOCK_STREAM. ! 86: .PP ! 87: It is possible to ! 88: .IR select (2) ! 89: a socket for the purposes of doing an ! 90: .I accept ! 91: by selecting it for read. ! 92: .PP ! 93: For certain protocols which require an explicit confirmation, ! 94: such as ISO or DATAKIT, ! 95: one should think of accept as merely dequeueing the next connection ! 96: request, and not in of itself implying confirmation. ! 97: Confirmation can be implied by a normal read or write on the new ! 98: file desciptor, and rejection can be implied by closing the ! 99: new socket. ! 100: .PP ! 101: One can obtain user connection request data without confirming ! 102: the connection by issuing a ! 103: recvmsg call with an msg_iovlen of 0 and a non-zero ! 104: msg_controllen, or by issuing a ! 105: .IR getsockopt (2) ! 106: request. ! 107: Similarly, one can provide user connection rejection information ! 108: by issuing a sendmsg call with providing only the control information, ! 109: or by calling ! 110: .IR setsockopt (2). ! 111: .SH "RETURN VALUE ! 112: The call returns \-1 on error. If it succeeds, it returns a non-negative ! 113: integer that is a descriptor for the accepted socket. ! 114: .SH ERRORS ! 115: The \fIaccept\fP will fail if: ! 116: .TP 20 ! 117: [EBADF] ! 118: The descriptor is invalid. ! 119: .TP 20 ! 120: [ENOTSOCK] ! 121: The descriptor references a file, not a socket. ! 122: .TP 20 ! 123: [EOPNOTSUPP] ! 124: The referenced socket is not of type SOCK_STREAM. ! 125: .TP 20 ! 126: [EFAULT] ! 127: The \fIaddr\fP parameter is not in a writable part of the ! 128: user address space. ! 129: .TP 20 ! 130: [EWOULDBLOCK] ! 131: The socket is marked non-blocking and no connections ! 132: are present to be accepted. ! 133: .SH SEE ALSO ! 134: bind(2), connect(2), listen(2), select(2), socket(2)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.