저는 pastebin에서 긴 폴링 기법을 사용한 예를 보았고 디자인의 재귀 적 특성으로 인해 스택 오버플로가 발생하는지 궁금 했습니까? 미안, 이것이 멍청한 질문이라면 나는 롱 폴링에 익숙하지 않고 객관적으로 익숙하지 않다. c. 예를 들어이 재귀 적 긴 폴링 기법으로 인해 스택 오버플로가 발생합니까?
//long polling in objective-C
- (void) longPoll {
//create an autorelease pool for the thread
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
//compose the request
NSError* error = nil;
NSURLResponse* response = nil;
NSURL* requestUrl = [NSURL URLWithString:@"http://www.mysite.com/pollUrl"];
NSURLRequest* request = [NSURLRequest requestWithURL:requestUrl];
//send the request (will block until a response comes back)
NSData* responseData = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error];
//pass the response on to the handler
//(can also check for errors here, if you want)
[self performSelectorOnMainThread:@selector(dataReceived:)
withObject:responseData waitUntilDone:YES];
//clear the pool
[pool drain];
//send the next poll request
[self performSelectorInBackground:@selector(longPoll) withObject: nil];
}
- (void) startPoll {
//not covered in this example:
// -stopping the poll
// -ensuring that only 1 poll is active at any given time
[self performSelectorInBackground:@selector(longPoll) withObject: nil];
}
- (void) dataReceived: (NSData*) theData {
//process the response here
}
소스 : http://pastebin.com/3z5SM4R0
편집 : 이 잘못 형성 질문과 downvote의 합당 가난한 질문에서 저를 유지하기 위해 도움이 될 것입니다 무엇이 잘못되었는지에 대한 간단한 메모를하는 경우 미래. 그렇지 않으면, stackoverflow는 비우호하고 독점적 인 커뮤니티처럼 느껴지기 시작합니다.
에 ¹According하지만 소년 안녕하세요 때로는 매우 매우 비싼 스레드를 많이 산란한다. – CodaFi
@CodaFi 그래서 모든 재귀마다 새 스레드가 생성됩니까? – David
구현 세부 사항입니다. 기회가 주어지면 도움이 될지도 모릅니다.하지만 GCD를 통해 더 똑똑해지고 구현되기를 바랍니다. 선택기가 백그라운드에서 이미 수행되고 있습니다. 지연시 설정하면 동일한 스레드에서 계속 호출됩니다. 더 나아가서 이것을 NSOperation으로 리팩토링하고 개인 대기열을 만드십시오. 오류를 쉽게 디버그 할 수 있습니다. – CodaFi