Socket::reconfigure_socket called on connection to apply options
'TCP_NODELAY' is set automatically on connection now.
This commit is contained in:
parent
2a5d960e56
commit
e0e956cf78
@ -155,6 +155,12 @@ namespace fr
|
||||
virtual bool has_data() const = 0;
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* Applies requested socket options to the socket.
|
||||
* Should be called when a new socket is created.
|
||||
*/
|
||||
void reconfigure_socket();
|
||||
|
||||
std::string remote_address;
|
||||
bool is_blocking;
|
||||
bool is_connected;
|
||||
|
||||
@ -152,9 +152,11 @@ namespace fr
|
||||
return Socket::Status::VerificationFailed;
|
||||
}
|
||||
|
||||
//Update members
|
||||
//Update state
|
||||
is_connected = true;
|
||||
remote_address = address + ":" + port;
|
||||
reconfigure_socket();
|
||||
|
||||
return Socket::Status::Success;
|
||||
}
|
||||
|
||||
@ -167,6 +169,7 @@ namespace fr
|
||||
{
|
||||
is_connected = true;
|
||||
ssl_socket_descriptor = std::move(context);
|
||||
reconfigure_socket();
|
||||
}
|
||||
|
||||
bool SSLSocket::has_data() const
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
// Created by fred on 06/12/16.
|
||||
//
|
||||
|
||||
#include <netinet/tcp.h>
|
||||
#include "frnetlib/Socket.h"
|
||||
|
||||
namespace fr
|
||||
@ -97,4 +98,11 @@ namespace fr
|
||||
{
|
||||
::shutdown(get_socket_descriptor(), 0);
|
||||
}
|
||||
|
||||
void Socket::reconfigure_socket()
|
||||
{
|
||||
//todo: Perhaps allow for these settings to be modified
|
||||
int one = 1;
|
||||
setsockopt(get_socket_descriptor(), SOL_TCP, TCP_NODELAY, &one, sizeof(one));
|
||||
}
|
||||
}
|
||||
@ -100,14 +100,13 @@ namespace fr
|
||||
|
||||
void TcpSocket::set_descriptor(int descriptor)
|
||||
{
|
||||
reconfigure_socket();
|
||||
socket_descriptor = descriptor;
|
||||
is_connected = true;
|
||||
}
|
||||
|
||||
Socket::Status TcpSocket::connect(const std::string &address, const std::string &port)
|
||||
{
|
||||
remote_address = address + ":" + port;
|
||||
|
||||
addrinfo *info;
|
||||
addrinfo hints;
|
||||
|
||||
@ -145,7 +144,11 @@ namespace fr
|
||||
//We're done with this now, cleanup
|
||||
freeaddrinfo(info);
|
||||
|
||||
//Update state now we've got a valid socket descriptor
|
||||
is_connected = true;
|
||||
remote_address = address + ":" + port;
|
||||
reconfigure_socket();
|
||||
|
||||
return Socket::Status::Success;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user