E
E
Evengard2012-06-08 23:23:26
Programming
Evengard, 2012-06-08 23:23:26

Best practice to implement HTTP(S) proxy server?

Hello, dear Khabrovites!

I was going to write an HTTP (S) proxy server with certain additional functionality, to which several clients will connect, and he, in turn, will also connect to another proxy server. Some intermediate proxy.
It is extremely important that keep-alive works.

And advice is needed here in what - how to implement? The simplest option seems to be implementation on threads (we create our own thread for each client, and we drive data back and forth). But ... I want something better and more productive - there are a very limited amount of resources.
The problem is that I am a complete layman in asynchronous programming. Can you advise how to get started? Can you throw good manuals at me for such cases? Or still not bother and do on threads? Again, can you recommend a better implementation technique? Will you throw manuals at me?

What is the best way to organize this proxy?

It is written under WinXP SP3, but by means of MinGW.

I apologize for the confusion of the question, I couldn’t do something better ... If something is not clear, please clarify!

Answer the question

In order to leave comments, you need to log in

6 answer(s)
V
Vladimir Dubrovin, 2012-06-09
@Evengard

Under Windows, the option one client - one thread is optimal if you do not need a very large number of simultaneous connections (say, about 10,000). If something very highly loaded is required, then one thread is used - n clients on asynchronous non-blocking sockets with an increase in the number of threads as necessary.
But again, I can suggest writing a plugin for 3proxy if its functionality is not enough.

R
RubtsovAV, 2012-06-09
@RubtsovAV

The flow option is the most reliable. There is such a thing as non-blocking sockets, maybe they will suit you, the second link in Google www.cyberforum.ru/cpp-linux/thread346566.html

M
mitnlag, 2012-06-08
@mitnlag

Instead of a manual, I will give advice. Write a module for nginx.

A
Alexey Akulovich, 2012-06-09
@AterCattus

libevent / libev may well be of help if you decide to write from scratch

A
AxisPod, 2012-06-09
@AxisPod

I would advise you to look for a ready-made open source project, take and finish the functionality. Especially given the lack of serious experience in this area.
If you really want to, I would advise you to use the asio library, which exists both in the boost package and separately. It’s better, of course, along with boost, right there there are good examples of the implementation of asynchronous servers that can be taken as a basis.

R
RubtsovAV, 2012-06-09
@RubtsovAV

By the way, there is also an option with a thread pool, where a certain minimum number of running threads is always maintained in the process. Thus, when clients connect, resources will not be spent on creating threads. This solution will work well only on multi-core systems and with a large number of clients. On a single core, non-blocking sockets are the best option. more economical in resources.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question