IceWalkers.com - Linux Software downloads and news
Name : Password :
Linux SoftwareLinux RPMLinux HowtosLink UsAboutAdvertise

accept (2)

ACCEPT(2)                  Linux Programmer's Manual                 ACCEPT(2)



NAME
       accept - accept a connection on a socket

SYNOPSIS
       #include<sys/types.h>
       #include<sys/socket.h>

       intaccept(int s,structsockaddr*addr,socklen_t*addrlen);

DESCRIPTION
       The   accept  function  is  used  with  connection-based  socket  types
       (SOCK_STREAM, SOCK_SEQPACKET and SOCK_RDM).  It extracts the first con-
       nection request on the queue of pending connections, creates a new con-
       nected socket with mostly the same properties as s, and allocates a new
       file  descriptor  for the socket, which is returned.  The newly created
       socket is no longer in the listening state.  The original socket  s  is
       unaffected  by  this  call.  Note  that  any  per file descriptor flags
       (everything that can be set with the F_SETFL fcntl, like  non  blocking
       or async state) are not inherited across an accept.

       The  argument s is a socket that has been created with socket(2), bound
       to a local address with bind(2), and is listening for connections after
       a listen(2).

       The  argument addr is a pointer to a sockaddr structure. This structure
       is filled in with the address of the connecting entity, as known to the
       communications  layer.   The  exact format of the address passed in the
       addr parameter is determined by the socket's family (see socket(2)  and
       the  respective  protocol man pages).  The addrlen argument is a value-
       result parameter: it should initially contain the size of the structure
       pointed  to  by  addr;  on return it will contain the actual length (in
       bytes) of the address returned. When addr is NULL nothing is filled in.

       If  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  present.   If the socket is marked non-blocking and no pending con-
       nections are present on the queue, accept returns EAGAIN.

       In order to be notified of incoming connections on a  socket,  you  can
       use  select(2)  or  poll(2).  A readable event will be delivered when a
       new connection is attempted and you may  then  call  accept  to  get  a
       socket  for  that connection.  Alternatively, you can set the socket to
       deliver SIGIO when activity occurs  on  a  socket;  see  socket(7)  for
       details.

       For  certain  protocols which require an explicit confirmation, such as
       DECNet, accept can be thought of as merely dequeuing the  next  connec-
       tion  request  and  not  implying  confirmation.   Confirmation  can be
       implied by a normal read or write  on  the  new  file  descriptor,  and
       rejection can be implied by closing the new socket. Currently only DEC-
       Net has these semantics on Linux.

NOTES
       There may not always be a connection waiting after a SIGIO is delivered
       or  select(2) or poll(2) return a readability event because the connec-
       tion might have been  removed  by  an  asynchronous  network  error  or
       another  thread before accept is called.  If this happens then the call
       will block waiting for the next connection to arrive.  To  ensure  that
       accept  never  blocks, the passed socket s needs to have the O_NONBLOCK
       flag set (see socket(7)).

RETURNVALUE
       The call returns -1 on error.  If it succeeds, it returns  a  non-nega-
       tive integer that is a descriptor for the accepted socket.

ERRORHANDLING
       Linux accept passes already-pending network errors on the new socket as
       an error code from accept.   This  behaviour  differs  from  other  BSD
       socket  implementations.  For reliable operation the application should
       detect the network errors defined for the  protocol  after  accept  and
       treat  them  like EAGAIN by retrying. In case of TCP/IP these are ENET-
       DOWN, EPROTO, ENOPROTOOPT, EHOSTDOWN, ENONET, EHOSTUNREACH, EOPNOTSUPP,
       and ENETUNREACH.

ERRORS
       accept shall fail if:

       EAGAIN or EWOULDBLOCK
              The socket is marked non-blocking and no connections are present
              to be accepted.

       EBADF  The descriptor is invalid.

       ENOTSOCK
              The descriptor references a file, not a socket.

       EOPNOTSUPP
              The referenced socket is not of type SOCK_STREAM.

       EINTR  The system call was interrupted by  a  signal  that  was  caught
              before a valid connection arrived.

       ECONNABORTED
              A connection has been aborted.

       EINVAL Socket is not listening for connections.

       EMFILE The per-process limit of open file descriptors has been reached.

       ENFILE The system maximum for file descriptors has been reached.

       accept may fail if:

       EFAULT The addr parameter is not in a writable part of the user address
              space.

       ENOBUFS,ENOMEM
              Not  enough free memory.  This often means that the memory allo-
              cation is limited by the socket buffer limits, not by the system
              memory.

       EPROTO Protocol error.

       Linux accept may fail if:

       EPERM  Firewall rules forbid connection.

       In  addition,  network errors for the new socket and as defined for the
       protocol may be returned. Various Linux kernels can return other errors
       such  as ENOSR, ESOCKTNOSUPPORT, EPROTONOSUPPORT, ETIMEDOUT.  The value
       ERESTARTSYS may be seen during a trace.

CONFORMINGTO
       SVr4, 4.4BSD (the accept function first appeared in BSD 4.2).  The  BSD
       man  page  documents five possible error returns (EBADF, ENOTSOCK, EOP-
       NOTSUPP, EWOULDBLOCK, EFAULT).  SUSv3 documents errors  EAGAIN,  EBADF,
       ECONNABORTED, EINTR, EINVAL, EMFILE, ENFILE, ENOBUFS, ENOMEM, ENOTSOCK,
       EOPNOTSUPP, EPROTO, EWOULDBLOCK. In addition,  SUSv2  documents  EFAULT
       and ENOSR.

       Linux  accept  does  _not_  inherit socket flags like O_NONBLOCK.  This
       behaviour differs from  other  BSD  socket  implementations.   Portable
       programs  should not rely on this behaviour and always set all required
       flags on the socket returned from accept.

