📜 ⬆️ ⬇️

Website development (web applications) in C ++ (and not only) in the form of link libraries (* .so, * .dll)

Introduction (lyrics)


About two years I was engaged in web development, creating websites and web applications in PHP. Here are just a web development, I came across a very strange life circumstances. Not to say that I was not interested - I was very interested in finding out how sites are created and how the Internet works.

But, at the same time, I was always attracted to low-level programming. During my studies, I really liked the C ++ programming language. Only there was nowhere to use it, except for their entertainment. Then I went down lower - I studied Assembler. I understood how the processor works (albeit too superficially) and how the programs actually run.

With all this set of knowledge and experience, I got into web development. Everything at first seemed very, very good, it turned out to be much easier than I thought. And over time, it became boring, it became too easy, uninteresting, there is no scope for optimizations and interesting solutions. You generate web pages, write and connect js-scripts, make out pages with css. I felt that I no longer develop as a programmer.

At that time, questions began to torment me:
')
  1. Why can't I create high performance web applications in a language like C ++ (not CGI)? After all, I like this language more than anyone else. I have never heard that there are sites written in C ++. Why?
  2. Why web development captured scripting (interpreted) programming languages?

With interpreted languages, of course, everything is clear. They are very convenient - no need to rebuild the entire project after making changes. In this case, all changes are applied on the fly, without restarting (stopping) the web application.

I was looking for the answer to the first question - how to write websites in C ++. On the Internet, nothing sensible on this topic is not found (only through CGI). And he was horrified: how is that? I want to be free to choose a development tool, I want to use the language that I like. And so far nobody has done anything? Or did, but uses only at home?

This made me start developing my own web server, where web applications (sites) would connect as libraries (* .so, * .dll).

(During development, I saw the light and understood how to use the HTTP protocol correctly - I learned what RESTful is. I learned how to build the architecture of web applications correctly. I was surprised how many sites do not meet the requirements of RESTful, that is, in fact, they do not work correctly) .

The essence


During the year of working on my own web server (which I am writing in C ++ of the most fashionable new standards), I managed to implement all the basic necessary functions:


Operating system support: Linux, Windows

How my web server works

The web server at startup connects to itself the libraries specified in the configuration files. Example:

server { listen 2280; server_name servertest www.servertest; server_module /media/projects/sites/servertest/module/servertest_release.so; server_module_update /media/projects/httpserverapp/httpserverapp/bin/Release/libhttpserverapp.so; root_dir /media/projects/sites/servertest/www/; request_max_size 10485760; } 

Where,

When connecting the library with the web application, the functions in it are searched for:


From the description it is clear that application_call is the main function of the web application, the entry point. All headers (disassembled separately), request data (URI - resource identifier (query string), “disassembled parameters?? Var1 = sample & var2 = 1000”), links to files (if transmitted), web application data are transferred to it (root directory). Each request is processed and executed in a separate thread (thread).

The peculiarity is that the client socket is also transmitted, with which you can (need) work directly.

The main work on the development of a web server can be said to have been completed. Already, the developer can create his own web applications in any programming language, the compilers of which allow building a project in the form of a library. For example, C and C ++.

Of course, you will need your own server (computer) to run such a web server (program) on it and enjoy the speed of web applications. Just remember that using a database dramatically reduces the performance of any application. But not so much to completely abandon the use of compiled languages.

Want to try?


The source code of the web server and the sample application is attached to it (used by IDE - Monodevelop).

The web server is distributed under the AGPL license.

What's next?


The web server is operational, but there is still something to work on (to put the code of some functions in order, to write comments on the code).

Further, I would like to take a closer look at and describe the structure of the web application, describe how to start development, for those who might be interested.

Now I am writing a framework for convenient development of C ++ web applications for my web server (not yet available). In fact, I am developing a website for one company. An ordinary site is nothing remarkable, but with optimizations. I use MariaDB DBMS.

Source: https://habr.com/ru/post/236865/


All Articles