Source release 16.2.0
This commit is contained in:
@@ -4,22 +4,22 @@
|
||||
|
||||
#include "http_socket.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include "winsock2.h"
|
||||
# include "ws2tcpip.h"
|
||||
# define ERROR_ASYNC_COMPLETE WSAEWOULDBLOCK
|
||||
# include "winsock2.h"
|
||||
# include "ws2tcpip.h"
|
||||
# define ERROR_ASYNC_COMPLETE WSAEWOULDBLOCK
|
||||
#else
|
||||
# include <netdb.h>
|
||||
# include <netinet/in.h>
|
||||
# include <sys/socket.h>
|
||||
# include <unistd.h>
|
||||
# define ERROR_ASYNC_COMPLETE EINPROGRESS
|
||||
# include <netdb.h>
|
||||
# include <netinet/in.h>
|
||||
# include <sys/socket.h>
|
||||
# include <unistd.h>
|
||||
# define ERROR_ASYNC_COMPLETE EINPROGRESS
|
||||
#endif
|
||||
|
||||
#include <openssl/bio.h>
|
||||
@@ -60,16 +60,15 @@ SSL_CTX* InitSslContext() {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static int LogBoringSslError(
|
||||
const char* message, size_t length, void* /* user_data */) {
|
||||
static int LogBoringSslError(const char* message, size_t length,
|
||||
void* /* user_data */) {
|
||||
LOGE(" BoringSSL Error: %s", message);
|
||||
return length;
|
||||
}
|
||||
|
||||
bool IsRetryableSslError(int ssl_error) {
|
||||
return ssl_error != SSL_ERROR_ZERO_RETURN &&
|
||||
ssl_error != SSL_ERROR_SYSCALL &&
|
||||
ssl_error != SSL_ERROR_SSL;
|
||||
return ssl_error != SSL_ERROR_ZERO_RETURN && ssl_error != SSL_ERROR_SYSCALL &&
|
||||
ssl_error != SSL_ERROR_SSL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -105,15 +104,15 @@ bool SocketWait(int fd, bool for_read, int timeout_in_ms) {
|
||||
tv.tv_sec = timeout_in_ms / 1000;
|
||||
tv.tv_usec = (timeout_in_ms % 1000) * 1000;
|
||||
|
||||
fd_set* read_fds = NULL;
|
||||
fd_set* write_fds = NULL;
|
||||
fd_set* read_fds = nullptr;
|
||||
fd_set* write_fds = nullptr;
|
||||
if (for_read) {
|
||||
read_fds = &fds;
|
||||
} else {
|
||||
write_fds = &fds;
|
||||
}
|
||||
|
||||
int ret = select(fd + 1, read_fds, write_fds, NULL, &tv);
|
||||
int ret = select(fd + 1, read_fds, write_fds, nullptr, &tv);
|
||||
if (ret == 0) {
|
||||
LOGE("socket timed out");
|
||||
return false;
|
||||
@@ -209,7 +208,7 @@ bool HttpSocket::ParseUrl(const std::string& url, std::string* scheme,
|
||||
}
|
||||
|
||||
HttpSocket::HttpSocket(const std::string& url)
|
||||
: socket_fd_(-1), ssl_(NULL), ssl_ctx_(NULL) {
|
||||
: socket_fd_(-1), ssl_(nullptr), ssl_ctx_(nullptr) {
|
||||
valid_url_ = ParseUrl(url, &scheme_, &secure_connect_, &domain_name_, &port_,
|
||||
&resource_path_);
|
||||
SSL_library_init();
|
||||
@@ -228,11 +227,11 @@ void HttpSocket::CloseSocket() {
|
||||
}
|
||||
if (ssl_) {
|
||||
SSL_free(ssl_);
|
||||
ssl_ = NULL;
|
||||
ssl_ = nullptr;
|
||||
}
|
||||
if (ssl_ctx_) {
|
||||
SSL_CTX_free(ssl_ctx_);
|
||||
ssl_ctx_ = NULL;
|
||||
ssl_ctx_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,9 +260,9 @@ bool HttpSocket::Connect(int timeout_in_ms) {
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_NUMERICSERV | AI_ADDRCONFIG;
|
||||
|
||||
struct addrinfo* addr_info = NULL;
|
||||
int ret = getaddrinfo(domain_name_.c_str(), port_.c_str(), &hints,
|
||||
&addr_info);
|
||||
struct addrinfo* addr_info = nullptr;
|
||||
int ret =
|
||||
getaddrinfo(domain_name_.c_str(), port_.c_str(), &hints, &addr_info);
|
||||
if (ret != 0) {
|
||||
LOGE("getaddrinfo failed, errno = %d", ret);
|
||||
return false;
|
||||
@@ -308,7 +307,8 @@ bool HttpSocket::Connect(int timeout_in_ms) {
|
||||
} else {
|
||||
if (GetError() != ERROR_ASYNC_COMPLETE) {
|
||||
// failed right away.
|
||||
LOGE("cannot connect to %s, errno = %d", domain_name_.c_str(), GetError());
|
||||
LOGE("cannot connect to %s, errno = %d", domain_name_.c_str(),
|
||||
GetError());
|
||||
CloseSocket();
|
||||
return false;
|
||||
} else {
|
||||
@@ -413,7 +413,7 @@ int HttpSocket::Read(char* data, int len, int timeout_in_ms) {
|
||||
if (ssl_error == SSL_ERROR_SYSCALL) {
|
||||
LOGE(" errno = %d = %s", GetError(), GetErrorString());
|
||||
}
|
||||
ERR_print_errors_cb(LogBoringSslError, NULL);
|
||||
ERR_print_errors_cb(LogBoringSslError, nullptr);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user