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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [doc/] [html/] [ref/] [net-httpd-organization.html] - Blame information for rev 842

Go to most recent revision | 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
>Server Organization</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="Embedded HTTP Server"
23
HREF="net-httpd-chapter.html"><LINK
24
REL="PREVIOUS"
25
TITLE="Embedded HTTP Server"
26
HREF="net-httpd-chapter.html"><LINK
27
REL="NEXT"
28
TITLE="Server Configuration"
29
HREF="net-httpd-configuration.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-httpd-chapter.html"
58
ACCESSKEY="P"
59
>Prev</A
60
></TD
61
><TD
62
WIDTH="80%"
63
ALIGN="center"
64
VALIGN="bottom"
65
>Chapter 48. Embedded HTTP Server</TD
66
><TD
67
WIDTH="10%"
68
ALIGN="right"
69
VALIGN="bottom"
70
><A
71
HREF="net-httpd-configuration.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-HTTPD-ORGANIZATION">Server Organization</H1
86
><P
87
>The server consists of one or more threads running in parallel to any
88
application threads and which serve web pages to clients. Apart from
89
defining content, the application does not need to do anything to
90
start the HTTP server.</P
91
><P
92
>The HTTP server is started by a static constructor. This simply
93
creates an initial thread and sets it running. Since this is called
94
before the scheduler is started, nothing will happen until the
95
application calls <TT
96
CLASS="FUNCTION"
97
>cyg_scheduler_start()</TT
98
>.</P
99
><P
100
>When the thread gets to run it first optionally delays for some period
101
of time. This is to allow the application to perform any
102
initialization free of any interference from the HTTP server. When the
103
thread does finally run it creates a socket, binds it to the HTTP
104
server port, and puts it into listen mode. It will then create any
105
additional HTTPD server threads that have been configured before
106
becoming a server thread itself.</P
107
><P
108
>Each HTTPD server thread simply waits for a connection to be made to
109
the server port. When the connection is made it reads the HTTP request
110
and extracts the filename being accessed. If the request also contains
111
form data, this is also preserved. The filename is then looked up in a
112
table.</P
113
><P
114
>Each table entry contains a filename pattern string, a
115
pointer to a handler function, and a user defined argument for the
116
function. Table entries are defined using the same link-time table
117
building mechanism used to generate device tables. This is all handled
118
by the <TT
119
CLASS="LITERAL"
120
>CYG_HTTPD_TABLE_ENTRY()</TT
121
> macro which has the
122
following format:</P
123
><TABLE
124
BORDER="5"
125
BGCOLOR="#E0E0F0"
126
WIDTH="70%"
127
><TR
128
><TD
129
><PRE
130
CLASS="PROGRAMLISTING"
131
>&#13;#include &lt;cyg/httpd/httpd.h&gt;
132
 
133
CYG_HTTPD_TABLE_ENTRY( __name, __pattern, __handler, __arg )&#13;</PRE
134
></TD
135
></TR
136
></TABLE
137
><P
138
>The <TT
139
CLASS="PARAMETER"
140
><I
141
>__name</I
142
></TT
143
> argument is a variable name for the
144
table entry since C does not allow us to define anonymous data
145
structures. This name should be chosen so that it is unique and does
146
not pollute the name space. The <TT
147
CLASS="PARAMETER"
148
><I
149
>__pattern</I
150
></TT
151
>
152
argument is the match pattern. The <TT
153
CLASS="PARAMETER"
154
><I
155
>__handler</I
156
></TT
157
>
158
argument is a pointer to the handler function and
159
<TT
160
CLASS="PARAMETER"
161
><I
162
>__arg</I
163
></TT
164
> the user defined value.</P
165
><P
166
>The link-time table building means that several different pieces of
167
code can define server table entries, and so long as the patterns do
168
not clash they can be totally oblivious of each other. However, note
169
also that this mechanism does not guarantee the order in which entries
170
appear, this depends on the order of object files in the link, which
171
could vary from one build to the next. So any tricky pattern matching
172
that relies on this may not always work.</P
173
><P
174
>A request filename matches an entry in the table if either it exactly
175
matches the pattern string, or if the pattern ends in an asterisk, and
176
it matches everything up to that point. So for example the pattern
177
&quot;/monitor/threads.html&quot; will only match that exact filename,
178
but the pattern &quot;/monitor/thread-*&quot; will match
179
&quot;/monitor/thread-0040.html&quot;,
180
&quot;/monitor/thread-0100.html&quot; and any other filename starting
181
with &quot;/monitor/thread-&quot;.</P
182
><P
183
>When a pattern is matched, the hander function is called. It has the
184
following prototype:</P
185
><TABLE
186
BORDER="5"
187
BGCOLOR="#E0E0F0"
188
WIDTH="70%"
189
><TR
190
><TD
191
><PRE
192
CLASS="PROGRAMLISTING"
193
>cyg_bool cyg_httpd_handler(FILE *client,
194
                           char *filename,
195
                           char *formdata,
196
                           void *arg);</PRE
