From 6929a67489e1ad4ff6694a54ee996cf7f40a13a9 Mon Sep 17 00:00:00 2001 From: davidhaas Date: Thu, 6 Feb 2003 22:18:30 +0000 Subject: [PATCH] Add the following features and bugfixes: Added select() functionality to sockets library. Support for errno in sockets library. Byte ordering fixes. basic lwip_ioctl(), FIONREAD, get/setsockopt() etc. support - added additional argument to netif_add to pass state pointer so that the if_init function has access to context information before the interface is added, without accessing globals. - added netif_remove() - to conserve cpu load the tcpip_tcp_timer should only be active when tcbs that need it exist. - pass length of available data to callbacks for NETCONN_EVT_RCV events - added tcpip_link_input(), a hack to allow processing of PPP packets in tcpip_thread() context. This saves threads and context switches. - renamed incompatible ASSERT() macro to LWIP_ASSERT() to avoid name collision. - changed a bunch of %d's to %u's in format strings for unsigned values. - added ip_frag to lwip_stats. - changed IP_REASS_MAXAGE and IP_REASS_TMO defaults to more realistic values. - added sys_timeout_remove() function to cancel timeouts (needed by PPP amongst other things). - tolerate NULL returns from sys_arch_timeouts() since some threads might not need to use or have timeouts. - added sys_sem_wait_timeout() - moved mem_malloc() function to end of mem.c to work around tasking compiler bug. - automatically bind to local tcp port if 0. - allow customization of port ranges for automatic local bindings. - corrected various typos, spelling errors, etc.. Thanks to Marc Boucher for many of these changes. --- ports/coldfire/include/arch/errno.h | 5 ----- ports/coldfire/proj/lwipopts.h | 1 + ports/coldfire/sys_arch.c | 2 +- ports/unix/include/arch/sys_arch.h | 3 +++ ports/unix/proj/lib/unixlib.c | 4 ++-- ports/unix/proj/minimal/main.c | 2 +- ports/unix/proj/unixsim/lwipopts.h | 5 +++++ ports/unix/proj/unixsim/simhost.c | 10 +++++----- ports/unix/proj/unixsim/simnode.c | 4 ++-- ports/unix/proj/unixsim/simrouter.c | 6 +++--- ports/unix/sys_arch.c | 5 ++--- 11 files changed, 25 insertions(+), 22 deletions(-) diff --git a/ports/coldfire/include/arch/errno.h b/ports/coldfire/include/arch/errno.h index edd7883..d06a9be 100644 --- a/ports/coldfire/include/arch/errno.h +++ b/ports/coldfire/include/arch/errno.h @@ -41,9 +41,4 @@ #define errno (*sys_arch_errno()) -/* Error numbers */ -#define EBADF 9 /* Bad file number */ -#define EINVAL 22 /* Invalid argument */ -#define ENOBUFS 105 /* No buffer space available */ -#define EWOULDBLOCK 40 /* We would have blocked if this was'nt non-blocking i/o */ #endif diff --git a/ports/coldfire/proj/lwipopts.h b/ports/coldfire/proj/lwipopts.h index 77b9c48..243ed6b 100644 --- a/ports/coldfire/proj/lwipopts.h +++ b/ports/coldfire/proj/lwipopts.h @@ -196,4 +196,5 @@ a lot of data that needs to be copied, this should be set high. */ #define LWIP_COMPAT_SOCKETS +#define LWIP_PROVIDE_ERRNO #endif /* __LWIPOPTS_H__ */ diff --git a/ports/coldfire/sys_arch.c b/ports/coldfire/sys_arch.c index cecc476..4afaddb 100644 --- a/ports/coldfire/sys_arch.c +++ b/ports/coldfire/sys_arch.c @@ -397,7 +397,7 @@ sys_mbox_post(sys_mbox_t mbox, void *msg) &msg, 1, NU_NO_SUSPEND); - ASSERT("sys_mbox_post: mbx post failed", status == NU_SUCCESS); + LWIP_ASSERT("sys_mbox_post: mbx post failed", status == NU_SUCCESS); } /*---------------------------------------------------------------------------------*/ u32_t diff --git a/ports/unix/include/arch/sys_arch.h b/ports/unix/include/arch/sys_arch.h index d9bdb29..6c49965 100644 --- a/ports/unix/include/arch/sys_arch.h +++ b/ports/unix/include/arch/sys_arch.h @@ -32,6 +32,9 @@ #ifndef __ARCH_SYS_ARCH_H__ #define __ARCH_SYS_ARCH_H__ +#include +#include + #define SYS_MBOX_NULL NULL #define SYS_SEM_NULL NULL diff --git a/ports/unix/proj/lib/unixlib.c b/ports/unix/proj/lib/unixlib.c index 3447dc9..22f4fbf 100644 --- a/ports/unix/proj/lib/unixlib.c +++ b/ports/unix/proj/lib/unixlib.c @@ -26,7 +26,7 @@ * * Author: Kieran Mansley * - * $Id: unixlib.c,v 1.1 2003/01/31 13:35:43 jani Exp $ + * $Id: unixlib.c,v 1.2 2003/02/06 22:18:31 davidhaas Exp $ */ /*-----------------------------------------------------------------------------------*/ @@ -83,7 +83,7 @@ void _init(void){ IP4_ADDR(&ipaddr, 192,168,1,1); IP4_ADDR(&netmask, 255,255,255,0); - netif_set_default(netif_add(&ipaddr, &netmask, &gateway, tapif_init, + netif_set_default(netif_add(&ipaddr, &netmask, &gateway, NULL, tapif_init, tcpip_input)); } diff --git a/ports/unix/proj/minimal/main.c b/ports/unix/proj/minimal/main.c index 5cdf653..49eff86 100644 --- a/ports/unix/proj/minimal/main.c +++ b/ports/unix/proj/minimal/main.c @@ -71,7 +71,7 @@ main(int argc, char **argv) IP4_ADDR(&ipaddr, 192,168,0,2); IP4_ADDR(&netmask, 255,255,255,0); - netif = netif_add(&ipaddr, &netmask, &gw, mintapif_init, ip_input); + netif = netif_add(&ipaddr, &netmask, &gw, NULL, mintapif_init, ip_input); netif_set_default(netif); diff --git a/ports/unix/proj/unixsim/lwipopts.h b/ports/unix/proj/unixsim/lwipopts.h index bb62213..a0c677d 100644 --- a/ports/unix/proj/unixsim/lwipopts.h +++ b/ports/unix/proj/unixsim/lwipopts.h @@ -123,6 +123,11 @@ a lot of data that needs to be copied, this should be set high. */ /* Maximum number of retransmissions of SYN segments. */ #define TCP_SYNMAXRTX 4 +/* TCP writable space (bytes). This must be less than or equal + to TCP_SND_BUF. It is the amount of space which must be + available in the tcp snd_buf for select to return writable */ +#define TCP_SNDLOWAT TCP_SND_BUF/2 + /* ---------- ARP options ---------- */ #define ARP_TABLE_SIZE 10 #define ARP_QUEUEING 1 diff --git a/ports/unix/proj/unixsim/simhost.c b/ports/unix/proj/unixsim/simhost.c index 313b5ff..7f2201c 100644 --- a/ports/unix/proj/unixsim/simhost.c +++ b/ports/unix/proj/unixsim/simhost.c @@ -106,7 +106,7 @@ main_thread(void *arg) IP4_ADDR(&ipaddr, 0,0,0,0); IP4_ADDR(&netmask, 0,0,0,0); - netif = netif_add(&ipaddr, &netmask, &gw, tapif_init, + netif = netif_add(&ipaddr, &netmask, &gw, NULL, tapif_init, tcpip_input); netif_set_default(netif); dhcp_init(); @@ -117,9 +117,9 @@ main_thread(void *arg) IP4_ADDR(&ipaddr, 192,168,0,2); IP4_ADDR(&netmask, 255,255,255,0); - /* netif_set_default(netif_add(&ipaddr, &netmask, &gw, tapif_init, + /* netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, tapif_init, tcpip_input));*/ - netif_set_default(netif_add(&ipaddr, &netmask, &gw, tapif_init, + netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, tapif_init, tcpip_input)); #endif /* Only used for testing purposes: */ @@ -127,14 +127,14 @@ main_thread(void *arg) IP4_ADDR(&ipaddr, 193,10,66,107); IP4_ADDR(&netmask, 255,255,252,0); - netif_add(&ipaddr, &netmask, &gw, pcapif_init, + netif_add(&ipaddr, &netmask, &gw, NULL, pcapif_init, tcpip_input);*/ IP4_ADDR(&gw, 127,0,0,1); IP4_ADDR(&ipaddr, 127,0,0,1); IP4_ADDR(&netmask, 255,0,0,0); - netif_add(&ipaddr, &netmask, &gw, loopif_init, + netif_add(&ipaddr, &netmask, &gw, NULL, loopif_init, tcpip_input); tcpecho_init(); diff --git a/ports/unix/proj/unixsim/simnode.c b/ports/unix/proj/unixsim/simnode.c index c494e15..20dca88 100644 --- a/ports/unix/proj/unixsim/simnode.c +++ b/ports/unix/proj/unixsim/simnode.c @@ -90,9 +90,9 @@ main_thread(void *arg) IP4_ADDR(&ipaddr, 192,168,1,2); IP4_ADDR(&netmask, 255,255,255,0); - netif_set_default(netif_add(&ipaddr, &netmask, &gw, unixif_init_client, + netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, unixif_init_client, tcpip_input)); - /* netif_set_default(netif_add(&ipaddr, &netmask, &gw, sioslipif_init1, + /* netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, sioslipif_init1, tcpip_input)); */ diff --git a/ports/unix/proj/unixsim/simrouter.c b/ports/unix/proj/unixsim/simrouter.c index 0e79074..6b87554 100644 --- a/ports/unix/proj/unixsim/simrouter.c +++ b/ports/unix/proj/unixsim/simrouter.c @@ -92,20 +92,20 @@ main_thread(void *arg) IP4_ADDR(&ipaddr, 192,168,0,2); IP4_ADDR(&netmask, 255,255,255,0); - netif_set_default(netif_add(&ipaddr, &netmask, &gw, tapif_init, + netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, tapif_init, tcpip_input)); IP4_ADDR(&gw, 192,168,1,1); IP4_ADDR(&ipaddr, 192,168,1,1); IP4_ADDR(&netmask, 255,255,255,0); - netif_set_default(netif_add(&ipaddr, &netmask, &gw, unixif_init_server, + netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, unixif_init_server, tcpip_input)); system("route add 192.168.1.1 192.168.0.2"); system("route add 192.168.1.2 192.168.0.2"); - /*netif_set_default(netif_add(&ipaddr, &netmask, &gw, sioslipif_init1, + /*netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, sioslipif_init1, tcpip_input)); */ diff --git a/ports/unix/sys_arch.c b/ports/unix/sys_arch.c index a08556c..07e2520 100644 --- a/ports/unix/sys_arch.c +++ b/ports/unix/sys_arch.c @@ -46,7 +46,6 @@ */ #include "lwip/debug.h" -#include #include #include #include @@ -221,7 +220,7 @@ sys_mbox_post(struct sys_mbox *mbox, void *msg) sys_sem_wait(mbox->mutex); - DEBUGF(SYS_DEBUG, ("sys_mbox_post: mbox %p msg %p\n", mbox, msg)); + DEBUGF(SYS_DEBUG, ("sys_mbox_post: mbox %p msg %p\n", (void *)mbox, (void *)msg)); while((mbox->last + 1) >= (mbox->first + SYS_MBOX_SIZE)) { mbox->wait_send++; @@ -276,7 +275,7 @@ sys_arch_mbox_fetch(struct sys_mbox *mbox, void **msg, u32_t timeout) sys_arch_sem_wait(mbox->mutex, 0); } - DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p msg %p\n", mbox, *msg)); + DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p msg %p\n", (void *)mbox, *msg)); if(msg != NULL) { *msg = mbox->msgs[mbox->first % SYS_MBOX_SIZE];