mirror of
https://github.com/sogou/workflow.git
synced 2026-10-28 02:56:43 +08:00
fix default port bug
This commit is contained in:
@@ -303,45 +303,39 @@ void WFComplexClientTask<REQ, RESP, CTX>::init(TransportType type,
|
||||
template<class REQ, class RESP, typename CTX>
|
||||
bool WFComplexClientTask<REQ, RESP, CTX>::set_port()
|
||||
{
|
||||
int port = 0;
|
||||
|
||||
if (uri_.port && uri_.port[0])
|
||||
if (uri_.port)
|
||||
{
|
||||
port = atoi(uri_.port);
|
||||
if (port < 0 || port > 65535)
|
||||
int port = atoi(uri_.port);
|
||||
|
||||
if (port <= 0 || port > 65535)
|
||||
{
|
||||
this->state = WFT_STATE_TASK_ERROR;
|
||||
this->error = WFT_ERR_URI_PORT_INVALID;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (port == 0 && uri_.scheme)
|
||||
if (uri_.scheme)
|
||||
{
|
||||
const char *port_str = WFGlobal::get_default_port(uri_.scheme);
|
||||
|
||||
if (port_str)
|
||||
{
|
||||
size_t port_len = strlen(port_str);
|
||||
|
||||
uri_.port = strdup(port_str);
|
||||
if (uri_.port)
|
||||
free(uri_.port);
|
||||
return true;
|
||||
|
||||
uri_.port = (char *)malloc(port_len + 1);
|
||||
if (!uri_.port)
|
||||
{
|
||||
uri_.state = URI_STATE_ERROR;
|
||||
uri_.error = errno;
|
||||
this->state = WFT_STATE_SYS_ERROR;
|
||||
this->error = errno;
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(uri_.port, port_str, port_len + 1);
|
||||
this->state = WFT_STATE_SYS_ERROR;
|
||||
this->error = errno;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
this->state = WFT_STATE_TASK_ERROR;
|
||||
this->error = WFT_ERR_URI_SCHEME_INVALID;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class REQ, class RESP, typename CTX>
|
||||
|
||||
@@ -60,19 +60,22 @@ public:
|
||||
settings_ = *settings;
|
||||
}
|
||||
|
||||
const char *get_default_port(const std::string& scheme) const
|
||||
const char *get_default_port(const std::string& scheme)
|
||||
{
|
||||
const auto it = static_scheme_port_.find(scheme);
|
||||
|
||||
if (it != static_scheme_port_.end())
|
||||
return it->second;
|
||||
|
||||
const char *port = NULL;
|
||||
user_scheme_port_mutex_.lock();
|
||||
const auto it2 = user_scheme_port_.find(scheme);
|
||||
|
||||
if (it2 != user_scheme_port_.end())
|
||||
return it2->second.c_str();
|
||||
port = it2->second.c_str();
|
||||
|
||||
return NULL;
|
||||
user_scheme_port_mutex_.unlock();
|
||||
return port;
|
||||
}
|
||||
|
||||
void register_scheme_port(const std::string& scheme, unsigned short port)
|
||||
|
||||
Reference in New Issue
Block a user