Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

tcpserver.c

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /* This file has been written by Sergio Perez Alcañiz <serpeal@disca.upv.es>  */
00003 /*            Departamento de Informática de Sistemas y Computadores          */
00004 /*            Universidad Politécnica de Valencia                             */
00005 /*            Valencia (Spain)                                                */
00006 /*            Date: April 2003                                                */
00007 /******************************************************************************/
00008 
00009 #include <linux/module.h>
00010 #include <linux/kernel.h>
00011 #include "lwip/sys.h"
00012 #include "lwip/api.h"
00013 #include <rtl_sched.h>
00014 #include <rtl_debug.h>
00015 
00016 struct netconn *conn, *newconn;
00017 pthread_t sequential_tcpserver_thread;
00018 
00019 /*-----------------------------------------------------------------------------------*/
00020 static void 
00021 tcpecho_thread(void *arg)
00022 {
00023 
00024   rtl_printf("\n\nEcho TCP server module inserted 0x%x.\n\n", (unsigned int) pthread_self()); 
00025 
00026   /* Create a new connection identifier. */
00027   conn = netconn_new(NETCONN_TCP);
00028   
00029   /* Bind connection to well known port number 7. */
00030   netconn_bind(conn, NULL, 7);
00031 
00032   /* Tell connection to go into listening mode. */
00033   netconn_listen(conn);
00034 
00035   while(1) {
00036 
00037     /* Grab new connection. */
00038     newconn = netconn_accept(conn);
00039 
00040     /* Process the new connection. */
00041     if(newconn != NULL) {
00042       struct netbuf *buf;
00043       void *data;
00044       u16_t len;
00045 
00046       while((buf = netconn_recv(newconn)) != NULL) {
00047         do {
00048           netbuf_data(buf, &data, &len);
00049           rtl_printf("\n\n\n\n\n---------------Echo TCP server receiving: %s --------------------\n\n\n\n\n",data);
00050         } while(netbuf_next(buf) >= 0);
00051         netbuf_delete(buf);     
00052       }
00053     }
00054   }
00055 }
00056 
00057 
00058 
00059 
00060 /*-----------------------------------------------------------------------------------*/
00061 int init_module(void){
00062   printk("\n\nEcho TCP server module being inserted.\n\n"); 
00063   sequential_tcpserver_thread = (pthread_t) sys_thread_new(tcpecho_thread, NULL, 0);
00064   return 0;
00065 }
00066 
00067 /*-----------------------------------------------------------------------------------*/
00068 void cleanup_module(void){
00069   sys_thread_delete((void *) sequential_tcpserver_thread);
00070   netconn_delete(conn);
00071   printk("\n\nEcho TCP server module removed.\n\n"); 
00072 }
00073 

Generated on Wed Jan 14 12:58:57 2004 for RTL-lwIP-0.4 by doxygen 1.3.4