⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shttpserv.c

📁 ucos for linux reference source
💻 C
字号:
/***************************************************************************                                                                         **   PROJECT     : uCOS_LwIP (TCP/IP stack)                                **                                                                         **   MODULE      : SHTTPSERV.c                                             **                                                                         **   AUTHOR      : Michael Anburaj                                         **                 URL  : http://geocities.com/michaelanburaj/             **                 EMAIL: michaelanburaj@hotmail.com                       **                                                                         **   PROCESSOR   : Any                                                     **                                                                         **   TOOL-CHAIN  : GCC                                                     **                                                                         **   DESCRIPTION :                                                         **   A simple HTTP/1.0 server using the minimal API.                       **                                                                         ***************************************************************************/#include "frmwrk_cfg.h"#include "lwip/sys.h"#include "lwip/api.h"#include "consol.h"/* ********************************************************************* *//* Global definitions *//* ********************************************************************* *//* File local definitions *//*Important!!! LwIP data alignment issue:   As of now LwIP code does not handle odd byte length packets properly. So use the Lwip odd byte   issue patch to patch the LwIP CVS source. This is true only for processors that cannot handle    un-aligned memory access.*//* This is the data for the actual web page. */static char abIndexData[] ="<html> \<head><title>LwIP Test app over MIPS uC/OS-II -by Michael Anburaj. [0]</title></head> \<BODY>\<FONT FACE=\"Arial\" SIZE=6 COLOR=\"#ff0000\"><P>This is the 1st test line.....</P>\<P>Number of times you have browsed to this page = [0].</P></FONT></BODY>\</html>";const static char abHttpHtmlHdr[] ="HTTP/1.1 200 OK\r\n\Content-Type: text/html\r\n\r\n\n";/* ********************************************************************* *//* Local functions *//* This function processes an incomming connection. */static void vProcessConnection(struct netconn *conn){    struct netbuf *inbuf;    char *rq;    u16_t len;    int i;    static int Number = 0;    err_t rc;    if(++Number == 10)        Number = 0;    i = 0;    while(abIndexData[i])    {        if(abIndexData[i] == '[')        {            i++;            abIndexData[i] = '0'+Number;        }        i++;    }    /* Read data from the connection into the netbuf inbuf.    We assume that the full request is in the netbuf. */    if((inbuf = netconn_recv(conn)) == NULL)    {        return;    }        netbuf_data(inbuf, (void **)&rq, &len);    /* delete data buffer */    netbuf_delete(inbuf);    /* Check if the request was an HTTP "GET /\r\n". */    if(rq[0] == 'G' && rq[1] == 'E' &&    rq[2] == 'T' && rq[3] == ' ' &&    rq[4] == '/')    {#if (DEBUG_VERBOSE_APP == 1)        CONSOL_SendString("<<<Responding to HTTP GET>>>\n");#endif        /* Send the header. */        if((rc = netconn_write(conn, (void *)abHttpHtmlHdr, sizeof(abHttpHtmlHdr), NETCONN_NOCOPY)) != ERR_OK)            printf("***Write1Err (%d)***\n", rc);        /* Send the actual web page. */        if((rc = netconn_write(conn, (void *)abIndexData, sizeof(abIndexData), NETCONN_NOCOPY)) != ERR_OK)            printf("***Write2Err (%d)***\n", rc);    }    else    {        printf("***bad data***\n");        /* FIXME : have to do something more, causes assertion pbuf_free: p->ref > 0 */    }}static void vTcpEchoThread(void *arg){    struct netconn *conn, *newconn;    /* Create a new TCP connection handle. */    conn = netconn_new(NETCONN_TCP);    /* Bind the connection to port 80 on any    local IP address. */    netconn_bind(conn, NULL, 80);    /* Put the connection into LISTEN state. */    netconn_listen(conn);    /* Loop forever. */    while(1)    {#if (DEBUG_VERBOSE_APP == 1)        CONSOL_SendString("<<<netconn_accept>>>\n");#endif        /* Accept a new connection. */        newconn = netconn_accept(conn);        if(newconn != NULL)        {#if (DEBUG_VERBOSE_APP == 1)            CONSOL_SendString("<<<vProcessConnection>>>\n");#endif            /* Process the incomming connection. */            vProcessConnection(newconn);#if (DEBUG_VERBOSE_APP == 1)            CONSOL_SendString("<<<netconn_delete>>>\n");#endif            /* Deallocate connection handle. */            netconn_delete(newconn);#if (DEBUG_VERBOSE_APP == 1)            CONSOL_SendString("<<<netconn_delete done>>>\n");#endif        }        else        {#if (DEBUG_VERBOSE_APP == 1)            CONSOL_SendString("<<<netconn_accept error>>>\n");#endif        }    }}static void vTcpEchoInit(void){    sys_thread_new(vTcpEchoThread, NULL, APP_THREAD_START_PRIO+2);}/* ********************************************************************* *//* Global functions *//***********************************************************************************************                                       LAPP_vInit** Description: This is the LwIP application entry point.** Arguments  : none.** Return     : none.** Note(s)    : **********************************************************************************************/void LAPP_vInit(){    vTcpEchoInit();}/* ********************************************************************* */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -