Update canceled to cancelled (#1256)

* rename all `canceled` to `cancelled`

* Adding changelog breaking changes
This commit is contained in:
Victor Vazquez 2021-01-05 16:28:05 -08:00 committed by GitHub
parent e697a7939b
commit e141cf1a6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 107 additions and 96 deletions

View File

@ -17,6 +17,11 @@
- Removed option `AllowBeast` from `CurlTransportSSLOptions` in `CurlTransportOptions`.
- Changed default option `NoRevoke` from `CurlTransportSSLOptions` for the `CurlTransportOptions` to `true`. This disables the revocation list checking by default.
- Changed type of `Token::ExpiresOn` to `DateTime`.
- Renamed exception `OperationCanceledException` to `OperationCancelledException`.
- Renamed methods from `Azure::Core::Context`.
- `IsCanceled` to `IsCancelled`
- `ThrowIfCanceled` to `ThrowIfCancelled`.
### Bug Fixes

View File

@ -27,17 +27,19 @@ namespace Azure { namespace Core {
};
/**
* @brief An exception that gets thrown when some operation is canceled.
* @brief An exception that gets thrown when some operation is cancelled.
*
*/
class OperationCanceledException : public std::runtime_error {
class OperationCancelledException : public std::runtime_error {
public:
/**
* @brief Construct with message string as description.
*
* @param message The description for the exception.
*/
explicit OperationCanceledException(std::string const& message) : std::runtime_error(message) {}
explicit OperationCancelledException(std::string const& message) : std::runtime_error(message)
{
}
};
/**
@ -392,19 +394,19 @@ namespace Azure { namespace Core {
}
/**
* @brief Check if the context is canceled.
* @return `true` if this context is canceled, `false` otherwise.
* @brief Check if the context is cancelled.
* @return `true` if this context is cancelled, `false` otherwise.
*/
bool IsCanceled() const { return CancelWhen() < std::chrono::system_clock::now(); }
bool IsCancelled() const { return CancelWhen() < std::chrono::system_clock::now(); }
/**
* @brief Throw an exception if the context was canceled.
* @brief Throw an exception if the context was cancelled.
*/
void ThrowIfCanceled() const
void ThrowIfCancelled() const
{
if (IsCanceled())
if (IsCancelled())
{
throw OperationCanceledException("Request was canceled by context.");
throw OperationCancelledException("Request was cancelled by context.");
}
}
};

View File

@ -44,7 +44,7 @@ namespace Azure { namespace Core {
/**
* @brief Get an authentication token.
*
* @param context #Context so that operation can be canceled.
* @param context #Context so that operation can be cancelled.
* @param scopes Authentication scopes.
*/
virtual AccessToken GetToken(Context const& context, std::vector<std::string> const& scopes)

View File

@ -59,9 +59,9 @@ namespace Azure { namespace Core { namespace Http {
/**
* @brief Read portion of data into a buffer.
* @remark Throws if error/canceled.
* @remark Throws if error/cancelled.
*
* @param conntext #Context so that operation can be canceled.
* @param conntext #Context so that operation can be cancelled.
* @param buffer Pointer to a first byte of the byte buffer to read the data into.
* @param count Size of the buffer to read the data into.
*
@ -73,7 +73,7 @@ namespace Azure { namespace Core { namespace Http {
* @brief Read #BodyStream into a buffer until the buffer is filled, or until the stream is
* read to end.
*
* @param conntext #Context so that operation can be canceled.
* @param conntext #Context so that operation can be cancelled.
* @param body #BodyStream to read.
* @param buffer Pointer to a first byte of the byte buffer to read the data into.
* @param count Size of the buffer to read the data into.
@ -90,7 +90,7 @@ namespace Azure { namespace Core { namespace Http {
* @brief Read #BodyStream until the stream is read to end, allocating memory for the entirety
* of contents.
*
* @param conntext #Context so that operation can be canceled.
* @param conntext #Context so that operation can be cancelled.
* @param body #BodyStream to read.
*
* @return A vector of bytes containing the entirety of data read from the \p body.

View File

@ -114,7 +114,7 @@ namespace Azure { namespace Core { namespace Http {
/**
* @brief Implements interface to send an HTTP Request and produce an HTTP RawResponse
*
* @param context #Context so that operation can be canceled.
* @param context #Context so that operation can be cancelled.
* @param request an HTTP Request to be send.
* @return unique ptr to an HTTP RawResponse.
*/

View File

@ -90,7 +90,7 @@ namespace Azure { namespace Core { namespace Http {
/**
* @brief Start the HTTP pipeline.
*
* @param ctx #Context so that operation can be canceled.
* @param ctx #Context so that operation can be cancelled.
* @param request The HTTP request to be processed.
*
* @return HTTP response after the request has been processed.

View File

@ -44,7 +44,7 @@ namespace Azure { namespace Core { namespace Http {
/**
* @brief Apply this HTTP policy.
*
* @param context #Context so that operation can be canceled.
* @param context #Context so that operation can be cancelled.
* @param request An HTTP #Request being sent.
* @param policy #NextHttpPolicy to invoke after this policy has been applied.
*
@ -96,7 +96,7 @@ namespace Azure { namespace Core { namespace Http {
/**
* @brief Apply this HTTP policy.
*
* @param context #Context so that operation can be canceled.
* @param context #Context so that operation can be cancelled.
* @param request An HTTP #Request being sent.
*
* @return An HTTP #RawResponse after this policy, and all subsequent HTTP policies in the stack

View File

@ -25,7 +25,7 @@ namespace Azure { namespace Core { namespace Http {
/**
* @brief Send an HTTP request over the wire.
*
* @param context #Context so that operation can be canceled.
* @param context #Context so that operation can be cancelled.
* @param request An HTTP #Request to send.
*/
// TODO - Should this be const

View File

@ -101,7 +101,7 @@ namespace Azure { namespace Core { namespace Http {
/**
* @brief Implement #BodyStream read. Calling this function pulls data from the wire.
*
* @param context #Context so that operation can be canceled.
* @param context #Context so that operation can be cancelled.
* @param buffer Buffer where data from wire is written to.
* @param count The number of bytes to read from the network.
* @return The actual number of bytes read from the network.
@ -158,7 +158,7 @@ namespace Azure { namespace Core { namespace Http {
* @brief Implements the Http transport interface to send an HTTP Request and produce an HTTP
* RawResponse.
*
* @param context #Context so that operation can be canceled.
* @param context #Context so that operation can be cancelled.
* @param request an HTTP request to be send.
* @return A unique pointer to an HTTP RawResponse.
*/

View File

@ -72,7 +72,7 @@ std::vector<uint8_t> BodyStream::ReadToEnd(Context const& context, BodyStream& b
int64_t MemoryBodyStream::Read(Context const& context, uint8_t* buffer, int64_t count)
{
context.ThrowIfCanceled();
context.ThrowIfCancelled();
int64_t copy_length = std::min(count, static_cast<int64_t>(this->m_length - this->m_offset));
// Copy what's left or just the count
@ -86,7 +86,7 @@ int64_t MemoryBodyStream::Read(Context const& context, uint8_t* buffer, int64_t
#if defined(AZ_PLATFORM_POSIX)
int64_t FileBodyStream::Read(Azure::Core::Context const& context, uint8_t* buffer, int64_t count)
{
context.ThrowIfCanceled();
context.ThrowIfCancelled();
auto result = pread(
this->m_fd,
@ -105,7 +105,7 @@ int64_t FileBodyStream::Read(Azure::Core::Context const& context, uint8_t* buffe
#elif defined(AZ_PLATFORM_WINDOWS)
int64_t FileBodyStream::Read(Azure::Core::Context const& context, uint8_t* buffer, int64_t count)
{
context.ThrowIfCanceled();
context.ThrowIfCancelled();
DWORD numberOfBytesRead;
auto o = OVERLAPPED();

View File

@ -109,7 +109,7 @@ int pollSocketUntilEventOrTimeout(
for (long counter = 0; counter < timeout && result == 0; counter = counter + interval)
{
// check cancelation
context.ThrowIfCanceled();
context.ThrowIfCancelled();
#if defined(AZ_PLATFORM_POSIX)
result = poll(&poller, 1, interval);
#elif defined(AZ_PLATFORM_WINDOWS)
@ -340,7 +340,7 @@ CURLcode CurlConnection::SendBuffer(
// expected to return CURLE_AGAIN (since socket is ready), so, a chuck of data will be uploaded
// and result will be CURLE_OK which breaks the loop. Also, getting other than CURLE_OK or
// CURLE_AGAIN throws.
context.ThrowIfCanceled();
context.ThrowIfCancelled();
for (CURLcode sendResult = CURLE_AGAIN; sendResult == CURLE_AGAIN;)
{
size_t sentBytesPerRequest = 0;
@ -606,7 +606,7 @@ void CurlSession::ReadStatusLineAndHeadersFromRawResponse(
// Read from curl session
int64_t CurlSession::Read(Context const& context, uint8_t* buffer, int64_t count)
{
context.ThrowIfCanceled();
context.ThrowIfCancelled();
if (count <= 0 || this->IsEOF())
{

View File

@ -106,65 +106,69 @@ namespace Azure { namespace Core { namespace Http {
// C26812: The enum type 'CURLcode' is unscoped. Prefer 'enum class' over 'enum' (Enum.3)
#pragma warning(disable : 26812)
#endif
auto result = curl_easy_getinfo(m_handle, CURLINFO_ACTIVESOCKET, &m_curlSocket);
auto result = curl_easy_getinfo(m_handle, CURLINFO_ACTIVESOCKET, &m_curlSocket);
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
if (result != CURLE_OK)
{
throw Http::TransportException(
"Broken connection. Couldn't get the active sockect for it."
+ std::string(curl_easy_strerror(result)));
if (result != CURLE_OK)
{
throw Http::TransportException(
"Broken connection. Couldn't get the active sockect for it."
+ std::string(curl_easy_strerror(result)));
}
}
}
/**
* @brief Destructor.
* @detail Cleans up CURL (invokes `curl_easy_cleanup()`).
*/
~CurlConnection() override { curl_easy_cleanup(this->m_handle); }
/**
* @brief Destructor.
* @detail Cleans up CURL (invokes `curl_easy_cleanup()`).
*/
~CurlConnection() override { curl_easy_cleanup(this->m_handle); }
std::string const& GetConnectionKey() const override { return this->m_connectionKey; }
std::string const& GetConnectionKey() const override { return this->m_connectionKey; }
/**
* @brief Update last usage time for the connection.
*/
void updateLastUsageTime() override { this->m_lastUseTime = std::chrono::steady_clock::now(); }
/**
* @brief Update last usage time for the connection.
*/
void updateLastUsageTime() override
{
this->m_lastUseTime = std::chrono::steady_clock::now();
}
/**
* @brief Checks whether this CURL connection is expired.
* @return `true` if this connection is considered expired, `false` otherwise.
*/
bool isExpired() override
{
auto connectionOnWaitingTimeMs = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - this->m_lastUseTime);
return connectionOnWaitingTimeMs.count() >= Details::c_DefaultConnectionExpiredMilliseconds;
}
/**
* @brief Checks whether this CURL connection is expired.
* @return `true` if this connection is considered expired, `false` otherwise.
*/
bool isExpired() override
{
auto connectionOnWaitingTimeMs = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - this->m_lastUseTime);
return connectionOnWaitingTimeMs.count() >= Details::c_DefaultConnectionExpiredMilliseconds;
}
/**
* @brief This function is used when working with streams to pull more data from the wire.
* Function will try to keep pulling data from socket until the buffer is all written or until
* there is no more data to get from the socket.
*
* @param context #Context so that operation can be canceled.
* @param buffer ptr to buffer where to copy bytes from socket.
* @param bufferSize size of the buffer and the requested bytes to be pulled from wire.
* @return return the numbers of bytes pulled from socket. It can be less than what it was
* requested.
*/
int64_t ReadFromSocket(Context const& context, uint8_t* buffer, int64_t bufferSize) override;
/**
* @brief This function is used when working with streams to pull more data from the wire.
* Function will try to keep pulling data from socket until the buffer is all written or until
* there is no more data to get from the socket.
*
* @param context #Context so that operation can be cancelled.
* @param buffer ptr to buffer where to copy bytes from socket.
* @param bufferSize size of the buffer and the requested bytes to be pulled from wire.
* @return return the numbers of bytes pulled from socket. It can be less than what it was
* requested.
*/
int64_t ReadFromSocket(Context const& context, uint8_t* buffer, int64_t bufferSize) override;
/**
* @brief This method will use libcurl socket to write all the bytes from buffer.
*
* @remarks Hardcoded timeout is used in case a socket stop responding.
*
* @param context #Context so that operation can be canceled.
* @param buffer ptr to the data to be sent to wire.
* @param bufferSize size of the buffer to send.
* @return CURL_OK when response is sent successfully.
*/
CURLcode SendBuffer(Context const& context, uint8_t const* buffer, size_t bufferSize) override;
};
/**
* @brief This method will use libcurl socket to write all the bytes from buffer.
*
* @remarks Hardcoded timeout is used in case a socket stop responding.
*
* @param context #Context so that operation can be cancelled.
* @param buffer ptr to the data to be sent to wire.
* @param bufferSize size of the buffer to send.
* @return CURL_OK when response is sent successfully.
*/
CURLcode SendBuffer(Context const& context, uint8_t const* buffer, size_t bufferSize)
override;
};
}}} // namespace Azure::Core::Http

View File

@ -271,7 +271,7 @@ namespace Azure { namespace Core { namespace Http {
* @brief Function used when working with Streams to manually write from the HTTP Request to
* the wire.
*
* @param context #Context so that operation can be canceled.
* @param context #Context so that operation can be cancelled.
*
* @return CURL_OK when response is sent successfully.
*/
@ -280,7 +280,7 @@ namespace Azure { namespace Core { namespace Http {
/**
* @brief Upload body.
*
* @param context #Context so that operation can be canceled.
* @param context #Context so that operation can be cancelled.
*
* @return Curl code.
*/
@ -290,7 +290,7 @@ namespace Azure { namespace Core { namespace Http {
* @brief This function is used after sending an HTTP request to the server to read the HTTP
* RawResponse from wire until the end of headers only.
*
* @param context #Context so that operation can be canceled.
* @param context #Context so that operation can be cancelled.
* @param reuseInternalBuffer Indicates whether the internal buffer should be reused.
*
* @return CURL_OK when an HTTP response is created.
@ -303,7 +303,7 @@ namespace Azure { namespace Core { namespace Http {
* @brief Reads from inner buffer or from Wire until chunkSize is parsed and converted to
* unsigned long long
*
* @param context #Context so that operation can be canceled.
* @param context #Context so that operation can be cancelled.
*/
void ParseChunkSize(Context const& context);
@ -371,7 +371,7 @@ namespace Azure { namespace Core { namespace Http {
* @brief Function will use the HTTP request received in constructor to perform a network call
* based on the HTTP request configuration.
*
* @param context #Context so that operation can be canceled.
* @param context #Context so that operation can be cancelled.
* @return CURLE_OK when the network call is completed successfully.
*/
CURLcode Perform(Context const& context);
@ -394,7 +394,7 @@ namespace Azure { namespace Core { namespace Http {
/**
* @brief Implement #BodyStream read. Calling this function pulls data from the wire.
*
* @param context #Context so that operation can be canceled.
* @param context #Context so that operation can be cancelled.
* @param buffer Buffer where data from wire is written to.
* @param count The number of bytes to read from the network.
* @return The actual number of bytes read from the network.

View File

@ -183,6 +183,6 @@ std::unique_ptr<RawResponse> Azure::Core::Http::RetryPolicy::Send(
// Restore the original query parameters before next retry
request.GetUrl().SetQueryParameters(std::move(originalQueryParameters));
ctx.ThrowIfCanceled();
ctx.ThrowIfCancelled();
}
}

View File

@ -559,7 +559,7 @@ std::unique_ptr<RawResponse> WinHttpTransport::Send(Context const& context, Requ
// Read the response from the sent request.
int64_t Details::WinHttpStream::Read(Context const& context, uint8_t* buffer, int64_t count)
{
context.ThrowIfCanceled();
context.ThrowIfCancelled();
if (count <= 0 || this->m_isEOF)
{
@ -587,7 +587,7 @@ int64_t Details::WinHttpStream::Read(Context const& context, uint8_t* buffer, in
+ std::to_string(error) + ".");
}
context.ThrowIfCanceled();
context.ThrowIfCancelled();
DWORD numberOfBytesToRead = numberOfBytesAvailable;
if (numberOfBytesAvailable > count)

View File

@ -81,16 +81,16 @@ TEST(Context, BasicChar)
EXPECT_TRUE(kind == ContextValue::ContextValueType::StdString);
}
TEST(Context, IsCanceled)
TEST(Context, IsCancelled)
{
auto duration = std::chrono::milliseconds(150);
auto deadline = std::chrono::system_clock::now() + duration;
Context context;
auto c2 = context.WithDeadline(deadline);
EXPECT_FALSE(c2.IsCanceled());
EXPECT_FALSE(c2.IsCancelled());
std::this_thread::sleep_for(duration);
EXPECT_TRUE(c2.IsCanceled());
EXPECT_TRUE(c2.IsCancelled());
}
TEST(Context, Alternative)

View File

@ -367,8 +367,8 @@ namespace Azure { namespace Core { namespace Test {
auto stream = Azure::Core::Http::MemoryBodyStream(bigBuffer);
auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Put, host, &stream);
// Request will be canceled from main thread throwing the exception
EXPECT_THROW(m_pipeline->Send(cancelThis, request), Azure::Core::OperationCanceledException);
// Request will be cancelled from main thread throwing the exception
EXPECT_THROW(m_pipeline->Send(cancelThis, request), Azure::Core::OperationCancelledException);
};
// Start request
@ -390,8 +390,8 @@ namespace Azure { namespace Core { namespace Test {
auto threadRoutine = [&]() {
auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, host);
// Request will be canceled from main thread throwing the exception
EXPECT_THROW(m_pipeline->Send(cancelThis, request), Azure::Core::OperationCanceledException);
// Request will be cancelled from main thread throwing the exception
EXPECT_THROW(m_pipeline->Send(cancelThis, request), Azure::Core::OperationCancelledException);
};
// Start request

View File

@ -95,7 +95,7 @@ namespace Azure { namespace Storage { namespace Details {
switchHost();
ctx.ThrowIfCanceled();
ctx.ThrowIfCancelled();
const int64_t baseRetryDelayMs = m_options.RetryDelay.count();
const int64_t maxRetryDelayMs = m_options.MaxRetryDelay.count();