Add framework for listen() and connect() -- still missing logic
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@353 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
parent
d47d9748a5
commit
e8a8f36d73
|
@ -212,4 +212,5 @@
|
|||
* Implemented receive timeouts via setsockopt(SO_RCVTIMEO).
|
||||
* Provide support for multiple network devices
|
||||
* Implement socket ioctl() calls to set addresses
|
||||
* Added listen() and accept()
|
||||
|
||||
|
|
|
@ -645,6 +645,7 @@ Other memory:
|
|||
* Implemented receive timeouts via setsockopt(SO_RCVTIMEO).
|
||||
* Provide support for multiple network devices
|
||||
* Implement socket ioctl() calls to set addresses
|
||||
* Added listen() and accept()
|
||||
</pre></ul>
|
||||
|
||||
<table width ="100%">
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -211,10 +211,7 @@ $(BIN): context depend $(LINKLIBS)
|
|||
$(MAKE) -C $(ARCH_SRC) TOPDIR=$(TOPDIR) LINKLIBS="$(LINKLIBS)" $(BIN)
|
||||
|
||||
depend:
|
||||
echo "CLEANDIRS: $(CLEANDIRS)"
|
||||
echo "MAKEDIRS: $(MAKEDIRS)"
|
||||
for dir in $(MAKEDIRS) ; do \
|
||||
echo "-- DEPS in $$dir --" ; \
|
||||
@for dir in $(MAKEDIRS) ; do \
|
||||
$(MAKE) -C $$dir TOPDIR=$(TOPDIR) depend ; \
|
||||
done
|
||||
|
||||
|
|
|
@ -83,30 +83,29 @@ $(SPECOBJS): %$(OBJEXT): %.c
|
|||
$(CC) -c $(HOSTCFLAGS) $< -o $@
|
||||
|
||||
libarch$(LIBEXT): $(OBJS)
|
||||
( for obj in $(OBJS) ; do \
|
||||
@( for obj in $(OBJS) ; do \
|
||||
$(AR) $@ $${obj} || \
|
||||
{ echo "$(AR) $@ $obj FAILED!" ; exit 1 ; } ; \
|
||||
done ; )
|
||||
|
||||
nuttx: $(LINKOBJS)
|
||||
nuttx$(EXEEXT): $(LINKOBJS)
|
||||
$(CC) $(LDFLAGS) $(LDPATHES) -o $(TOPDIR)/$@ $(LINKOBJS) \
|
||||
-Wl,--start-group $(LDLIBS) -Wl,--end-group $(EXTRA_LIBS)
|
||||
@$(NM) $(TOPDIR)/$@ | \
|
||||
grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
|
||||
sort > $(TOPDIR)/System.map
|
||||
|
||||
grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
|
||||
sort > $(TOPDIR)/System.map
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
touch $@
|
||||
@$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
rm -f libarch$(LIBEXT) *~
|
||||
if [ ! -z "$(OBJEXT)" ]; then rm -f *$(OBJEXT); fi
|
||||
@rm -f libarch$(LIBEXT) *~
|
||||
@if [ ! -z "$(OBJEXT)" ]; then rm -f *$(OBJEXT); fi
|
||||
|
||||
distclean: clean
|
||||
rm -f Make.dep .depend
|
||||
@rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
||||
|
|
|
@ -180,6 +180,9 @@ EXTERN int socket(int domain, int type, int protocol);
|
|||
EXTERN int bind(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen);
|
||||
EXTERN int connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen);
|
||||
|
||||
EXTERN int listen(int sockfd, int backlog);
|
||||
EXTERN int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
|
||||
EXTERN ssize_t send(int sockfd, FAR const void *buf, size_t len, int flags);
|
||||
EXTERN ssize_t sendto(int sockfd, FAR const void *buf, size_t len, int flags,
|
||||
FAR const struct sockaddr *to, socklen_t tolen);
|
||||
|
|
|
@ -40,8 +40,8 @@ MKDEP = $(TOPDIR)/tools/mkdeps.sh
|
|||
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
SOCK_ASRCS =
|
||||
SOCK_CSRCS = socket.c bind.c connect.c send.c sendto.c recv.c recvfrom.c \
|
||||
net-sockets.c net-close.c
|
||||
SOCK_CSRCS = socket.c bind.c connect.c listen.c accept.c send.c sendto.c \
|
||||
recv.c recvfrom.c net-sockets.c net-close.c
|
||||
|
||||
ifeq ($(CONFIG_NET_SOCKOPTS),y)
|
||||
SOCK_CSRCS += setsockopt.c getsockopt.c
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
/****************************************************************************
|
||||
* net/accept.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "net-internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: accept
|
||||
*
|
||||
* Description:
|
||||
* The accept function is used with connection-based socket types
|
||||
* (SOCK_STREAM, SOCK_SEQPACKET and SOCK_RDM). It extracts the first
|
||||
* connection request on the queue of pending connections, creates a new
|
||||
* connected socket with mostly the same properties as 'sockfd', 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 'sockfd' is unaffected by this call. Per file descriptor flags
|
||||
* are not inherited across an accept.
|
||||
*
|
||||
* The 'sockfd' argument is a socket descriptor that has been created with
|
||||
* socket(), bound to a local address with bind(), and is listening for
|
||||
* connections after a call to listen().
|
||||
*
|
||||
* On return, the 'addr' structure is filled in with the address of the
|
||||
* connecting entity. The 'addrlen' argument initially contains the size
|
||||
* of the structure pointed to by 'addr'; on return it will contain the
|
||||
* actual length of the address returned.
|
||||
*
|
||||
* 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 EAGAIN.
|
||||
*
|
||||
* Parameters:
|
||||
* sockfd The listening socket descriptior
|
||||
* addr Receives the address of the connecting client
|
||||
* addrlen Input: allocated size of 'addr', Return: returned size of 'addr'
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns -1 on error. If it succeeds, it returns a non-negative integer
|
||||
* that is a descriptor for the accepted socket.
|
||||
*
|
||||
* 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.
|
||||
* EFAULT
|
||||
* The addr parameter is not in a writable part of the user address
|
||||
* space.
|
||||
* ENOBUFS or ENOMEM
|
||||
* Not enough free memory.
|
||||
* EPROTO
|
||||
* Protocol error.
|
||||
* EPERM
|
||||
* Firewall rules forbid connection.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
|
||||
{
|
||||
*get_errno_ptr() = ENOSYS;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */
|
|
@ -0,0 +1,94 @@
|
|||
/****************************************************************************
|
||||
* net/listen.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "net-internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: listen
|
||||
*
|
||||
* Description:
|
||||
* To accept connections, a socket is first created with socket(), a
|
||||
* willingness to accept incoming connections and a queue limit for incoming
|
||||
* connections are specified with listen, and then the connections are
|
||||
* accepted with accept(). The listen() call applies only to sockets of
|
||||
* type SOCK_STREAM or SOCK_SEQPACKET.
|
||||
*
|
||||
* Parameters:
|
||||
* sockfd Socket descriptor of the bound socket
|
||||
* backlog 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.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, zero is returned. On error, -1 is returned, and errno is set
|
||||
* appropriately.
|
||||
*
|
||||
* EADDRINUSE
|
||||
* Another socket is already listening on the same port.
|
||||
* EBADF
|
||||
* The argument 'sockfd' is not a valid descriptor.
|
||||
* ENOTSOCK
|
||||
* The argument 'sockfd' is not a socket.
|
||||
* EOPNOTSUPP
|
||||
* The socket is not of a type that supports the listen operation.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int listen(int sockfd, int backlog)
|
||||
{
|
||||
*get_errno_ptr() = ENOSYS;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */
|
|
@ -43,6 +43,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <libgen.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -203,16 +204,18 @@ FILE *open_outfile(const char *filename)
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: generate_sourcefile_list
|
||||
* Function: generate_mkdefs
|
||||
****************************************************************************/
|
||||
|
||||
int generate_sourcefile_list(void)
|
||||
int generate_mkdefs(void)
|
||||
{
|
||||
int ret = 1;
|
||||
FILE *stream;
|
||||
|
||||
if (( stream = open_stringfile()))
|
||||
{
|
||||
printf("STRNG_ASRCS =\n");
|
||||
printf("STRNG_CSRCS = ");
|
||||
ret = 0;
|
||||
while (fgets(g_line, 1024, stream) && !ret)
|
||||
{
|
||||
|
@ -239,14 +242,16 @@ int generate_sourcefiles(void)
|
|||
FILE *cstream;
|
||||
const char *pname;
|
||||
const char *pvalue;
|
||||
char *filename;
|
||||
char buffer[512];
|
||||
int len;
|
||||
int ndx;
|
||||
int ret = 1;
|
||||
|
||||
|
||||
filename = strdup(g_stringfile);
|
||||
if (( instream = open_stringfile()))
|
||||
{
|
||||
snprintf(buffer, 512, "%s.h", g_stringfile);
|
||||
snprintf(buffer, 512, "%s.h", basename(filename));
|
||||
hstream = open_outfile(buffer);
|
||||
if (hstream)
|
||||
{
|
||||
|
@ -258,11 +263,12 @@ int generate_sourcefiles(void)
|
|||
ret = parse_stringfile_line(&pname, &pvalue);
|
||||
if (!ret)
|
||||
{
|
||||
len = strlen(pvalue);
|
||||
|
||||
snprintf(buffer, 512, "%s.c", pname);
|
||||
cstream = open_outfile(buffer);
|
||||
if (cstream)
|
||||
{
|
||||
len = strlen(pvalue);
|
||||
fprintf(cstream, "const char %s[%d] = {", pname, len);
|
||||
for (ndx = 0; ndx < len; ndx++)
|
||||
{
|
||||
|
@ -272,7 +278,7 @@ int generate_sourcefiles(void)
|
|||
}
|
||||
fprintf(cstream, "0x%02x", pvalue[ndx]);
|
||||
}
|
||||
fprintf(cstream, "}\n");
|
||||
fprintf(cstream, "};\n");
|
||||
fclose(cstream);
|
||||
}
|
||||
fprintf(hstream, "extern const char %s[%d];\n", pname, len);
|
||||
|
@ -283,6 +289,7 @@ int generate_sourcefiles(void)
|
|||
}
|
||||
fclose(instream);
|
||||
}
|
||||
free(filename);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -364,7 +371,7 @@ int main(int argc, char **argv, char **envp)
|
|||
ret = generate_sourcefiles();
|
||||
break;
|
||||
case SRCLIST:
|
||||
ret = generate_sourcefile_list();
|
||||
ret = generate_mkdefs();
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
|
|
|
@ -34,4 +34,4 @@
|
|||
############################################################################
|
||||
|
||||
WEBCLIENT_ASRCS =
|
||||
WEBCLIENT_CSRCS = webclient-strings.c webclient.c
|
||||
WEBCLIENT_CSRCS = webclient.c
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <net/uip/uipopt.h>
|
||||
|
||||
#include "webclient-strings.h"
|
||||
#include "netutil-strings.h"
|
||||
|
||||
#define WEBCLIENT_CONF_MAX_URLLEN 100
|
||||
|
||||
|
|
|
@ -34,4 +34,4 @@
|
|||
############################################################################
|
||||
|
||||
WEBSERVER_ASRCS =
|
||||
WEBSERVER_CSRCS = httpd.c http-strings.c httpd-fs.c httpd-cgi.c
|
||||
WEBSERVER_CSRCS = httpd.c httpd-fs.c httpd-cgi.c
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
|
||||
#include "httpd.h"
|
||||
#include "httpd-cgi.h"
|
||||
#include "http-strings.h"
|
||||
#include "netutil-strings.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
|
Loading…
Reference in New Issue