Follow up from #686 to address PR comments about typos
This commit is contained in:
parent
a4588240e9
commit
190a0e80b1
@ -526,7 +526,7 @@ namespace Azure { namespace Core { namespace Http {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief function to log
|
||||
* @brief The function to log.
|
||||
*
|
||||
*/
|
||||
std::function<void(std::string const& message)> m_logger;
|
||||
|
||||
@ -54,7 +54,6 @@ int pollSocketUntilEventOrTimeout(
|
||||
#ifndef POSIX
|
||||
#ifndef WINDOWS
|
||||
// platform does not support Poll().
|
||||
// TODO. Legacy select() for other platforms?
|
||||
throw Azure::Core::Http::TransportException(
|
||||
"Error while sending request. Platform does not support Poll()");
|
||||
#endif
|
||||
@ -86,10 +85,12 @@ int pollSocketUntilEventOrTimeout(
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
// Windows needs this after every write to socket or peformance would be reduced to 1/4 for
|
||||
// Windows needs this after every write to socket or performance would be reduced to 1/4 for
|
||||
// uploading operation.
|
||||
// https://github.com/Azure/azure-sdk-for-cpp/issues/644
|
||||
void WinSocketSetBuffSize(curl_socket_t socket, std::function<void(std::string const& message)> logger)
|
||||
void WinSocketSetBuffSize(
|
||||
curl_socket_t socket,
|
||||
std::function<void(std::string const& message)> logger)
|
||||
{
|
||||
ULONG ideal;
|
||||
DWORD ideallen;
|
||||
@ -97,11 +98,13 @@ void WinSocketSetBuffSize(curl_socket_t socket, std::function<void(std::string c
|
||||
if (WSAIoctl(socket, SIO_IDEAL_SEND_BACKLOG_QUERY, 0, 0, &ideal, sizeof(ideal), &ideallen, 0, 0)
|
||||
== 0)
|
||||
{
|
||||
// if WSAloctl succeded (returned 0), set the socket buffer size.
|
||||
// if WSAloctl succeeded (returned 0), set the socket buffer size.
|
||||
// Specifies the total per-socket buffer space reserved for sends.
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt
|
||||
auto result = setsockopt(socket, SOL_SOCKET, SO_SNDBUF, (const char*)&ideal, sizeof(ideal));
|
||||
logger("Windows - calling setsockopt after uploading chunk. ideal = " + std::to_string(ideal) + " result = " + std::to_string(result));
|
||||
logger(
|
||||
"Windows - calling setsockopt after uploading chunk. ideal = " + std::to_string(ideal)
|
||||
+ " result = " + std::to_string(result));
|
||||
}
|
||||
}
|
||||
#endif // WINDOWS
|
||||
@ -128,7 +131,7 @@ std::unique_ptr<RawResponse> CurlTransport::Send(Context const& context, Request
|
||||
auto session = std::make_unique<CurlSession>(request, LogThis);
|
||||
CURLcode performing;
|
||||
|
||||
// Try to send the request. If we get CURLE_UNSUPPORTED_PROTOCOL back it means the connection is
|
||||
// Try to send the request. If we get CURLE_UNSUPPORTED_PROTOCOL back, it means the connection is
|
||||
// either closed or the socket is not usable any more. In that case, let the session be destroyed
|
||||
// and create a new session to get another connection from connection pool.
|
||||
// Prevent from trying forever by using c_DefaultMaxOpenNewConnectionIntentsAllowed.
|
||||
@ -149,18 +152,20 @@ std::unique_ptr<RawResponse> CurlTransport::Send(Context const& context, Request
|
||||
{
|
||||
switch (performing)
|
||||
{
|
||||
case CURLE_COULDNT_RESOLVE_HOST: {
|
||||
case CURLE_COULDNT_RESOLVE_HOST:
|
||||
{
|
||||
throw Azure::Core::Http::CouldNotResolveHostException(
|
||||
"Could not resolve host " + request.GetUrl().GetHost());
|
||||
}
|
||||
default: {
|
||||
default:
|
||||
{
|
||||
throw Azure::Core::Http::TransportException(
|
||||
"Error while sending request. " + std::string(curl_easy_strerror(performing)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LogThis("Request completed. Moving respone out of session and session to response.");
|
||||
LogThis("Request completed. Moving response out of session and session to response.");
|
||||
// Move Response out of the session
|
||||
auto response = session->GetResponse();
|
||||
// Move the ownership of the CurlSession (bodyStream) to the response
|
||||
@ -315,19 +320,21 @@ CURLcode CurlSession::SendBuffer(uint8_t const* buffer, size_t bufferSize)
|
||||
|
||||
switch (sendResult)
|
||||
{
|
||||
case CURLE_OK: {
|
||||
case CURLE_OK:
|
||||
{
|
||||
sentBytesTotal += sentBytesPerRequest;
|
||||
this->m_uploadedBytes += sentBytesPerRequest;
|
||||
break;
|
||||
}
|
||||
case CURLE_AGAIN: {
|
||||
case CURLE_AGAIN:
|
||||
{
|
||||
// start polling operation
|
||||
auto pollUntilSocketIsReady = pollSocketUntilEventOrTimeout(
|
||||
this->m_curlSocket, PollSocketDirection::Write, 60000L);
|
||||
|
||||
if (pollUntilSocketIsReady == 0)
|
||||
{
|
||||
throw Azure::Core::Http::TransportException("Timeout waitting for socket to upload.");
|
||||
throw Azure::Core::Http::TransportException("Timeout waiting for socket to upload.");
|
||||
}
|
||||
else if (pollUntilSocketIsReady < 0)
|
||||
{ // negative value, error while polling
|
||||
@ -338,7 +345,8 @@ CURLcode CurlSession::SendBuffer(uint8_t const* buffer, size_t bufferSize)
|
||||
// Ready to continue download.
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
default:
|
||||
{
|
||||
return sendResult;
|
||||
}
|
||||
}
|
||||
@ -494,7 +502,7 @@ void CurlSession::ReadStatusLineAndHeadersFromRawResponse(bool reUseInternalBUff
|
||||
// For Head request, set the length of body response to 0.
|
||||
// Response will give us content-length as if we were not doing Head saying what would it be the
|
||||
// length of the body. However, Server won't send body
|
||||
// For NoContent status code, also need to set conentLength to 0.
|
||||
// For NoContent status code, also need to set contentLength to 0.
|
||||
// https://github.com/Azure/azure-sdk-for-cpp/issues/406
|
||||
if (this->m_request.GetMethod() == HttpMethod::Head
|
||||
|| this->m_lastStatusCode == Azure::Core::Http::HttpStatusCode::NoContent)
|
||||
@ -504,7 +512,7 @@ void CurlSession::ReadStatusLineAndHeadersFromRawResponse(bool reUseInternalBUff
|
||||
return;
|
||||
}
|
||||
|
||||
// headers are already loweCase at this point
|
||||
// headers are already lowerCase at this point
|
||||
auto headers = this->m_response->GetHeaders();
|
||||
|
||||
auto isContentLengthHeaderInResponse = headers.find("content-length");
|
||||
@ -615,7 +623,7 @@ int64_t CurlSession::Read(Azure::Core::Context const& context, uint8_t* buffer,
|
||||
|
||||
if (this->m_bodyStartInBuffer == this->m_innerBufferSize)
|
||||
{
|
||||
this->m_bodyStartInBuffer = -1; // read everyting from inner buffer already
|
||||
this->m_bodyStartInBuffer = -1; // read everything from inner buffer already
|
||||
}
|
||||
return totalRead;
|
||||
}
|
||||
@ -664,7 +672,8 @@ int64_t CurlSession::ReadFromSocket(uint8_t* buffer, int64_t bufferSize)
|
||||
|
||||
switch (readResult)
|
||||
{
|
||||
case CURLE_AGAIN: {
|
||||
case CURLE_AGAIN:
|
||||
{
|
||||
// start polling operation
|
||||
auto pollUntilSocketIsReady
|
||||
= pollSocketUntilEventOrTimeout(this->m_curlSocket, PollSocketDirection::Read, 60000L);
|
||||
@ -681,10 +690,12 @@ int64_t CurlSession::ReadFromSocket(uint8_t* buffer, int64_t bufferSize)
|
||||
// Ready to continue download.
|
||||
break;
|
||||
}
|
||||
case CURLE_OK: {
|
||||
case CURLE_OK:
|
||||
{
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
default:
|
||||
{
|
||||
// Error reading from socket
|
||||
throw Azure::Core::Http::TransportException(
|
||||
"Error while reading from network socket. CURLE code: " + std::to_string(readResult)
|
||||
@ -848,7 +859,7 @@ int64_t CurlSession::ResponseBufferParser::BuildStatusCode(
|
||||
if (this->m_internalBuffer.size() > 0)
|
||||
{
|
||||
// If the index is same as buffer it means delimiter is at position 0, meaning that
|
||||
// internalBuffer containst the status line and we don't need to add anything else
|
||||
// internalBuffer contains the status line and we don't need to add anything else
|
||||
if (indexOfEndOfStatusLine > buffer)
|
||||
{
|
||||
// Append and build response minus the delimiter
|
||||
@ -896,7 +907,7 @@ int64_t CurlSession::ResponseBufferParser::BuildHeader(
|
||||
// advance
|
||||
{
|
||||
// move offset one possition. This is because readStatusLine and readHeader will read up to
|
||||
// '\r' then next delimeter is '\n' and we don't care
|
||||
// '\r' then next delimiter is '\n' and we don't care
|
||||
start = buffer + 1;
|
||||
}
|
||||
|
||||
@ -923,7 +934,7 @@ int64_t CurlSession::ResponseBufferParser::BuildHeader(
|
||||
if (this->m_internalBuffer.size() > 0)
|
||||
{
|
||||
// If the index is same as buffer it means delimiter is at position 0, meaning that
|
||||
// internalBuffer containst the status line and we don't need to add anything else
|
||||
// internalBuffer contains the status line and we don't need to add anything else
|
||||
if (indexOfEndOfStatusLine > buffer)
|
||||
{
|
||||
// Append and build response minus the delimiter
|
||||
@ -990,7 +1001,7 @@ std::unique_ptr<CurlConnection> CurlConnectionPool::GetCurlConnection(Request& r
|
||||
// No available connection for the pool for the required host. Create one
|
||||
auto newConnection = std::make_unique<CurlConnection>(host);
|
||||
|
||||
// Libcurl setup before open connection (url, connet_only, timeout)
|
||||
// Libcurl setup before open connection (url, connect_only, timeout)
|
||||
SetLibcurlOption(
|
||||
newConnection->GetHandle(),
|
||||
CURLOPT_URL,
|
||||
@ -1033,7 +1044,7 @@ void CurlConnectionPool::MoveConnectionBackToPool(
|
||||
// laststatusCode = 0
|
||||
if (code < 200 || code >= 300)
|
||||
{
|
||||
// A hanlder with previos response with Error can't be re-use.
|
||||
// A handler with previous response with Error can't be re-use.
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// this option is used to allow the application to use std::getenv without getting a compilation
|
||||
// warning about it on MSVC.
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user