Giter Club home page Giter Club logo

webserver's Introduction

Webserver

I wrote this code as an exercise in systems programming with C. This is a simple multi-threaded webserver. Each request is executed in a separate thread and the threads are managed by a thread pool.

How does it work?

The webserver serves cgi scripts, located in the cgi-bin subdirectory and static files, located in the static subdirectory.

Usage:

$ make server
gcc -c -o server.o server.c
gcc -c -o threadpool.o threadpool.c
gcc -o server server.o threadpool.o
$ ./server
Running on port: 8000

(In a separate terminal)
$ curl 'localhost:8000/cgi-bin/simple.py?num1=5&num2=7'
Content-Type:text/html

<h1>Addition Results</h1>
<p>5 + 7 = 12</p>

$ curl localhost:8000/static/example_org.html
<!doctype html>
  ...
  ...
</html>

Or you can use the client binary:
$ make client
gcc -pthread -std=gnu99 -ggdb -c -o client.o client.c
gcc -pthread -std=gnu99 -ggdb -o client client.o

$ ./client '/cgi-bin/simple.py?num1=5&num2=7'
GET /cgi-bin/simple.py?num1=5&num2=7 HTTP/1.1
Server: PetkoWS/1.0 (MacOS)
Content-Type: text/html
...

$ ./client /static/example_org.html
GET /static/example_org.html HTTP/1.1
Server: PetkoWS/1.0 (MacOS)
Content-Type: text/html
...

Debugging

It's pretty easy to create memory leaks in C. Therefore, it's highly recommended to use valgrind to check for them:

$ make server && valgrind --leak-check=full  ./server

Run some queries and press Ctrl-C in valgrind. You'll see a list of memory leaks.

webserver's People

Contributors

pminkov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.