ANSAWSS3: recover from dead sockets, and report why an upload failed

Field logs showed clusters of uploads taking exactly 20004/20007/20003 ms —
the default _idleTimeoutMs — across several workers at the same instant, then
recurring. Cause: a connection whose request failed was returned to the pool,
so a socket silently dropped by a middlebox was handed to worker after worker,
each paying the full idle timeout to rediscover it. Chilkat's autoReconnect
only covers a cleanly closed connection, not a half-open one.

Connection handling:
- DiscardConnection(): a TRANSPORT failure closes the connection instead of
  pooling it (23 sites). An HTTP error status is not a transport failure - the
  server answered - so those connections are still reused.
- Pooled connections idle longer than 15 s are dropped at acquire time.
- First request on a reused connection uses a short idle timeout (a quarter of
  the configured one, 5 s by default); a fresh connection keeps the full one.
  A dead socket now costs ~5 s once, not 20 s repeatedly.
- One upload call is capped at 30 s wall-clock. The attempt count alone was not
  a time bound: 20 attempts x 20 s could block the caller for ~400 s.
- RetryLoop no longer gives up after one failed connect. Callers call Connect()
  once at startup, so returning left the handle dead for the process lifetime.
  Now backs off 3 s -> 30 s until connected or stopped.
- Connections carry the config generation they were built against, so a connect
  completing just after SetAuthentication cleared the pool cannot leave an
  unauthenticated connection behind (those uploads would 403).
- Stale per-request state is cleared on acquire: multipart uploadId/partNumber
  query params, and the gzip Content-Encoding set by UploadTextData. Not
  ClearAllHeaders - that wipes SigV4 state (fcc985e).

Return codes - upload exports now say whether a retry is worthwhile:
-20 permanent (bad argument, licence, or HTTP 4xx), -21 not connected yet,
-22 transient. Recorded per thread, since one handle is shared by many workers.
Success stays the only positive value, so rc == 1 and rc != 1 are unchanged.
Handle and exception codes (-1/-3/-4) made consistent across all upload
wrappers; some previously returned 0 for these.

Also fixes a misclassification this surfaced: Chilkat reports failure for an
HTTP 4xx delivered during an Expect: 100-continue exchange, so NoSuchBucket was
treated as a network error and retried 20 times before reporting "transient".
The failure path now checks the response status. Chilkat's ~2 KB error dump per
failure is compressed to one line carrying the actual S3 error code.

