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

📄 net-common-dhcp.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>DHCP</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="Support Features"HREF="net-common-support.html"><LINKREL="PREVIOUS"TITLE="Support Features"HREF="net-common-support.html"><LINKREL="NEXT"TITLE="TCP/IP Library Reference"HREF="tcpip-library-reference.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-common-support.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 37. Support Features</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="tcpip-library-reference.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="NET-COMMON-DHCP">DHCP</H1><P>This API publishes a routine to maintain DHCP state, and asemaphore that is signalled when a lease requires attention: thisis your clue to call the aforementioned routine.</P><P>The intent with this API is that a simple DHCP client thread,which maintains the state of the interfaces, can go as follows:(after <TTCLASS="FUNCTION">init_all_network_interfaces()</TT> iscalled from elsewhere)</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">while ( 1 ) {        while ( 1 ) {            cyg_semaphore_wait( &amp;dhcp_needs_attention );            if ( ! dhcp_bind() ) // a lease expired                break; // If we need to re-bind        }        dhcp_halt(); // tear everything down        init_all_network_interfaces(); // re-initialize}</PRE></TD></TR></TABLE><P>and if the application does not want to suffer the overheadof a separate thread and its stack for this, this functionalitycan be placed in the app&#8217;s server loop in an obvious fashion. That is the goal of breaking out these internal elements.  For example,some server might be arranged to poll DHCP from time to time likethis:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">while ( 1 ) {    init_all_network_interfaces();    open-my-listen-sockets();    while ( 1 ) {       serve-one-request();       // sleeps if no connections, but not forever;        // so this loop is polled a few times a minute...       if ( cyg_semaphore_trywait( &amp;dhcp_needs_attention )) {             if ( ! dhcp_bind() ) {                 close-my-listen-sockets();                 dhcp_halt();                 break;             }       }    }}</PRE></TD></TR></TABLE><P>If the configuration option CYGOPT_NET_DHCP_DHCP_THREADis defined, then eCos provides a thread as described initially.Independent of this option, initialization of the interfaces stilloccurs in <TTCLASS="FUNCTION">init_all_network_interfaces()</TT> andyour startup code can call that.  It will start the DHCP managementthread if configured.  If a lease fails to be renewed, the managementthread will shut down all interfaces and attempt to initialize allthe interfaces again from scratch.  This may cause chaos in theapp, which is why managing the DHCP state in an application awarethread is actually better, just far less convenient for testing.</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-common-support.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="tcpip-library-reference.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Support Features</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="net-common-support.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">TCP/IP Library Reference</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

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