Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed private AWSSRWebSocket classes in order to avoid duplicated symbols when the client project relies on the real SocketRocket #21

Merged
merged 1 commit into from
May 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions AWSAppSyncClient/MQTTSDK/SocketRocket/AWSSRWebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ - (NSString *)stringBySHA1ThenBase64Encoding;
@end

NSString *const AWSSRWebSocketErrorDomain = @"AWSSRWebSocketErrorDomain";
NSString *const SRHTTPResponseErrorKey = @"HTTPResponseStatusCode";
NSString *const AWSSRHTTPResponseErrorKey = @"HTTPResponseStatusCode";

// Returns number of bytes consumed. Returning 0 means you didn't match.
// Sends bytes to callback handler;
typedef size_t (^stream_scanner)(NSData *collected_data);

typedef void (^data_callback)(AWSSRWebSocket *webSocket, NSData *data);

@interface SRIOConsumer : NSObject {
@interface AWSSRIOConsumer : NSObject {
stream_scanner _scanner;
data_callback _handler;
size_t _bytesNeeded;
Expand All @@ -173,12 +173,12 @@ @interface SRIOConsumer : NSObject {
@end

// This class is not thread-safe, and is expected to always be run on the same queue.
@interface SRIOConsumerPool : NSObject
@interface AWSSRIOConsumerPool : NSObject

- (id)initWithBufferCapacity:(NSUInteger)poolSize;

- (SRIOConsumer *)consumerWithScanner:(stream_scanner)scanner handler:(data_callback)handler bytesNeeded:(size_t)bytesNeeded readToCurrentFrame:(BOOL)readToCurrentFrame unmaskBytes:(BOOL)unmaskBytes;
- (void)returnConsumer:(SRIOConsumer *)consumer;
- (AWSSRIOConsumer *)consumerWithScanner:(stream_scanner)scanner handler:(data_callback)handler bytesNeeded:(size_t)bytesNeeded readToCurrentFrame:(BOOL)readToCurrentFrame unmaskBytes:(BOOL)unmaskBytes;
- (void)returnConsumer:(AWSSRIOConsumer *)consumer;

@end

Expand Down Expand Up @@ -252,7 +252,7 @@ @implementation AWSSRWebSocket {
__strong AWSSRWebSocket *_selfRetain;

NSArray *_requestedProtocols;
SRIOConsumerPool *_consumerPool;
AWSSRIOConsumerPool *_consumerPool;
}

@synthesize delegate = _delegate;
Expand Down Expand Up @@ -339,7 +339,7 @@ - (void)_SR_commonInit;

_consumers = [[NSMutableArray alloc] init];

_consumerPool = [[SRIOConsumerPool alloc] init];
_consumerPool = [[AWSSRIOConsumerPool alloc] init];

_scheduledRunloops = [[NSMutableSet alloc] init];

Expand Down Expand Up @@ -445,7 +445,7 @@ - (void)_HTTPHeadersDidFinish;

if (responseCode >= 400) {
SRFastLog(@"Request failed with response code %d", responseCode);
[self _failWithError:[NSError errorWithDomain:AWSSRWebSocketErrorDomain code:2132 userInfo:@{NSLocalizedDescriptionKey:[NSString stringWithFormat:@"received bad response code from server %ld", (long)responseCode], SRHTTPResponseErrorKey:@(responseCode)}]];
[self _failWithError:[NSError errorWithDomain:AWSSRWebSocketErrorDomain code:2132 userInfo:@{NSLocalizedDescriptionKey:[NSString stringWithFormat:@"received bad response code from server %ld", (long)responseCode], AWSSRHTTPResponseErrorKey:@(responseCode)}]];
return;
}

Expand Down Expand Up @@ -1282,7 +1282,7 @@ - (BOOL)_innerPumpScanner {
return didWork;
}

SRIOConsumer *consumer = [_consumers objectAtIndex:0];
AWSSRIOConsumer *consumer = [_consumers objectAtIndex:0];

size_t bytesNeeded = consumer.bytesNeeded;

Expand Down Expand Up @@ -1611,7 +1611,7 @@ - (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode;
@end


@implementation SRIOConsumer
@implementation AWSSRIOConsumer

@synthesize bytesNeeded = _bytesNeeded;
@synthesize consumer = _scanner;
Expand All @@ -1633,7 +1633,7 @@ - (void)setupWithScanner:(stream_scanner)scanner handler:(data_callback)handler
@end


@implementation SRIOConsumerPool {
@implementation AWSSRIOConsumerPool {
NSUInteger _poolSize;
NSMutableArray *_bufferedConsumers;
}
Expand All @@ -1652,22 +1652,22 @@ - (id)init
return [self initWithBufferCapacity:8];
}

- (SRIOConsumer *)consumerWithScanner:(stream_scanner)scanner handler:(data_callback)handler bytesNeeded:(size_t)bytesNeeded readToCurrentFrame:(BOOL)readToCurrentFrame unmaskBytes:(BOOL)unmaskBytes;
- (AWSSRIOConsumer *)consumerWithScanner:(stream_scanner)scanner handler:(data_callback)handler bytesNeeded:(size_t)bytesNeeded readToCurrentFrame:(BOOL)readToCurrentFrame unmaskBytes:(BOOL)unmaskBytes;
{
SRIOConsumer *consumer = nil;
AWSSRIOConsumer *consumer = nil;
if (_bufferedConsumers.count) {
consumer = [_bufferedConsumers lastObject];
[_bufferedConsumers removeLastObject];
} else {
consumer = [[SRIOConsumer alloc] init];
consumer = [[AWSSRIOConsumer alloc] init];
}

[consumer setupWithScanner:scanner handler:handler bytesNeeded:bytesNeeded readToCurrentFrame:readToCurrentFrame unmaskBytes:unmaskBytes];

return consumer;
}

- (void)returnConsumer:(SRIOConsumer *)consumer;
- (void)returnConsumer:(AWSSRIOConsumer *)consumer;
{
if (_bufferedConsumers.count < _poolSize) {
[_bufferedConsumers addObject:consumer];
Expand Down