Implementing a http server
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Implementing a http server




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Implementing a http server  
Peyman Taher


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-21-06 06:29 AM

I'm trying to implement a small http server to learn unix programming,
and there're few problems i'm trying to solve. I appreciate if you can
help.

suppose I have a PERL cgi source file, called "test.pl", and the server
recieves a request for that file, what i do is this:

each time i set the "chmod +x test.pl" using the chmod syscall, then i
putenv("QUERY_STRING="" "" ") and then execl("test.pl", "test.pl",
NULL).
first of all, what is the best way to do so? or how usually those web
servers that actually work, handle this?
then, now i need to redirect the output of the PERL program which goes
to STDOUT to the socket, and send it over the socket file descriptor,
how can i do that? is it done with popoen() or dup2()? which is better?
and another thing is that, if browser send some parameters (after ?
sign in request), then what i do is that i set the QUERY_STRING to that
value, BUT, PERL function param() which is supposed to parse
QUERY_STRING and retrive data, seems to not working for me. i set
QUERY_STRING envv and call the execl() to execute my PERL source file,
then in the PERL file i have this:

print "$ENV{QUERY_STRING}\n";

if (param) {
print "found a parameter";
}

the first line, does print the value i set for envv, meaning that the
envv pointer is passed to the program, but the param() thing, returns
false, meaning that there's no QUERY_STRING!!! why? what might be
wrong? I read the cgi-rfc, and it says that the only thing i need is to
set QUERY_STRING = query_string; and query_string = *somestring; and
somestring = reserved | unreserved | ..., which is exactly what i do!






[ Post a follow-up to this message ]



    Re: Implementing a http server  
Hubble


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-21-06 12:31 PM

Peyman Taher schrieb:

> I'm trying to implement a small http server to learn unix programming,
> and there're few problems i'm trying to solve. I appreciate if you can
> help.
>
> suppose I have a PERL cgi source file, called "test.pl", and the server
> recieves a request for that file, what i do is this:
>
> each time i set the "chmod +x test.pl" using the chmod syscall, then i
> putenv("QUERY_STRING="" "" ") and then execl("test.pl", "test.pl",
> NULL).
> first of all, what is the best way to do so? or how usually those web
> servers that actually work, handle this?
> then, now i need to redirect the output of the PERL program which goes
> to STDOUT to the socket, ...

First, the httpd should not use chmod +x. This is the job of the
administrator and/or setup program and needs only be done once.

IMHO, better use execle or execve and not use putenv. If you use
putenv, consider setenv, since it does not need parsing.

After fork(), use dup2 to copy the accepted file discriptor to
stdin/stdout.

outline:

fd=accept(...)
if (pid=fork())==0) {
dup2(fd,0);
dup2(fd,1);
.. setup vectors for execve
execve(...);

}

Notes: Remember to check the return values of all system calls for
errors. Needs a SIGCHLD signal handler to remove zombie processes.

After trying yourself, have a look at existing small httpd
implementations: For instance

http://www.acme.com/software/mini_httpd/
http://www.acme.com/software/micro_httpd/

Hubble






[ Post a follow-up to this message ]



    Re: Implementing a http server  
ilko.k.v@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-21-06 12:31 PM

You are need reading www.kegel.com






[ Post a follow-up to this message ]



    Re: Implementing a http server  
Peyman Taher


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-23-06 06:35 AM



On Dec 21, 5:01 pm, "Hubble" <rei...@huober.de> wrote:
> This is the job of the
> administrator and/or setup program and needs only be done once.
> ...
Thank you so much.






[ Post a follow-up to this message ]



    Re: Implementing a http server  
toby


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-23-06 06:35 AM

Hubble wrote:
> Peyman Taher schrieb:
> 
> After trying yourself, have a look at existing small httpd
> implementations: For instance
>
> http://www.acme.com/software/mini_httpd/
> http://www.acme.com/software/micro_httpd/

Here's a longer list, for posterity. Mainly these are selected because
they 1) are stable/mature 2) have simplicity and small footprint as
design goals. There are hundreds of other web servers out there that
don't have those two attributes. But I've probably missed some, and
some of those I've listed may not be suitable (unstable, etc).
Corrections welcome!

Best known
- thttpd
- lighttpd
- fnord
- Boa
- tux

Lesser known
- cherokee
- erlang based ones: yaws, httpd (inets), pico, ...
- thy
- monkey
- AppWeb
- Anti-Web httpd
- abyss
- mini-httpd
- muhttpd
- shttpd
- shttpdj
- Hiawatha
- phttpd
- AHD
- Embedded HTTP Server (EHS) - C++ class
- Seminole (*really* embeddable)
- And-httpd, webfs, darkhttpd, micro_httpd (static only)
- w3server

This is ignoring beta, Java/PHP/Python/Perl/etc implementations.


>
> Hubble






[ Post a follow-up to this message ]



    Re: Implementing a http server  
toby


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-23-06 06:35 AM


ilko.k.v@gmail.com wrote:
> You are need reading www.kegel.com

This thread isn't about scalability, but worth mentioning in the
context of Dan's site: Erlang has not hit Dan's radar yet. He asks "Why
Johnny can't serve 10K clients", while Erlang servers such as yaws have
been benchmarked with 80,000 concurrent connections
(http://www.sics.se/~joe/apachevsyaws.html), and should scale much
farther... A single Erlang system can reliably run tens of millions of
processes
(http://www.erlang.org/ml-archive/er...1/msg00118.html)
and a million-user benchmark is commonplace:
http://blog.jabber.com/filaments/20...ively-scalable/






[ Post a follow-up to this message ]



    Re: Implementing a http server  
ilko.k.v@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-25-06 06:16 PM

Author wrote - "I'm trying to implement a small http server to learn
unix programming ..."
Why ?
toby wrote:
> ilko.k.v@gmail.com wrote: 
>
> This thread isn't about scalability, but worth mentioning in the
> context of Dan's site: Erlang has not hit Dan's radar yet. He asks "Why
> Johnny can't serve 10K clients", while Erlang servers such as yaws have
> been benchmarked with 80,000 concurrent connections
> (http://www.sics.se/~joe/apachevsyaws.html), and should scale much
> farther... A single Erlang system can reliably run tens of millions of
> processes
> (http://www.erlang.org/ml-archive/er...1/msg00118.html)
> and a million-user benchmark is commonplace:
> http://blog.jabber.com/filaments/20...ively-scalable/






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 06:04 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register