Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server based on beast. #512

Merged
merged 15 commits into from Dec 1, 2021
Merged

Server based on beast. #512

merged 15 commits into from Dec 1, 2021

Conversation

joka921
Copy link
Member

@joka921 joka921 commented Nov 25, 2021

No description provided.

Copy link
Member

@hannahbast hannahbast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detailed 1-1 with Johannes, thank you very much!

@joka921
Copy link
Member Author

joka921 commented Dec 1, 2021

@joaomarques90
Yes, you completely got my point. (Additionally I was tired).
At daylight I am confused about the following:

  1. Variables can be referenced in their own initialization (size_t x = &x; is valid,
  2. size_t x = x; also, but the latter case is rather pointless).
  3. Apparently this also holds, if the initialization is an immediately invoked lambda
    ( size_t x = []() {return x;}();)
  4. There must be some rationale behind this being valid (@hannahbast discovered the first case as an initialization of a somewhat random or at least nondeterministic seed in Google's absl library. But in the second case I am confused, that this works even if the lambda has no captures (size_t x = [x](){return x;}())

@joaomarques90
Copy link
Contributor

joaomarques90 commented Dec 1, 2021

When I said "pointer of vector-var 'types'" what I really meant was that the compiler already has that variable in stack (var name --> stack address line) exposed prior to the execution of the lambda.

Item 1.
size_t x = &x;
Shouldn't be valid due to pointer/type issues. But can if the compiler is permissive or you flag it.

Item 2.
size_t x = x;
It's redundant but valid. If you think on it by assembly: first declares it in memory, then copy the value to the register and then back to the memory. If the compiler is smart enough, it would even skip this, depending on the flag -Ox [except -O0] )

Item 3.

size_t x = []() {return x;}();
Invalid. Would work if, as mentioned above about this commit, it had a reference (or a copy). That lambda function does not have it in its own stack.

Item 4.
size_t x = [x](){return x;}()
Valid. It captures 'x' by value, not by reference, when you define the lambda. Therefore it has access to a copy of the var and its type. Two instances of the var in the memory for different stacks.

In all of them valid, the contents would be past-sediment-values.

I hope my answer does not contain errors. If so, my apologies.

@joka921
Copy link
Member Author

joka921 commented Dec 1, 2021

@joaomarques90 You are correct about everything,
see-here(godbolt) .

To clarify my answer:
size_t x = &x // doesn't work because of the wrong type
but
size_t x = reinterpret_cast<size_t>(&x) // would.
(the reason why this fails is unrelated to the original topic).

You are also right about the lambda captures,
size_t x = [](){return x;}(); // doesn't work because of missing capture. *BUT, and here we come to why no compiler complained about my bug:* static size_t x = {return x;}(); // compiles without any warning.

(In fact Clang 13 only warns about the non-static lambda capture variant, GCC 11 also about the "default" variant at item 1.)

(@joaomarques90 in Markdown as its used here,
best enclose code example in backticks it then looks like this and all characters are shown`.)
I have edited your comment to this style:)

Copy link
Member

@hannahbast hannahbast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another quick 1-1

@joka921 joka921 merged commit 6422b7c into ad-freiburg:master Dec 1, 2021
@joka921 joka921 deleted the f.beastServer branch December 1, 2021 13:50
joka921 added a commit that referenced this pull request Dec 1, 2021
* Implemented a Coroutine-Based HTTP-Server based on Boost::Beast.
* This is much cleaner code than the previous implementation using POSIX sockets.
* It also allows easier extension for Websockets/POST requests/ Accept Headers, which we want in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants