mirror of
https://github.com/oatpp/oatpp.git
synced 2025-04-06 18:40:24 +08:00
network: Address family parameter for connection providers.
This commit is contained in:
parent
894fc19402
commit
ef721f6218
@ -26,6 +26,10 @@
|
||||
|
||||
namespace oatpp { namespace network {
|
||||
|
||||
|
||||
Address::Address(const oatpp::String& pHost, v_uint16 pPort, Family pFamily)
|
||||
: host(pHost)
|
||||
, port(pPort)
|
||||
, family(pFamily)
|
||||
{}
|
||||
|
||||
}}
|
||||
|
@ -32,7 +32,8 @@ namespace oatpp { namespace network {
|
||||
/**
|
||||
* Network address.
|
||||
*/
|
||||
struct Address {
|
||||
class Address {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Address family.
|
||||
@ -42,14 +43,29 @@ struct Address {
|
||||
/**
|
||||
* IPv4.
|
||||
*/
|
||||
IPv4 = 0,
|
||||
IP_4 = 0,
|
||||
|
||||
/**
|
||||
* IPv6.
|
||||
*/
|
||||
IPv6 = 1
|
||||
IP_6 = 1,
|
||||
|
||||
/**
|
||||
* Unspecified.
|
||||
*/
|
||||
UNSPEC = 2
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param pHost
|
||||
* @param pPort
|
||||
* @param pFamily
|
||||
*/
|
||||
Address(const oatpp::String& pHost, v_uint16 pPort, Family pFamily = UNSPEC);
|
||||
|
||||
/**
|
||||
* Host name without schema and port. Ex.: "oatpp.io", "127.0.0.1", "localhost".
|
||||
*/
|
||||
|
@ -57,11 +57,17 @@ std::shared_ptr<oatpp::data::stream::IOStream> ConnectionProvider::get() {
|
||||
struct addrinfo hints;
|
||||
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = 0;
|
||||
hints.ai_protocol = 0;
|
||||
|
||||
switch(m_address.family) {
|
||||
case Address::IP_4: hints.ai_family = AF_INET; break;
|
||||
case Address::IP_6: hints.ai_family = AF_INET6; break;
|
||||
default:
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
}
|
||||
|
||||
struct addrinfo* result;
|
||||
auto res = getaddrinfo(m_address.host->c_str(), portStr->c_str(), &hints, &result);
|
||||
|
||||
@ -149,11 +155,17 @@ oatpp::async::CoroutineStarterForResult<const std::shared_ptr<oatpp::data::strea
|
||||
struct addrinfo hints;
|
||||
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = 0;
|
||||
hints.ai_protocol = 0;
|
||||
|
||||
switch(m_address.family) {
|
||||
case Address::IP_4: hints.ai_family = AF_INET; break;
|
||||
case Address::IP_6: hints.ai_family = AF_INET6; break;
|
||||
default:
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
}
|
||||
|
||||
// TODO make call to get addrinfo non-blocking !!!
|
||||
auto res = getaddrinfo(m_address.host->c_str(), portStr->c_str(), &hints, &m_result);
|
||||
if (res != 0) {
|
||||
|
@ -105,11 +105,17 @@ oatpp::v_io_handle ConnectionProvider::instantiateServer(){
|
||||
struct addrinfo hints;
|
||||
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = 0;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
|
||||
switch(m_address.family) {
|
||||
case Address::IP_4: hints.ai_family = AF_INET; break;
|
||||
case Address::IP_6: hints.ai_family = AF_INET6; break;
|
||||
default:
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
}
|
||||
|
||||
auto portStr = oatpp::utils::conversion::int32ToStr(m_address.port);
|
||||
|
||||
iResult = getaddrinfo(m_address.host->c_str(), portStr->c_str(), &hints, &result);
|
||||
@ -166,11 +172,17 @@ oatpp::v_io_handle ConnectionProvider::instantiateServer(){
|
||||
struct addrinfo hints;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = 0;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
|
||||
switch(m_address.family) {
|
||||
case Address::IP_4: hints.ai_family = AF_INET; break;
|
||||
case Address::IP_6: hints.ai_family = AF_INET6; break;
|
||||
default:
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
}
|
||||
|
||||
auto portStr = oatpp::utils::conversion::int32ToStr(m_address.port);
|
||||
|
||||
ret = getaddrinfo(m_address.host->c_str(), portStr->c_str(), &hints, &result);
|
||||
|
Loading…
x
Reference in New Issue
Block a user