0

How can I modify the server_http.hpp file in the Http Server Library to set SO_REUSEPORT on the socket? Or how can I pass in a fd. (the systemd .socket file will need ReusePort=yes for that).

https://github.com/eidheim/Simple-Web-Server/blob/master/server_http.hpp

island slangz
  • 105
  • 2
  • 7

1 Answers1

2

SO_REUSEPORT doesn't exist in Windows, so there is only system-dependent solution:

#include <arpa/inet.h>

/// ... 
int opt = 1;
::setsockopt(acceptor.native_handle(), SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt));

But in general, I think you should ask yourself, why do you need it?

  • @islandslangz then don't you need to use the socket that systemd transferred to you? – user253751 Aug 09 '22 at 18:49
  • I see. It's not clear from your code that you want to use the same socket. In that case you should add in your systemd.service file, in `Service` section line `StandardInput=socket`. In that case systemd will start your service and provide you fd as argument. You can call `socket.assign()` to assign that fd to your boost socket. – Maksim Demianov Aug 09 '22 at 19:02