NOTE
       The third argument of accept was originally declared as an 'int *' (and
       is  that  under libc4 and libc5 and on many other systems like BSD 4.*,
       SunOS 4, SGI); a POSIX 1003.1g draft standard wanted to change it  into
       a  'size_t  *', and that is what it is for SunOS 5.  Later POSIX drafts
       have 'socklen_t *', and so do the Single Unix Specification and glibc2.
       Quoting  Linus  Torvalds: _Any_ sane library _must_ have "socklen_t" be
       the same size as int.  Anything else breaks any BSD socket layer stuff.
       POSIX  initially  _did_  make it a size_t, and I (and hopefully others,
       but obviously not too many) complained  to  them  very  loudly  indeed.
       Making  it  a  size_t is completely broken, exactly because size_t very
       seldom is the same size as "int" on 64-bit architectures, for  example.
       And  it  _has_ to be the same size as "int" because that's what the BSD
       socket interface is.  Anyway, the POSIX people eventually got  a  clue,
       and  created  "socklen_t".  They shouldn't have touched it in the first
       place, but once they did they felt it had to have a named type for some
       unfathomable  reason  (probably  somebody  didn't like losing face over
       having done the original stupid thing, so they  silently  just  renamed
       their blunder).

SEEALSO
       bind(2), connect(2), listen(2), select(2), socket(2)



Linux 2.2 Page                    2002-04-23                         ACCEPT(2)

_Exitgetsockoptoutwshmat
_exitgettidoutw_pshmctl
_llseekgettimeofdaypauseshmdt
_newselectgetuidpersonalityshmget
_sysctlgttypipeshmop
acceptidlepivot_rootshutdown
accessinbpollsigaction
acctinb_pprctlsigaltstack
adjtimexinlpreadsigblock
afs_syscallinl_pprofsiggetmask
alarminsbpselectsigmask
alloc_hugepagesinslptracesignal
arch_prctlinswpwritesigpause
bdflushintroquotactlsigpending
bindinwreadsigprocmask
breakinw_preaddirsigqueue
brkioctlreadlinksigreturn
cacheflushioctl_listreadvsigsetmask
capgetiopermrebootsigsuspend
capsetioplrecvsigtimedwait
chdiripcrecvfromsigvec
chmodkillrecvmsgsigwaitinfo
chownkillpgrenamesocket
chrootlchownrmdirsocketcall
clonelinksbrksocketpair
closelistensched_get_priority_maxssetmask
connectllseeksched_get_priority_minstat
creatlocksched_getaffinitystatfs
duplseeksched_getparamstime
dup2lstatsched_getschedulerstty
execvemadvisesched_rr_get_intervalswapoff
exitmincoresched_setaffinityswapon
fchdirmkdirsched_setparamsymlink
fchmodmknodsched_setschedulersync
fchownmlocksched_yieldsyscall
fcntlmlockallselectsyscalls
fdatasyncmmapselect_tutsysctl
flockmmap2semctlsysfs
forkmodify_ldtsemgetsysinfo
free_hugepagesmountsemopsyslog
fstatmprotectsendtime
fstatfsmpxsendfiletimes
fsyncmremapsendmsgtkill
ftruncatemsgctlsendtotruncate
futexmsggetsetcontextumask
getcontextmsgopsetdomainnameumount
getdentsmsgrcvsetegidumount2
getdomainnamemsgsndseteuiduname
getdtablesizemsyncsetfsgidundocumented
getegidmunlocksetfsuidunimplemented
geteuidmunlockallsetgidunlink
getgidmunmapsetgroupsuselib
getgroupsnanosleepsethostidustat
gethostidnfsservctlsethostnameutime
gethostnamenicesetitimerutimes
getitimerobsoletesetpgidvfork
getpagesizeoldfstatsetpgrpvhangup
getpeernameoldlstatsetpriorityvm86
getpgidoldoldunamesetregidwait
getpgrpoldstatsetresgidwait3
getpidoldunamesetresuidwait4
getppidopensetreuidwaitpid
getpriorityoutbsetrlimitwrite
getresgidoutb_psetsidwritev
getresuidoutlsetsockopt 
getrlimitoutl_psettimeofday 
getrusageoutsbsetuid 
getsidoutslsetup 


Transmission 1.41 beta 2
Lightweight, yet powerful BitTorrent client
X-Moto 0.5.0
2D motocross platform game
Gdm 2.25.1
Reimplementation of the well known xdm program.
Linux Kernel 2.6 2.6.28-rc7
Linux Kernel
Linux Kernel 2.4 2.4.37
Linux Kernel
RIP 7.3
Small linux system for the purpose of system booting or repairing
GEdit 2.25.1
Small but powerful text editor
VLC media player 0.9.7
Cross-platform media player and streaming server
GNOME 2.25.2
GNOME desktop environment
WebGUI 7.6.5
A fully featured content management system.
Free IT Magazines, White Papers, eBooks, and more !
Dr. Dobb's Journal

Dr. Dobb's Journal enables programmers to write the most efficient and sophisticated programs and help in daily programming quandaries.

The 7 Things that IT Security Professionals MUST KNOW!

Gain key insight into security problem and find the safest means to protect your technological assets.

Database Trends and Applications

Provides timely coverage of the technology, intelligence and insight needed to plan, implement and manage information-rich projects.

Linux Software Map
Find Linux RPM
Best Rated Linux Software
Most Rated Linux Software
Linux Distributions
Linux Howtos
Quick Survey

Please take our survey and help us improve our website to serve you better.

Thank you.
Linux Software
Linux / IT Resources
Site Resources
Google
Privacy Policy
Contact Us
Submit Software
Advertising info