Skip to content

Commit

Permalink
fix: Continuously read from buffer while no errors occur. (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroOrozco committed Jan 2, 2024
1 parent 4e320d8 commit 876798c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
# 0.0.3 (26–12-2023)

### Fixes

- Continuously read from buffer while no errors occur. The buffer was closing itself after being put on hold, rather than waiting to read the entire package from the SSLRead.

# 0.0.2 (09–26-2022)

### Improvements
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -85,7 +85,7 @@ During the current phase of this project, we only support SPM. We have plans to
dependencies: [
.package(
url: "https://github.com/twilio/twilio-verify-sna-ios.git",
.upToNextMajor(from: "0.0.2")
.upToNextMajor(from: "0.0.3")
)
]
```
Expand Down
30 changes: 19 additions & 11 deletions SNASources/CellularSession.m
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
2 changes: 1 addition & 1 deletion Sources/TwilioVerifySNAConfig.swift
Expand Up @@ -20,5 +20,5 @@
import Foundation

public struct TwilioVerifySNAConfig {
public static let version = "0.0.2"
public static let version = "0.0.3"
}
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 Down Expand Up @@ -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 Down

0 comments on commit 876798c

Please sign in to comment.