Verified against live S3: 14,701 uploads across 15 threads with a 150 s idle
gap, 0 failures, no call over 5 s (avg 90 ms, p95 136 ms), matching the
pre-change baseline; and all six return-code classes confirmed end to end.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-12 21:24:12 +10:00
co-authored by Claude Opus 5
parent 6f1d069d14
commit 86b520d85c
4 changed files with 606 additions and 206 deletions
+99 -84
View File
@@ -209,6 +209,20 @@ public:
AWSHandleGuard& operator=(const AWSHandleGuard&) = delete;
};
// Failure code for an upload whose C++ call returned false. ANSAWSS3 records
// WHY on the calling thread, which is what lets the caller decide whether a
// retry is worthwhile:
// -20 permanent — bad argument / licence / bucket / HTTP 4xx: do not retry
// -21 not connected — link not up yet, background retry running: retry later
// -22 transient — network/timeout/5xx after internal retries: retry
// Falls back to the historical -2 if no status was recorded. Never returns a
// success code, so `rc == 1` remains an exact success test.
static int AwsUploadFailureCode() {
const int status = ANSCENTER::ANSAWSS3::LastCallStatus();
if (status == ANSCENTER::ANSAWSS3::kCallSuccess) return -2;
return status;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
@@ -1910,7 +1924,7 @@ extern "C" ANSULT_API int UploadTextDataANSAWSHandle(ANSCENTER::ANSAWSS3** Hand
return 0;
}
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadTextData(bucketName, textDataPath, outPath)) {
@@ -1922,13 +1936,13 @@ extern "C" ANSULT_API int UploadTextDataANSAWSHandle(ANSCENTER::ANSAWSS3** Hand
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) {
return 0;
return -3;
}
catch (...) {
return 0;
return -4;
}
}
extern "C" ANSULT_API int UploadBinaryDataANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* binaryDataPath, LStrHandle uploadedFilePath) {
@@ -1936,7 +1950,7 @@ extern "C" ANSULT_API int UploadBinaryDataANSAWSHandle(ANSCENTER::ANSAWSS3** Ha
return 0;
}
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadBinaryData(bucketName, binaryDataPath, outPath)) {
@@ -1948,13 +1962,13 @@ extern "C" ANSULT_API int UploadBinaryDataANSAWSHandle(ANSCENTER::ANSAWSS3** Ha
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) {
return 0;
return -3;
}
catch (...) {
return 0;
return -4;
}
}
extern "C" ANSULT_API int UploadFileStreamDataANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* fileDataPath, LStrHandle uploadedFilePath) {
@@ -1962,7 +1976,7 @@ extern "C" ANSULT_API int UploadFileStreamDataANSAWSHandle(ANSCENTER::ANSAWSS3*
return 0;
}
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadFileStream(bucketName, fileDataPath, outPath)) {
@@ -1974,13 +1988,13 @@ extern "C" ANSULT_API int UploadFileStreamDataANSAWSHandle(ANSCENTER::ANSAWSS3*
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) {
return 0;
return -3;
}
catch (...) {
return 0;
return -4;
}
}
extern "C" ANSULT_API int UploadMultiPartDataANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* fileDataPath, int fileSize, LStrHandle uploadedFilePath) {
@@ -1988,7 +2002,7 @@ extern "C" ANSULT_API int UploadMultiPartDataANSAWSHandle(ANSCENTER::ANSAWSS3**
return 0;
}
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadMultipartData(bucketName, fileDataPath, outPath, fileSize)) {
@@ -2000,13 +2014,13 @@ extern "C" ANSULT_API int UploadMultiPartDataANSAWSHandle(ANSCENTER::ANSAWSS3**
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) {
return 0;
return -3;
}
catch (...) {
return 0;
return -4;
}
}
extern "C" ANSULT_API int DownloadFileStreamANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* objectName, const char* savedFilePath) {
@@ -2043,7 +2057,7 @@ extern "C" ANSULT_API int UploadJpegImageANSAWSHandle(ANSCENTER::ANSAWSS3** Han
}
return 1;
}
else return -2;// failed upload
else return AwsUploadFailureCode();
}
catch (std::exception& e) {
return -3;//excception
@@ -2088,9 +2102,10 @@ extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle(ANSCENTER::ANSAWSS3
return 1;
}
else {
ANS_DBG("ANSAWS", "Upload FAILED (-2): file=%s, UploadPrefixJpegImage returned false",
fileName ? fileName : "(null)");
return -2;
const int rc = AwsUploadFailureCode();
ANS_DBG("ANSAWS", "Upload FAILED (%d): file=%s, UploadPrefixJpegImage returned false",
rc, fileName ? fileName : "(null)");
return rc;
}
}
catch (std::exception& e) {
@@ -2159,7 +2174,7 @@ extern "C" ANSULT_API int UploadPrefixMultiPartDataANSAWSHandle(ANSCENTER::ANSA
return 0;
}
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadPrefixMultipartData(bucketName, prefix, fileDataPath, objectName, outPath, fileSize)) {
@@ -2171,13 +2186,13 @@ extern "C" ANSULT_API int UploadPrefixMultiPartDataANSAWSHandle(ANSCENTER::ANSA
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) {
return 0;
return -3;
}
catch (...) {
return 0;
return -4;
}
}
extern "C" ANSULT_API int UploadPrefixBinaryDataANSAWSHandle(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, const char* binaryDataPath, const char* objectName, LStrHandle uploadedFilePath) {
@@ -2185,7 +2200,7 @@ extern "C" ANSULT_API int UploadPrefixBinaryDataANSAWSHandle(ANSCENTER::ANSAWSS
return 0;
}
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadPrefixBinaryData(bucketName, prefix, binaryDataPath, objectName, outPath)) {
@@ -2197,79 +2212,79 @@ extern "C" ANSULT_API int UploadPrefixBinaryDataANSAWSHandle(ANSCENTER::ANSAWSS
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) {
return 0;
return -3;
}
catch (...) {
return 0;
return -4;
}
}
// ── C++ test APIs (std::string& instead of LStrHandle) ──
extern "C" ANSULT_API int UploadTextDataANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* textDataPath, std::string& uploadedFilePath) {
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || textDataPath == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
return guard.get()->UploadTextData(bucketName, textDataPath, uploadedFilePath) ? 1 : 0;
} catch (...) { return 0; }
return guard.get()->UploadTextData(bucketName, textDataPath, uploadedFilePath) ? 1 : AwsUploadFailureCode();
} catch (...) { return -4; }
}
extern "C" ANSULT_API int UploadBinaryDataANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* binaryDataPath, std::string& uploadedFilePath) {
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || binaryDataPath == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
return guard.get()->UploadBinaryData(bucketName, binaryDataPath, uploadedFilePath) ? 1 : 0;
} catch (...) { return 0; }
return guard.get()->UploadBinaryData(bucketName, binaryDataPath, uploadedFilePath) ? 1 : AwsUploadFailureCode();
} catch (...) { return -4; }
}
extern "C" ANSULT_API int UploadFileStreamDataANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* fileDataPath, std::string& uploadedFilePath) {
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || fileDataPath == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
return guard.get()->UploadFileStream(bucketName, fileDataPath, uploadedFilePath) ? 1 : 0;
} catch (...) { return 0; }
return guard.get()->UploadFileStream(bucketName, fileDataPath, uploadedFilePath) ? 1 : AwsUploadFailureCode();
} catch (...) { return -4; }
}
extern "C" ANSULT_API int UploadMultiPartDataANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* fileDataPath, int fileSize, std::string& uploadedFilePath) {
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || fileDataPath == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
return guard.get()->UploadMultipartData(bucketName, fileDataPath, uploadedFilePath, fileSize) ? 1 : 0;
} catch (...) { return 0; }
return guard.get()->UploadMultipartData(bucketName, fileDataPath, uploadedFilePath, fileSize) ? 1 : AwsUploadFailureCode();
} catch (...) { return -4; }
}
extern "C" ANSULT_API int UploadJpegImageANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, unsigned char* jpeg_string, int32 bufferLength, const char* fileName, std::string& uploadedFilePath) {
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || jpeg_string == nullptr || bufferLength <= 0 || fileName == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
return guard.get()->UploadJpegImage(bucketName, jpeg_string, bufferLength, fileName, uploadedFilePath) ? 1 : 0;
} catch (...) { return 0; }
return guard.get()->UploadJpegImage(bucketName, jpeg_string, bufferLength, fileName, uploadedFilePath) ? 1 : AwsUploadFailureCode();
} catch (...) { return -4; }
}
extern "C" ANSULT_API int UploadPrefixBinaryDataANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, const char* binaryDataPath, const char* objectName, std::string& uploadedFilePath) {
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || prefix == nullptr || binaryDataPath == nullptr || objectName == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
return guard.get()->UploadPrefixBinaryData(bucketName, prefix, binaryDataPath, objectName, uploadedFilePath) ? 1 : 0;
} catch (...) { return 0; }
return guard.get()->UploadPrefixBinaryData(bucketName, prefix, binaryDataPath, objectName, uploadedFilePath) ? 1 : AwsUploadFailureCode();
} catch (...) { return -4; }
}
extern "C" ANSULT_API int UploadPrefixMultiPartDataANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, const char* fileDataPath, const char* objectName, int fileSize, std::string& uploadedFilePath) {
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || prefix == nullptr || fileDataPath == nullptr || fileSize <= 0) return 0;
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
return guard.get()->UploadPrefixMultipartData(bucketName, prefix, fileDataPath, objectName, uploadedFilePath, fileSize) ? 1 : 0;
} catch (...) { return 0; }
return guard.get()->UploadPrefixMultipartData(bucketName, prefix, fileDataPath, objectName, uploadedFilePath, fileSize) ? 1 : AwsUploadFailureCode();
} catch (...) { return -4; }
}
extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, unsigned char* jpeg_string, int32 bufferLength, const char* fileName, std::string& uploadedFilePath) {
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || prefix == nullptr || jpeg_string == nullptr || bufferLength <= 0 || fileName == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(*Handle));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
return guard.get()->UploadPrefixJpegImage(bucketName, prefix, jpeg_string, bufferLength, fileName, uploadedFilePath) ? 1 : 0;
} catch (...) { return 0; }
return guard.get()->UploadPrefixJpegImage(bucketName, prefix, jpeg_string, bufferLength, fileName, uploadedFilePath) ? 1 : AwsUploadFailureCode();
} catch (...) { return -4; }
}
extern "C" ANSULT_API int GeneratePresignedURLANSAWSHandle_CPP(ANSCENTER::ANSAWSS3** Handle, const char* bucketName, const char* prefix, const char* objectName, int validDays, std::string& presignedURL) {
if (Handle == nullptr || *Handle == nullptr || bucketName == nullptr || prefix == nullptr || objectName == nullptr) return 0;
@@ -2767,7 +2782,7 @@ extern "C" ANSULT_API int UploadTextDataANSAWSHandle_V2(uint64_t handleVal, cons
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
if (bucketName == nullptr || textDataPath == nullptr || uploadedFilePath == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadTextData(bucketName, textDataPath, outPath)) {
@@ -2779,17 +2794,17 @@ extern "C" ANSULT_API int UploadTextDataANSAWSHandle_V2(uint64_t handleVal, cons
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) { return 0; }
catch (...) { return 0; }
catch (std::exception& e) { return -3; }
catch (...) { return -4; }
}
extern "C" ANSULT_API int UploadBinaryDataANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* binaryDataPath, LStrHandle uploadedFilePath) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
if (bucketName == nullptr || binaryDataPath == nullptr || uploadedFilePath == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadBinaryData(bucketName, binaryDataPath, outPath)) {
@@ -2801,17 +2816,17 @@ extern "C" ANSULT_API int UploadBinaryDataANSAWSHandle_V2(uint64_t handleVal, co
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) { return 0; }
catch (...) { return 0; }
catch (std::exception& e) { return -3; }
catch (...) { return -4; }
}
extern "C" ANSULT_API int UploadFileStreamDataANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* fileDataPath, LStrHandle uploadedFilePath) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
if (bucketName == nullptr || fileDataPath == nullptr || uploadedFilePath == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadFileStream(bucketName, fileDataPath, outPath)) {
@@ -2823,17 +2838,17 @@ extern "C" ANSULT_API int UploadFileStreamDataANSAWSHandle_V2(uint64_t handleVal
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) { return 0; }
catch (...) { return 0; }
catch (std::exception& e) { return -3; }
catch (...) { return -4; }
}
extern "C" ANSULT_API int UploadMultiPartDataANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* fileDataPath, int fileSize, LStrHandle uploadedFilePath) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
if (bucketName == nullptr || fileDataPath == nullptr || uploadedFilePath == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadMultipartData(bucketName, fileDataPath, outPath, fileSize)) {
@@ -2845,17 +2860,17 @@ extern "C" ANSULT_API int UploadMultiPartDataANSAWSHandle_V2(uint64_t handleVal,
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) { return 0; }
catch (...) { return 0; }
catch (std::exception& e) { return -3; }
catch (...) { return -4; }
}
extern "C" ANSULT_API int UploadJpegImageANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, unsigned char* jpeg_string, int32 bufferLength, const char* fileName, LStrHandle uploadedFilePath) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
if (bucketName == nullptr || jpeg_string == nullptr || bufferLength <= 0 || fileName == nullptr || uploadedFilePath == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadJpegImage(bucketName, jpeg_string, bufferLength, fileName, outPath)) {
@@ -2867,17 +2882,17 @@ extern "C" ANSULT_API int UploadJpegImageANSAWSHandle_V2(uint64_t handleVal, con
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) { return 0; }
catch (...) { return 0; }
catch (std::exception& e) { return -3; }
catch (...) { return -4; }
}
extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* prefix, unsigned char* jpeg_string, int32 bufferLength, const char* fileName, LStrHandle uploadedFilePath) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
if (bucketName == nullptr || prefix == nullptr || jpeg_string == nullptr || bufferLength <= 0 || fileName == nullptr || uploadedFilePath == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadPrefixJpegImage(bucketName, prefix, jpeg_string, bufferLength, fileName, outPath)) {
@@ -2889,10 +2904,10 @@ extern "C" ANSULT_API int UploadPrefixJpegImageANSAWSHandle_V2(uint64_t handleVa
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) { return 0; }
catch (...) { return 0; }
catch (std::exception& e) { return -3; }
catch (...) { return -4; }
}
extern "C" ANSULT_API int GeneratePresignedURLANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* prefix, const char* objectName, int validDays, LStrHandle presignedURL) {
@@ -2921,7 +2936,7 @@ extern "C" ANSULT_API int UploadPrefixMultiPartDataANSAWSHandle_V2(uint64_t hand
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
if (bucketName == nullptr || prefix == nullptr || fileDataPath == nullptr || fileSize <= 0 || uploadedFilePath == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadPrefixMultipartData(bucketName, prefix, fileDataPath, objectName, outPath, fileSize)) {
@@ -2933,17 +2948,17 @@ extern "C" ANSULT_API int UploadPrefixMultiPartDataANSAWSHandle_V2(uint64_t hand
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) { return 0; }
catch (...) { return 0; }
catch (std::exception& e) { return -3; }
catch (...) { return -4; }
}
extern "C" ANSULT_API int UploadPrefixBinaryDataANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* prefix, const char* binaryDataPath, const char* objectName, LStrHandle uploadedFilePath) {
auto* _v2h = reinterpret_cast<ANSCENTER::ANSAWSS3*>(handleVal); if (!_v2h) return 0;
if (bucketName == nullptr || prefix == nullptr || binaryDataPath == nullptr || objectName == nullptr || uploadedFilePath == nullptr) return 0;
AWSHandleGuard guard(AcquireAWSHandle(_v2h));
if (!guard) return 0;
if (!guard) return -1; // handle not in registry
try {
std::string outPath;
if (guard.get()->UploadPrefixBinaryData(bucketName, prefix, binaryDataPath, objectName, outPath)) {
@@ -2955,10 +2970,10 @@ extern "C" ANSULT_API int UploadPrefixBinaryDataANSAWSHandle_V2(uint64_t handleV
}
return 1;
}
else return 0;
else return AwsUploadFailureCode();
}
catch (std::exception& e) { return 0; }
catch (...) { return 0; }
catch (std::exception& e) { return -3; }
catch (...) { return -4; }
}
extern "C" ANSULT_API int DownloadFileStreamANSAWSHandle_V2(uint64_t handleVal, const char* bucketName, const char* objectName, const char* savedFilePath) {