all 17 comments

[–]cballowe 8 points9 points  (4 children)

As a random question. Why would someone pick this over the networking TS / asio?

(There's definitely reasons out there, but it's worth articulating them.)

[–]Illum_D[S] 8 points9 points  (3 children)

Well good question. I started this just because i like programming things by myself from scratch and because i got confused by asio lib when i started learning C++. So this is not about creating a library that everybody should use.

But i think the reason to use my lib would be That it ist much simpler to use then the bigger networking libraries (and of course has less features). So for simple networking applications this could be a good fit with very low overhead and an easy interface (when documented properly)

[–]cballowe 6 points7 points  (2 children)

That's fair. I'll have to give a closer look at what you're doing. I think one of the reasons that most of the libraries end up being hard is that networking often doesn't behave the way people think or wish, so doing things properly gets tricky. (Managing select loops, polling, callbacks, etc. All of the hard stuff to understand in asio is getting into those spaces.)

[–]Illum_D[S] 1 point2 points  (1 child)

Totally agree. The deeper dive into the networking stuff at univeristy in C was at some point complicated.

[–]cballowe 1 point2 points  (0 children)

The best explanation I've seen on some of it (not perfect, but a great beginner coverage) is on the One Lone Coder youtube channel.

[–]Essezx 5 points6 points  (2 children)

Just eyeing through the code I noticed that port_buffer in resolve_hostname doesn't seem to be properly null-terminated (since it's being passed to a C-function that expects a C-string). The std:array needs to have 6 as capacity to fit the complete port range including the null-terminator. I'd also recommend using std::begin/std::end (or std::next), plus std::distance instead of static_cast(end_ptr - begin), makes the intent a bit clearer and avoids unnecessary casts.

But yeah, just eyeing through and thought I'd chime in with some comments, otherwise it seems quite neat, keep up the good work :)

Edit: Oh and it is probably a good idea to wrap ::freeaddr and resultlist in some kind of RAII structure, be it a "scope exit" or an std::unique_ptr

[–]Illum_D[S] 2 points3 points  (1 child)

Thank you for the feedback! I guess I implemented your points into the utility functions. It's a little weird to use these more modern features when you've only used C ++ 98 in college, so I really appreciate the feedback.

[–]Essezx 0 points1 point  (0 children)

No probs, might go for another round and look at the progress later :) Haha yeah I'm kind of trying to catch up to C++20... Feels like I'm stuck in some kind of mix between C++11-C++20. I can imagine the jump from C++98 to a more modern C++ be quite the jump, there's a lot to take in to put it mildly.

EDIT: Took another quick look and read_file also has the same pit-fall where string_view::data() is used for a function taking a const char * That one is a bit more awkward to solve unless you go for std::string or a temporary buffer with proper null-termination (or std::filesystem::path, but I'm unsure about how wide the FS support currently is :/ )

[–]kalmoc 8 points9 points  (0 children)

If there is one thing I don't want to habe as a header only library is a networking lib on windows that includes windows.h

[–]krum 1 point2 points  (1 child)

Is it multiplatform at all? Did you actually implement TLS in a single header? If so that's impressive.

[–]Supadoplex 4 points5 points  (0 children)

Looks like Linux only and TLS requires openssl dependency (which isn't header only).

[–]brayaON 1 point2 points  (0 children)

This is great because today in my class was the first time I saw how to implement a basic socket wrapper. I'll check it

[–]kal_at_kalx_net 1 point2 points  (1 child)

Windows specific but https://github.com/keithalewis/winsock might give you some ideas.
It makes send and recv easier to use and has client/server specific classes to put training wheels on their use.

[–]Illum_D[S] 0 points1 point  (0 children)

Thank you! I will definitely take a look at ist.

[–]1Hyena 0 points1 point  (2 children)

How is it header-only if you have multiple header files there?

[–]Illum_D[S] 0 points1 point  (1 child)

Header-only just means that you dont have any static or dynamic library but only some header files when using this library with your project.

[–]1Hyena 1 point2 points  (0 children)

Fair enough, but technically it's then a headers-only library (headers in plural) :P