This commit is contained in:
Stefan Lankes 2011-08-10 08:02:30 +02:00
parent 1bb959fdee
commit 4321b18b3c
2 changed files with 63 additions and 1 deletions

View file

@ -1,4 +1,4 @@
C_source := main.c tasks.c syscall.c tests.c echo.c ping.c init.c server.c client.c shell.c
C_source := main.c tasks.c syscall.c tests.c echo.c ping.c netio.c init.c server.c client.c shell.c
MODULE := kernel
include $(TOPDIR)/Makefile.inc

62
kernel/netio.c Normal file
View file

@ -0,0 +1,62 @@
/*
* this example is derived from the netio example of the contrib-1.4.0
*
* see http://download.savannah.gnu.org/releases/lwip/
*/
#include <metalsvm/stddef.h>
#include <lwip/opt.h>
#if defined(CONFIG_LWIP)
#include <lwip/opt.h>
#include <lwip/tcp.h>
/* See http://www.nwlab.net/art/netio/netio.html to get the netio tool */
#if LWIP_TCP
static err_t netio_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
LWIP_UNUSED_ARG(arg);
if (err == ERR_OK && p != NULL) {
tcp_recved(pcb, p->tot_len);
pbuf_free(p);
} else {
pbuf_free(p);
}
if (err == ERR_OK && p == NULL) {
tcp_arg(pcb, NULL);
tcp_sent(pcb, NULL);
tcp_recv(pcb, NULL);
tcp_close(pcb);
}
return ERR_OK;
}
static err_t netio_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(err);
tcp_arg(pcb, NULL);
tcp_sent(pcb, NULL);
tcp_recv(pcb, netio_recv);
return ERR_OK;
}
void netio_init(void)
{
struct tcp_pcb *pcb;
pcb = tcp_new();
tcp_bind(pcb, IP_ADDR_ANY, 18767);
pcb = tcp_listen(pcb);
tcp_accept(pcb, netio_accept);
}
#endif /* LWIP_TCP */
#endif