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

📄 net-httpd-organization.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
字号:
<!-- Copyright (C) 2003 Red Hat, Inc.                                --><!-- This material may be distributed only subject to the terms      --><!-- and conditions set forth in the Open Publication License, v1.0  --><!-- or later (the latest version is presently available at          --><!-- http://www.opencontent.org/openpub/).                           --><!-- Distribution of the work or derivative of the work in any       --><!-- standard (paper) book form is prohibited unless prior           --><!-- permission is obtained from the copyright holder.               --><HTML><HEAD><TITLE>Server Organization</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="Embedded HTTP Server"HREF="net-httpd-chapter.html"><LINKREL="PREVIOUS"TITLE="Embedded HTTP Server"HREF="net-httpd-chapter.html"><LINKREL="NEXT"TITLE="Server Configuration"HREF="net-httpd-configuration.html"></HEAD><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="net-httpd-chapter.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 48. Embedded HTTP Server</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="net-httpd-configuration.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="NET-HTTPD-ORGANIZATION">Server Organization</H1><P>The server consists of one or more threads running in parallel to anyapplication threads and which serve web pages to clients. Apart fromdefining content, the application does not need to do anything tostart the HTTP server.</P><P>The HTTP server is started by a static constructor. This simplycreates an initial thread and sets it running. Since this is calledbefore the scheduler is started, nothing will happen until theapplication calls <TTCLASS="FUNCTION">cyg_scheduler_start()</TT>.</P><P>When the thread gets to run it first optionally delays for some periodof time. This is to allow the application to perform anyinitialization free of any interference from the HTTP server. When thethread does finally run it creates a socket, binds it to the HTTPserver port, and puts it into listen mode. It will then create anyadditional HTTPD server threads that have been configured beforebecoming a server thread itself.</P><P>Each HTTPD server thread simply waits for a connection to be made tothe server port. When the connection is made it reads the HTTP requestand extracts the filename being accessed. If the request also containsform data, this is also preserved. The filename is then looked up in atable.</P><P>Each table entry contains a filename pattern string, apointer to a handler function, and a user defined argument for thefunction. Table entries are defined using the same link-time tablebuilding mechanism used to generate device tables. This is all handledby the <TTCLASS="LITERAL">CYG_HTTPD_TABLE_ENTRY()</TT> macro which has thefollowing format:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">&#13;#include &lt;cyg/httpd/httpd.h&gt;CYG_HTTPD_TABLE_ENTRY( __name, __pattern, __handler, __arg )&#13;</PRE></TD></TR></TABLE><P>The <TTCLASS="PARAMETER"><I>__name</I></TT> argument is a variable name for thetable entry since C does not allow us to define anonymous datastructures. This name should be chosen so that it is unique and doesnot pollute the name space. The <TTCLASS="PARAMETER"><I>__pattern</I></TT>argument is the match pattern. The <TTCLASS="PARAMETER"><I>__handler</I></TT>argument is a pointer to the handler function and<TTCLASS="PARAMETER"><I>__arg</I></TT> the user defined value.</P><P>The link-time table building means that several different pieces ofcode can define server table entries, and so long as the patterns donot clash they can be totally oblivious of each other. However, notealso that this mechanism does not guarantee the order in which entriesappear, this depends on the order of object files in the link, whichcould vary from one build to the next. So any tricky pattern matchingthat relies on this may not always work.</P><P>A request filename matches an entry in the table if either it exactlymatches the pattern string, or if the pattern ends in an asterisk, andit matches everything up to that point. So for example the pattern&quot;/monitor/threads.html&quot; will only match that exact filename,but the pattern &quot;/monitor/thread-*&quot; will match&quot;/monitor/thread-0040.html&quot;,&quot;/monitor/thread-0100.html&quot; and any other filename startingwith &quot;/monitor/thread-&quot;.</P><P>When a pattern is matched, the hander function is called. It has thefollowing prototype:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_bool cyg_httpd_handler(FILE *client,                           char *filename,                           char *formdata,                           void *arg);</PRE></TD></TR></TABLE><P>The <TTCLASS="PARAMETER"><I>client</I></TT> argument is the TCP connection tothe client: anything output through this stream will be returned tothe browser. The <TTCLASS="PARAMETER"><I>filename</I></TT> argument is thefilename from the HTTP request and the <TTCLASS="PARAMETER"><I>formdata</I></TT>argument is any form response data, or NULL if none was sent. The<TTCLASS="PARAMETER"><I>arg</I></TT> argument is the user defined value from thetable entry.</P><P>The handler is entirely responsible for generating the response to theclient, both HTTP header and content. If the handler decides that itdoes not want to generate a response it can return<TTCLASS="LITERAL">false</TT>, in which case the table scan is resumed foranother match. If no match is found, or no handler returns true, thena default response page is generated indicating that the requestedpage cannot be found.</P><P>Finally, the server thread closes the connection to the client andloops back to accept a new connection.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="net-httpd-chapter.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="net-httpd-configuration.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Embedded HTTP Server</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="net-httpd-chapter.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Server Configuration</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

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