mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
Basic server functionality: listen(), accept()
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@382 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -42,7 +42,7 @@ TARG_ASRCS =
|
||||
TARG_AOBJS = $(TARG_ASRCS:.S=$(OBJEXT))
|
||||
|
||||
TARG_CSRCS = nettest.c
|
||||
ifeq ($(CONFIG_NETTEST_SERVER),y)
|
||||
ifeq ($(CONFIG_EXAMPLE_NETTEST_SERVER),y)
|
||||
TARG_CSRCS += nettest-server.c
|
||||
else
|
||||
TARG_CSRCS += nettest-client.c
|
||||
@@ -55,13 +55,14 @@ TARG_OBJS = $(TARG_AOBJS) $(TARG_COBJS)
|
||||
|
||||
TARG_BIN = lib$(CONFIG_EXAMPLE)$(LIBEXT)
|
||||
|
||||
HOSTCFLAGS += -DCONFIG_NETTEST_HOST=1
|
||||
ifeq ($(CONFIG_NETTEST_SERVER),y)
|
||||
HOSTCFLAGS += -DCONFIG_NETTEST_SERVER=1
|
||||
HOSTCFLAGS += -DCONFIG_EXAMPLE_NETTEST_HOST=1
|
||||
ifeq ($(CONFIG_EXAMPLE_NETTEST_SERVER),y)
|
||||
HOSTCFLAGS += -DCONFIG_EXAMPLE_NETTEST_SERVER=1 \
|
||||
-DCONFIG_EXAMPLE_NETTEST_CLIENTIP="$(CONFIG_EXAMPLE_NETTEST_CLIENTIP)"
|
||||
endif
|
||||
|
||||
HOST_SRCS = host.c
|
||||
ifeq ($(CONFIG_NETTEST_SERVER),y)
|
||||
ifeq ($(CONFIG_EXAMPLE_NETTEST_SERVER),y)
|
||||
HOST_SRCS += nettest-client.c
|
||||
else
|
||||
HOST_SRCS += nettest-server.c
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
#ifdef CONFIG_NETTEST_SERVER
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_SERVER
|
||||
send_client();
|
||||
#else
|
||||
recv_server();
|
||||
|
||||
@@ -57,12 +57,12 @@ void send_client(void)
|
||||
{
|
||||
struct sockaddr_in myaddr;
|
||||
char outbuf[SENDSIZE];
|
||||
#ifndef CONFIG_NETTEST_PERFORMANCE
|
||||
#ifndef CONFIG_EXAMPLE_NETTEST_PERFORMANCE
|
||||
char inbuf[SENDSIZE];
|
||||
#endif
|
||||
int sockfd;
|
||||
int nbytessent;
|
||||
#ifndef CONFIG_NETTEST_PERFORMANCE
|
||||
#ifndef CONFIG_EXAMPLE_NETTEST_PERFORMANCE
|
||||
int nbytesrecvd;
|
||||
#endif
|
||||
int ch;
|
||||
@@ -107,7 +107,7 @@ void send_client(void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NETTEST_PERFORMANCE
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_PERFORMANCE
|
||||
/* Then receive messages forever */
|
||||
|
||||
for (;;)
|
||||
|
||||
@@ -63,7 +63,7 @@ void recv_server(void)
|
||||
int acceptsd;
|
||||
socklen_t addrlen;
|
||||
int nbytesread;
|
||||
#ifndef CONFIG_NETTEST_PERFORMANCE
|
||||
#ifndef CONFIG_EXAMPLE_NETTEST_PERFORMANCE
|
||||
int totalbytesread;
|
||||
int nbytessent;
|
||||
int ch;
|
||||
@@ -133,7 +133,7 @@ void recv_server(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NETTEST_PERFORMANCE
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_PERFORMANCE
|
||||
/* Then receive data forever */
|
||||
|
||||
for (;;)
|
||||
@@ -194,7 +194,7 @@ void recv_server(void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NETTEST_HOST
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_HOST
|
||||
/* At present, data received by the target before it is completed the
|
||||
* the write opertion and started the read operation results in a failure
|
||||
* (the data is not received, but it is ACKed). This will have to be
|
||||
|
||||
@@ -94,7 +94,7 @@ int user_start(int argc, char *argv[])
|
||||
addr.s_addr = HTONL(CONFIG_EXAMPLE_NETTEST_NETMASK);
|
||||
uip_setnetmask("eth0", &addr);
|
||||
|
||||
#ifdef CONFIG_NETTEST_SERVER
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_SERVER
|
||||
recv_server();
|
||||
#else
|
||||
send_client();
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETTEST_HOST
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_HOST
|
||||
#else
|
||||
# include <debug.h>
|
||||
#endif
|
||||
@@ -49,7 +49,7 @@
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETTEST_HOST
|
||||
#ifdef CONFIG_EXAMPLE_NETTEST_HOST
|
||||
/* HTONS/L macros are unique to uIP */
|
||||
|
||||
# define HTONS(a) htons(a)
|
||||
|
||||
Reference in New Issue
Block a user