197
></TD
198
></TR
199
></TABLE
200
><P
201
>The <TT
202
CLASS="PARAMETER"
203
><I
204
>client</I
205
></TT
206
> argument is the TCP connection to
207
the client: anything output through this stream will be returned to
208
the browser. The <TT
209
CLASS="PARAMETER"
210
><I
211
>filename</I
212
></TT
213
> argument is the
214
filename from the HTTP request and the <TT
215
CLASS="PARAMETER"
216
><I
217
>formdata</I
218
></TT
219
>
220
argument is any form response data, or NULL if none was sent. The
221
<TT
222
CLASS="PARAMETER"
223
><I
224
>arg</I
225
></TT
226
> argument is the user defined value from the
227
table entry.</P
228
><P
229
>The handler is entirely responsible for generating the response to the
230
client, both HTTP header and content. If the handler decides that it
231
does not want to generate a response it can return
232
<TT
233
CLASS="LITERAL"
234
>false</TT
235
>, in which case the table scan is resumed for
236
another match. If no match is found, or no handler returns true, then
237
a default response page is generated indicating that the requested
238
page cannot be found.</P
239
><P
240
>Finally, the server thread closes the connection to the client and
241
loops back to accept a new connection.</P
242
></DIV
243
><DIV
244
CLASS="NAVFOOTER"
245
><HR
246
ALIGN="LEFT"
247
WIDTH="100%"><TABLE
248
SUMMARY="Footer navigation table"
249
WIDTH="100%"
250
BORDER="0"
251
CELLPADDING="0"
252
CELLSPACING="0"
253
><TR
254
><TD
255
WIDTH="33%"
256
ALIGN="left"
257
VALIGN="top"
258
><A
259
HREF="net-httpd-chapter.html"
260
ACCESSKEY="P"
261
>Prev</A
262
></TD
263
><TD
264
WIDTH="34%"
265
ALIGN="center"
266
VALIGN="top"
267
><A
268
HREF="ecos-ref.html"
269
ACCESSKEY="H"
270
>Home</A
271
></TD
272
><TD
273
WIDTH="33%"
274
ALIGN="right"
275
VALIGN="top"
276
><A
277
HREF="net-httpd-configuration.html"
278
ACCESSKEY="N"
279
>Next</A
280
></TD
281
></TR
282
><TR
283
><TD
284
WIDTH="33%"
285
ALIGN="left"
286
VALIGN="top"
287
>Embedded HTTP Server</TD
288
><TD
289
WIDTH="34%"
290
ALIGN="center"
291
VALIGN="top"
292
><A
293
HREF="net-httpd-chapter.html"
294
ACCESSKEY="U"
295
>Up</A
296
></TD
297
><TD
298
WIDTH="33%"
299
ALIGN="right"
300
VALIGN="top"
301
>Server Configuration</TD
302
></TR
303
></TABLE
304
></DIV
305
></BODY
306
></HTML
307
>

powered by: WebSVN 2.1.0

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