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

tcpthreaded.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 /*-----------------------------------------------------------------------------------*/
00017 static void 
00018 serve_echo(void *arg)
00019 {
00020   struct netconn *newconn;
00021 
00022   /* Grab new connection. */
00023   newconn = (struct netconn *) arg; //netconn_accept(conn);
00024 
00025   rtl_printf("accepted new connection %p by thread 0x%x\n", newconn,(unsigned int)pthread_self());
00026 
00027   /* Process the new connection. */
00028   if(newconn != NULL) {
00029     struct netbuf *buf;
00030     void *data;
00031     u16_t len;
00032     
00033     while((buf = netconn_recv(newconn)) != NULL) {
00034       do {
00035         netbuf_data(buf, &data, &len);
00036         rtl_printf("Got : %s\n", data);
00037       } while(netbuf_next(buf) >= 0);
00038       netbuf_delete(buf);       
00039     }
00040 
00041     /* Close connection and discard connection identifier. */
00042     netconn_close(newconn);
00043     netconn_delete(newconn);
00044   }
00045   sys_thread_exit();  
00046 }
00047 
00048 /*-----------------------------------------------------------------------------------*/
00049 static void 
00050 tcpecho_thread(void *arg)
00051 {
00052   struct netconn *conn;
00053 
00054    /* Create a new connection identifier. */
00055   conn = netconn_new(NETCONN_TCP);
00056 
00057   /* Bind connection to well known port number 7. */
00058   netconn_bind(conn, NULL, 7);
00059 
00060   /* Tell connection to go into listening mode. */
00061   netconn_listen(conn);
00062 
00063   while(1) {
00064     /* Grab new connection. */
00065     sys_thread_new(serve_echo, netconn_accept(conn), 0);
00066   }
00067 }
00068 
00069 /*-----------------------------------------------------------------------------------*/
00070 int init_module(void){
00071   printk("\n Multithreaded TCP echo server inserted\n");
00072   sys_thread_new(tcpecho_thread, NULL, 0);  
00073   return 0;
00074 }
00075 
00076 /*-----------------------------------------------------------------------------------*/
00077 void cleanup_module(void){
00078   printk("\n Multithreaded TCP echo server removed\n");
00079 }

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