[ios2]ASIHTTPReques 清除所有持久连接

http://www.winddisk.com/2012/08/27/iphone_screenlock_network_disconnection/

+ (void)clearPersistentConnections
{
	[connectionsLock lock];
	NSUInteger i;
	for (i=0; i<[persistentConnectionsPool count]; i++) {
		NSDictionary *existingConnection = [persistentConnectionsPool objectAtIndex:i];
		if (![existingConnection objectForKey:@"request"]) {
#if DEBUG_PERSISTENT_CONNECTIONS
			ASI_DEBUG_LOG(@"[CONNECTION] Closing connection #%i manualy",[[existingConnection objectForKey:@"id"] intValue]);
#endif
			NSInputStream *stream = [existingConnection objectForKey:@"stream"];
			if (stream) {
				[stream close];
			}
			[persistentConnectionsPool removeObject:existingConnection];
			i--;
		}
	}
	[connectionsLock unlock];
}
posted @ 2013-08-20 15:08  金建彤  阅读(181)  评论(0编辑  收藏  举报