Skip to content

Commit

Permalink
update: Continuously read from buffer while no errors occur.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroOrozco committed Dec 22, 2023
1 parent 4e320d8 commit 764e699
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
30 changes: 19 additions & 11 deletions SNASources/CellularSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ - (CellularSessionResult * _Nonnull)performRequest:(NSURL * _Nonnull)url {
const char* request = [requestString UTF8String];

char buffer[4096];

NSMutableData *responseData = [NSMutableData dataWithCapacity:0];

// Step 4). Invoke the HTTP request using the instantiated socket

if ([[url scheme] isEqualToString:@"http"]) {
Expand Down Expand Up @@ -282,14 +283,21 @@ - (CellularSessionResult * _Nonnull)performRequest:(NSURL * _Nonnull)url {
do {
// SSLRead performs a typical application-level read operation.
status = SSLRead(context, buffer, sizeof(buffer) - 1, &processed);
buffer[processed] = 0;

// If the buffer was filled, then continue reading
if (processed == sizeof(buffer) - 1) {
status = errSSLWouldBlock;

if (status == noErr && processed > 0) {
[responseData appendBytes:buffer length:processed]; // Append the received data to responseData
} else if (status == errSSLWouldBlock) {
// No more data available
SSLClose(context);
CFRelease(context);
status = noErr;
break;
} else {
// No data received
break;
}
} while (status == errSSLWouldBlock);
} while (status == noErr);

if (status && status != errSSLClosedGraceful) {
SSLClose(context);
CFRelease(context);
Expand All @@ -301,9 +309,9 @@ - (CellularSessionResult * _Nonnull)performRequest:(NSURL * _Nonnull)url {

}
}
NSString *response = [[NSString alloc] initWithBytes:buffer length:sizeof(buffer) encoding:NSASCIIStringEncoding];

NSString *response = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];

// Step 5). Parse the HTTP response and check whether it contains a redirect HTTP code

if ([response rangeOfString:@"HTTP/"].location == NSNotFound) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,4 @@ extension PhoneNumberViewController {
}

/// Not required for the SDK implementation.
private let sampleAppVersion = "0.0.3"
private let sampleAppVersion = "0.0.4"
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Configuration/Info.plist;
Expand All @@ -417,7 +417,7 @@
"@executable_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 0.0.3;
MARKETING_VERSION = 0.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.twilio.TwilioVerifySNADemo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -433,7 +433,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Configuration/Info.plist;
Expand All @@ -448,7 +448,7 @@
"@executable_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 0.0.3;
MARKETING_VERSION = 0.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.twilio.TwilioVerifySNADemo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down

0 comments on commit 764e699

Please sign in to comment.