Add framework for listen() and connect() -- still missing logic

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@353 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2007-09-23 16:58:09 +00:00
parent bbd134bf41
commit d9e7cffac8
2 changed files with 134 additions and 14 deletions
+133 -14
View File
@@ -21,7 +21,7 @@ User's Manual
<p>
Gregory Nutt
<p>
<small>Last Update: September 8, 2007</small>
<small>Last Update: September 23, 2007</small>
</center>
<h1>1.0 <A NAME="Introduction">Introduction</a></h1>
@@ -5780,12 +5780,14 @@ Those socket APIs are discussed in the following paragraphs.</p>
<li><a href="#socket">2.12.1 socket</a></li>
<li><a href="#bind">2.12.2 bind</a></li>
<li><a href="#connect">2.12.3 connect</a></li>
<li><a href="#send">2.12.4 send</a></li>
<li><a href="#sendto">2.12.5 sendto</a></li>
<li><a href="#recv">2.12.6 recv</a></li>
<li><a href="#recvfrom">2.12.7 recvfrom</a></li>
<li><a href="#setsockopt">2.12.8 setsockopt</a></li>
<li><a href="#getsockopt">2.12.9 getsockopt</a></li>
<li><a href="#listen">2.12.4 listen</a></li>
<li><a href="#accept">2.12.5 accept</a></li>
<li><a href="#send">2.12.6 send</a></li>
<li><a href="#sendto">2.12.7 sendto</a></li>
<li><a href="#recv">2.12.8 recv</a></li>
<li><a href="#recvfrom">2.12.9 recvfrom</a></li>
<li><a href="#setsockopt">2.12.10 setsockopt</a></li>
<li><a href="#getsockopt">2.12.11 getsockopt</a></li>
</ul>
<h3><a name="socket">2.12.1 <code>socket</code></a></h3>
@@ -5951,7 +5953,122 @@ Those socket APIs are discussed in the following paragraphs.</p>
to accept new connections.</li>
</ul>
<h3><a name="send">2.12.4 <code>send</code></a></h3>
<h3><a name="listen">2.12.4 listen</a></h3>
<p>
<b>Function Prototype:</b>
</p>
<pre>
#include <sys/socket.h>
int listen(int sockfd, int backlog);
</pre>
<p>
<b>Description:</b>
To accept connections, a socket is first created with <code>socket()</code>, a
willingness to accept incoming connections and a queue limit for incoming
connections are specified with <code>listen()</code>, and then the connections are
accepted with <code>accept()</code>. The <code>listen()</coe> call applies only to sockets of
type <code>SOCK_STREAM</code> or <code>SOCK_SEQPACKET</code>.
</p>
<p>
<b>Input Parameters:</b>
</p>
<ul>
<li><code>sockfd</code>: Socket descriptor of the bound socket.</li>
<li><code>backlog</code>: The maximum length the queue of pending connections may grow.
If a connection request arrives with the queue full, the client may receive an error
with an indication of ECONNREFUSED or, if the underlying protocol supports retransmission,
the request may be ignored so that retries succeed.</li>
</ul>
<p>
<b>Returned Values:</b>
On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
</p>
<ul>
<li><code>EADDRINUSE</code>: Another socket is already listening on the same port.</li>
<li><code>EBADF</code>: The argument <code>sockfd</code> is not a valid descriptor.</li>
<li><code>ENOTSOCK</code>: The argument <code>sockfd</code> is not a socket.</li>
<li><code>EOPNOTSUPP</code>: The socket is not of a type that supports the listen operation.</li>
</ul>
<h3><a name="accept">2.12.5 accept</a></h3>
<p>
<b>Function Prototype:</b>
</p>
<pre>
#include <sys/socket.h>
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
</pre>
<p>
<b>Description:</b>
The <code>accept()</code> function is used with connection-based socket types
(<code>SOCK_STREAM</code>, <code>SOCK_SEQPACKET</code> and <code>SOCK_RDM</code>).
It extracts the first connection request on the queue of pending connections,
creates a new connected socket with most of the same properties as <code>sockfd</code>,
and allocates a new socket descriptor for the socket, which is returned. The
newly created socket is no longer in the listening state. The original
socket <code>sockfd</code> is unaffected by this call. Per file descriptor flags
are not inherited across an accept.
</p>
<p>
The <code>sockfd</code> argument is a socket descriptor that has been created with
<code>socket()</code>, bound to a local address with <code>bind()</code>, and is listening for
connections after a call to <code>listen()</code>.
</p>
<p>
On return, the <code>addr</code> structure is filled in with the address of the
connecting entity. The <code>addrlen</code> argument initially contains the size
of the structure pointed to by <code>addr</code>; on return it will contain the
actual length of the address returned.
</p>
<p>
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
connections are present on the queue, accept returns <code>EAGAIN</code>.
</p>
<p>
<b>Input Parameters:</b>
</p>
<ul>
<li><code>sockfd</code>: Socket descriptor of the listening socket.</li>
<li><code>addr</code>: Receives the address of the connecting client.</li>
<li><code>addrlen</code>: Input: allocated size of <code>addr</code>, Return: returned size of <code>addr</code>.</li>
</ul>
<p>
<b>Returned Values:</b>
Returns -1 on error. If it succeeds, it returns a non-negative integer
that is a descriptor for the accepted socket.
</p>
<ul>
<li><code>EAGAIN</code> or <code>EWOULDBLOCK</code>:
The socket is marked non-blocking and no connections are present to be accepted.</li>
<li><code>EBADF</code>:
The descriptor is invalid.</li>
<li><code>ENOTSOCK</code>:
The descriptor references a file, not a socket.</li>
<li><code>EOPNOTSUPP</code>:
The referenced socket is not of type <code>SOCK_STREAM</code>.</li>
<li><code>EINTR</code>:
The system call was interrupted by a signal that was caught before a valid connection arrived.</li>
<li><code>ECONNABORTED</code>:
A connection has been aborted.</li>
<li><code>EINVAL</code>:
Socket is not listening for connections.</li>
<li><code>EMFILE</code>:
The per-process limit of open file descriptors has been reached.</li>
<li><code>ENFILE</code>:
The system maximum for file descriptors has been reached.</li>
<li><code>EFAULT</code>:
The addr parameter is not in a writable part of the user address space.</li>
<li><code>ENOBUFS</code> or <code>ENOMEM</code>:
Not enough free memory.</li>
<li><code>EPROTO</code>:
Protocol error.</li>
<li><code>EPERM</code>:
Firewall rules forbid connection.</li>
</ul>
<h3><a name="send">2.12.6 <code>send</code></a></h3>
<p>
<b>Function Prototype:</b>
</p>
@@ -5983,7 +6100,7 @@ Those socket APIs are discussed in the following paragraphs.</p>
See <a href="#sendto"><code>sendto()</code></a>.
</p>
<h3><a name="sendto">2.12.5 <code>sendto</code></a></h3>
<h3><a name="sendto">2.12.7 <code>sendto</code></a></h3>
<p>
<b>Function Prototype:</b>
</p>
@@ -6055,7 +6172,7 @@ Those socket APIs are discussed in the following paragraphs.</p>
MSG_NOSIGNAL is set.
</ul>
<h3><a name="recv">2.12.6 <code>recv</code></a></h3>
<h3><a name="recv">2.12.8 <code>recv</code></a></h3>
<p>
<b>Function Prototype:</b>
</p>
@@ -6086,7 +6203,7 @@ Those socket APIs are discussed in the following paragraphs.</p>
Zero on success.
</p>
<h3><a name="recvfrom">2.12.7 <code>recvfrom</code></a></h3>
<h3><a name="recvfrom">2.12.9 <code>recvfrom</code></a></h3>
<p>
<b>Function Prototype:</b>
</p>
@@ -6148,7 +6265,7 @@ Those socket APIs are discussed in the following paragraphs.</p>
The argument <code>sockfd</code> does not refer to a socket.
</ul>
<h3><a name="setsockopt">2.12.8 <code>setsockopt</code></a></h3>
<h3><a name="setsockopt">2.12.10 <code>setsockopt</code></a></h3>
<p>
<b>Function Prototype:</b>
</p>
@@ -6208,7 +6325,7 @@ Those socket APIs are discussed in the following paragraphs.</p>
Insufficient resources are available in the system to complete the call.
</ul>
<h3><a name="getsockopt">2.12.9 <code>getsockopt</code></a></h3>
<h3><a name="getsockopt">2.12.11 <code>getsockopt</code></a></h3>
<p>
<b>Function Prototype:</b>
</p>
@@ -6469,6 +6586,7 @@ notify a task when a message is available on a queue.
<table width="100%">
<tr>
<td>
<li><a href="#accept">accept</a></li>
<li><a href="#bind">bind</a></li>
<li><a href="#clockgetres">clock_getres</a></li>
<li><a href="#clockgettime">clock_gettime</a></li>
@@ -6485,6 +6603,7 @@ notify a task when a message is available on a queue.
<li><a href="#gmtimer">gmtime_r</a></li>
<li><a href="#Introduction">Introduction</a>
<li><a href="#kill">kill</a></li>
<li><a href="#listen">listen</a></li>
<li><a href="#localtimer">localtime_r</a></li>
<li><a href="#Message_Queue">Named Message Queue Interfaces</a>
<li><a href="#mktime">mktime</a></li>
@@ -6541,9 +6660,9 @@ notify a task when a message is available on a queue.
<li><a href="#pthreadmutexattrinit">pthread_mutexattr_init</a></li>
<li><a href="#pthreadmutexattrsetpshared">pthread_mutexattr_setpshared</a></li>
<li><a href="#pthreadmutexdestrory">pthread_mutex_destroy</a></li>
<li><a href="#pthreadmutexinit">pthread_mutex_init</a></li>
</td>
<td>
<li><a href="#pthreadmutexinit">pthread_mutex_init</a></li>
<li><a href="#pthreadmutexlock">pthread_mutex_lock</a></li>
<li><a href="#pthreadmutextrylock">pthread_mutex_trylock</a></li>
<li><a href="#pthreadmutexunlock">pthread_mutex_unlock</a></li>