-
Notifications
You must be signed in to change notification settings - Fork 198
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
Calling setsockopts on unconnected socket #16
Comments
It's hardly possible for both the C and the C++ part because TCP client sockets are created and immediately connected after that in create_inet_stream_socket in C/inet/libinetsocket.c (actual socket()/connect() in lines 185+). From the viewpoint of libsocket++, it's an atomic operation. The only possibility I see at the moment is introducing some more parameters in create_inet_stream_socket which are passed to a setsockopt call. Or, if you want to especially set the SO_REUSEADDR flag, a boolean (in C: int) flag. |
I follow. Shouldn't the socket be created when the object is created (RAII) and then only connected when you call I think the more-parameter option is a decent one, but how would you set multiple options in a scalable way? The only possibility I see is accepting a |
It may at first seem as a better alternative to do it the RAII way you mentioned. But there comes a load of problems with it, the (in my opinion) most important one being the choice of the address family. Usually I would use Using an additional parameter |
Gotcha. That makes sense. If you are going to pass |
Hm... Didn't think of that... What about implementing |
That would work. There would be a lot of Also, oops, I didn't mean to close this. |
cf. https://github.com/dermesser/libsocket/blob/master/C/inet/libinetsocket.c#L572 Maybe a little more compact, and we're fine 👍 |
As far as I can tell, it isn't possible to set options on a socket without first getting it into the connected state. It would be useful to do this, for example, to set the socket option
SO_REUSEADDR
before connecting. The problem is that the socket isn't actually created until connection time.Using
setsockopt
withinet_stream::getfd
works fine after connecting, because the socket file descriptor is then valid.Am I missing something, or is this not possible?
The text was updated successfully, but these errors were encountered: