A C library for writing thread-per-client TCP servers
License
basus/litepipe
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
# Litepipe Litepipe is a multithreaded server library. Litepipe handles the creation of sockets and the listening for incoming connection. Once a client makes a connection Litepipe spawns a separate thread to handle the connection. Client code provides the port number to listen on, the number of connections in the listening queue (the backlog) and a function that handles communication with a single client. ## Using Litepipe I've included a simple echo server that uses the Litepipe library to listen on a port and echo back whatever it receives. The Makefile contains rules to build Litepipe as a basic object file, a static library and a shared library. The simplest way to use Litepipe would be to just copy the litepipe.c and litepipe.h files into your project and compile them in as necessary (including the litepipe.h header). The lp_spawn() function takes 3 parameters: an integer for the port number, an integer for the backlog of clients to listen to and finally a function pointer of the form void*(*)(void*) (that communicates with the client). If it can succesfully create the sockets and wait for connection, it returns a pointer to thread that is currently listening. If there was an error it returns -1 (and error messages are printed to stderr). The communicator function gets a single argument -- a void pointer that points to an integer which is the file descriptor for the client socket (and can be used for the send() and recv() functions). The communicator is responsible for all actual communication with the client. Again, take a look at the echo server for a simple example. ## A brief history Litepipe began as a project for the Operating Systems class at Lafayette College in Spring 2010. The project was to create a multithreaded server and corresponding client to send data over a network. One of the requirements was to have the threading and networking code be separate from the rest of the application. For the original version, Berkin Ilbeyi wrote most of the library and the client and I built the server. After the project was over I decided to take the server and library components and rebuild them into a reusable library for building thread-per-client servers. The current code bears little resemblance to the original project code. In particular, the library does not handle sending and receiving messages over the network -- only accepting connections. ## What can I use Litepipe for? Litepipe spawns a thread for each client, which means that if you have thousands of clients, you could overwhelm the CPU. Litepipe is probably more suited for applications with a smaller number of clients that stay connected for a longer amount of time. Applications could include private chat or file servers. Honestly though, I'm leaving to others to come up with uses for it. It seemed like an interesting experiment to create something potentially useful and I had a good learning experience doing it. Enjoy!
About
A C library for writing thread-per-client TCP servers
Resources
License
Stars
Watchers
Forks
Packages 0
No packages published