AppRTCDemo was blocking the main thread for network requests. This fixes it by making the background queue serial instead of using @synchronize to make the background operations serial.
R=fischman@webrtc.org Review URL: https://webrtc-codereview.appspot.com/16379004 Patch from Bridger Maxwell <bridgeyman@gmail.com>. git-svn-id: http://webrtc.googlecode.com/svn/trunk@6028 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
9bd49becc1
commit
7c82adae61
1
AUTHORS
1
AUTHORS
@ -3,6 +3,7 @@
|
||||
|
||||
Anil Kumar <an1kumar@gmail.com>
|
||||
Ben Strong <bstrong@gmail.com>
|
||||
Bridger Maxwell <bridgeyman@gmail.com>
|
||||
Christophe Dumez <ch.dumez@samsung.com>
|
||||
Eric Rescorla, RTFM Inc.
|
||||
Jie Mao <maojie0924@gmail.com>
|
||||
|
@ -56,7 +56,8 @@
|
||||
if (self = [super init]) {
|
||||
_ICEServerDelegate = delegate;
|
||||
_messageHandler = handler;
|
||||
_backgroundQueue = dispatch_queue_create("RTCBackgroundQueue", NULL);
|
||||
_backgroundQueue = dispatch_queue_create("RTCBackgroundQueue",
|
||||
DISPATCH_QUEUE_SERIAL);
|
||||
_sendQueue = [NSMutableArray array];
|
||||
// Uncomment to see Request/Response logging.
|
||||
// _verboseLogging = YES;
|
||||
@ -72,11 +73,22 @@
|
||||
}
|
||||
|
||||
- (void)sendData:(NSData*)data {
|
||||
@synchronized(self) {
|
||||
[self maybeLogMessage:@"Send message"];
|
||||
[self maybeLogMessage:@"Send message"];
|
||||
|
||||
dispatch_async(self.backgroundQueue, ^{
|
||||
[self.sendQueue addObject:[data copy]];
|
||||
}
|
||||
[self requestQueueDrainInBackground];
|
||||
|
||||
if ([self.postMessageUrl length] < 1) {
|
||||
return;
|
||||
}
|
||||
for (NSData* data in self.sendQueue) {
|
||||
NSString* url =
|
||||
[NSString stringWithFormat:@"%@/%@",
|
||||
self.baseURL, self.postMessageUrl];
|
||||
[self sendData:data withUrl:url];
|
||||
}
|
||||
[self.sendQueue removeAllObjects];
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - Internal methods
|
||||
@ -133,24 +145,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)requestQueueDrainInBackground {
|
||||
dispatch_async(self.backgroundQueue, ^(void) {
|
||||
// TODO(hughv): This can block the UI thread. Fix.
|
||||
@synchronized(self) {
|
||||
if ([self.postMessageUrl length] < 1) {
|
||||
return;
|
||||
}
|
||||
for (NSData* data in self.sendQueue) {
|
||||
NSString* url =
|
||||
[NSString stringWithFormat:@"%@/%@",
|
||||
self.baseURL, self.postMessageUrl];
|
||||
[self sendData:data withUrl:url];
|
||||
}
|
||||
[self.sendQueue removeAllObjects];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)sendData:(NSData*)data withUrl:(NSString*)url {
|
||||
NSMutableURLRequest* request =
|
||||
[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
|
||||
|
Loading…
x
Reference in New Issue
Block a user