1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="Support Features"
23 HREF="net-common-support.html"><LINK
25 TITLE="Support Features"
26 HREF="net-common-support.html"><LINK
28 TITLE="TCP/IP Library Reference"
29 HREF="tcpip-library-reference.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="net-common-support.html"
65 >Chapter 37. Support Features</TD
71 HREF="tcpip-library-reference.html"
85 NAME="NET-COMMON-DHCP">DHCP</H1
87 >This API publishes a routine to maintain DHCP state, and a
88 semaphore that is signalled when a lease requires attention: this
89 is your clue to call the aforementioned routine.</P
91 >The intent with this API is that a simple DHCP client thread,
92 which maintains the state of the interfaces, can go as follows:
95 >init_all_network_interfaces()</TT
97 called from elsewhere)</P
105 CLASS="PROGRAMLISTING"
108 cyg_semaphore_wait( &dhcp_needs_attention );
109 if ( ! dhcp_bind() ) // a lease expired
110 break; // If we need to re-bind
112 dhcp_halt(); // tear everything down
113 init_all_network_interfaces(); // re-initialize
119 >and if the application does not want to suffer the overhead
120 of a separate thread and its stack for this, this functionality
121 can be placed in the app’s server loop in an obvious fashion.
122 That is the goal of breaking out these internal elements. For example,
123 some server might be arranged to poll DHCP from time to time like
132 CLASS="PROGRAMLISTING"
134 init_all_network_interfaces();
135 open-my-listen-sockets();
138 // sleeps if no connections, but not forever;
139 // so this loop is polled a few times a minute...
140 if ( cyg_semaphore_trywait( &dhcp_needs_attention )) {
141 if ( ! dhcp_bind() ) {
142 close-my-listen-sockets();
153 >If the configuration option CYGOPT_NET_DHCP_DHCP_THREAD
154 is defined, then eCos provides a thread as described initially.
155 Independent of this option, initialization of the interfaces still
158 >init_all_network_interfaces()</TT
160 your startup code can call that. It will start the DHCP management
161 thread if configured. If a lease fails to be renewed, the management
162 thread will shut down all interfaces and attempt to initialize all
163 the interfaces again from scratch. This may cause chaos in the
164 app, which is why managing the DHCP state in an application aware
165 thread is actually better, just far less convenient for testing.</P
172 SUMMARY="Footer navigation table"
183 HREF="net-common-support.html"
201 HREF="tcpip-library-reference.html"
211 >Support Features</TD
217 HREF="net-common-support.html"
225 >TCP/IP Library Reference</TD