OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [doc/] [html/] [ref/] [net-common-dhcp.html] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 28 unneback
<!-- 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.               -->
9
<HTML
10
><HEAD
11
><TITLE
12
>DHCP</TITLE
13
><meta name="MSSmartTagsPreventParsing" content="TRUE">
14
<META
15
NAME="GENERATOR"
16
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
17
"><LINK
18
REL="HOME"
19
TITLE="eCos Reference Manual"
20
HREF="ecos-ref.html"><LINK
21
REL="UP"
22
TITLE="Support Features"
23
HREF="net-common-support.html"><LINK
24
REL="PREVIOUS"
25
TITLE="Support Features"
26
HREF="net-common-support.html"><LINK
27
REL="NEXT"
28
TITLE="TCP/IP Library Reference"
29
HREF="tcpip-library-reference.html"></HEAD
30
><BODY
31
CLASS="SECT1"
32
BGCOLOR="#FFFFFF"
33
TEXT="#000000"
34
LINK="#0000FF"
35
VLINK="#840084"
36
ALINK="#0000FF"
37
><DIV
38
CLASS="NAVHEADER"
39
><TABLE
40
SUMMARY="Header navigation table"
41
WIDTH="100%"
42
BORDER="0"
43
CELLPADDING="0"
44
CELLSPACING="0"
45
><TR
46
><TH
47
COLSPAN="3"
48
ALIGN="center"
49
>eCos Reference Manual</TH
50
></TR
51
><TR
52
><TD
53
WIDTH="10%"
54
ALIGN="left"
55
VALIGN="bottom"
56
><A
57
HREF="net-common-support.html"
58
ACCESSKEY="P"
59
>Prev</A
60
></TD
61
><TD
62
WIDTH="80%"
63
ALIGN="center"
64
VALIGN="bottom"
65
>Chapter 37. Support Features</TD
66
><TD
67
WIDTH="10%"
68
ALIGN="right"
69
VALIGN="bottom"
70
><A
71
HREF="tcpip-library-reference.html"
72
ACCESSKEY="N"
73
>Next</A
74
></TD
75
></TR
76
></TABLE
77
><HR
78
ALIGN="LEFT"
79
WIDTH="100%"></DIV
80
><DIV
81
CLASS="SECT1"
82
><H1
83
CLASS="SECT1"
84
><A
85
NAME="NET-COMMON-DHCP">DHCP</H1
86
><P
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
90
><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:
93
(after <TT
94
CLASS="FUNCTION"
95
>init_all_network_interfaces()</TT
96
> is
97
called from elsewhere)</P
98
><TABLE
99
BORDER="5"
100
BGCOLOR="#E0E0F0"
101
WIDTH="70%"
102
><TR
103
><TD
104
><PRE
105
CLASS="PROGRAMLISTING"
106
>while ( 1 ) {
107
        while ( 1 ) {
108
            cyg_semaphore_wait( &amp;dhcp_needs_attention );
109
            if ( ! dhcp_bind() ) // a lease expired
110
                break; // If we need to re-bind
111
        }
112
        dhcp_halt(); // tear everything down
113
        init_all_network_interfaces(); // re-initialize
114
}</PRE
115
></TD
116
></TR
117
></TABLE
118
><P
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&#8217;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
124
this:</P
125
><TABLE
126
BORDER="5"
127
BGCOLOR="#E0E0F0"
128
WIDTH="70%"
129
><TR
130
><TD
131
><PRE
132
CLASS="PROGRAMLISTING"
133
>while ( 1 ) {
134
    init_all_network_interfaces();
135
    open-my-listen-sockets();
136
    while ( 1 ) {
137
       serve-one-request();
138
       // sleeps if no connections, but not forever;
139
       // so this loop is polled a few times a minute...
140
       if ( cyg_semaphore_trywait( &amp;dhcp_needs_attention )) {
141
             if ( ! dhcp_bind() ) {
142
                 close-my-listen-sockets();
143
                 dhcp_halt();
144
                 break;
145
             }
146
       }
147
    }
148
}</PRE
149
></TD
150
></TR
151
></TABLE
152
><P
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
156
occurs in <TT
157
CLASS="FUNCTION"
158
>init_all_network_interfaces()</TT
159
> and
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
166
></DIV
167
><DIV
168
CLASS="NAVFOOTER"
169
><HR
170
ALIGN="LEFT"
171
WIDTH="100%"><TABLE
172
SUMMARY="Footer navigation table"
173
WIDTH="100%"
174
BORDER="0"
175
CELLPADDING="0"
176
CELLSPACING="0"
177
><TR
178
><TD
179
WIDTH="33%"
180
ALIGN="left"
181
VALIGN="top"
182
><A
183
HREF="net-common-support.html"
184
ACCESSKEY="P"
185
>Prev</A
186
></TD
187
><TD
188
WIDTH="34%"
189
ALIGN="center"
190
VALIGN="top"
191
><A
192
HREF="ecos-ref.html"
193
ACCESSKEY="H"
194
>Home</A
195
></TD
196
><TD
197
WIDTH="33%"
198
ALIGN="right"
199
VALIGN="top"
200
><A
201
HREF="tcpip-library-reference.html"
202
ACCESSKEY="N"
203
>Next</A
204
></TD
205
></TR
206
><TR
207
><TD
208
WIDTH="33%"
209
ALIGN="left"
210
VALIGN="top"
211
>Support Features</TD
212
><TD
213
WIDTH="34%"
214
ALIGN="center"
215
VALIGN="top"
216
><A
217
HREF="net-common-support.html"
218
ACCESSKEY="U"
219
>Up</A
220
></TD
221
><TD
222
WIDTH="33%"
223
ALIGN="right"
224
VALIGN="top"
225
>TCP/IP Library Reference</TD
226
></TR
227
></TABLE
228
></DIV
229
></BODY
230
></HTML
231
>

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.