Your Own Personal WEB Server

"Нечего делать" - это очень сильный стимул. Иногда человек от нечего делать делает гораздо больше, чем от стимула "надо сделать". Это типа эпиграф такой, хех...

Initialization

Upon startup server:

Stage is described by struct worker in swebs.h header file:


	struct worker {

		char *name;
		void* (*action)(void*);

		char *in_queue_name;
		struct job_queue *in;

		char *out_queue_name;
		struct job_queue *out;

		char *aux_queue_name;
		struct job_queue *aux;
	};

Fields in this structure have following meanings:

struct job_queue looks like this:


	struct job_queue {
		char *to_whom;
		int rdfd;
		int wrfd;
		int load;
	};

where

The diagram below illustrates relations between stages:


				############
				# ACCEPTOR #
				############
				     |_________
                		     V	       |
				############   |
			  	# FETCHER  #   |
				############   |
				     |         |
				     V         |
				############   |
				#  SENDER  #___|
				############
				     |
				     V
				############
				#  LOGGER  #
				############

All worker types (stages) are described below.

Acceptor

Acceptor uses epoll_wait() for polling listening and data sockets and is responsible for:

struct job looks like this:

	struct job {
		struct connection *cnx;
		int sock;
		time_t when;
		int num;
		char who[IP_STR_LEN + 1];
		struct http_request_header hdr;

		int is_last;
		char content_type[64 + 1];
		char index_file[128 + 1];
		struct stat finfo;

		int response_hlen;
		int response_blen;
		size_t from_byte;
		size_t upto_byte;
		off_t offs;

		int fd;
		unsigned char *buf;
		size_t fetched;
		size_t sent;
		int buf_sent;
		int buf_total;

		int status;
		int done;
		nt pollinfd;
		char reason_500[16];
	}

Fetcher

There are following actions in the fetcher loop:

Sender

Sender thread in its' loop does the following:

Logger

Logger is the final element in the stage chain. It

Monitor

This one executes in the main thread of the server and in it's infinite loop:

File Descriptor Cache

In order not to waste file descriptors YOPS makes use of file descriptor cache (FDC). Caching file descriptors means that if 100 clients are downloading same file simultaneously, YOPS is using only one file descriptor for this file, not 100. For details see fd-cache.h in the source.

Note: if you want to raise the number of open files limit,
edit /etc/security/limits.conf accordingly.