调试器停止在 ASIHTTPRequest 的 ScheduleReadStream 上,没有错误

发布于 2024-12-27 23:05:13 字数 1123 浏览 1 评论 0原文

调试器在 ASIHTTPRequest 的 ScheduleReadStream 方法中暂停,但不会产生错误。

更具体地说,它停在这条线上:

[[self readStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]];

无论我点击播放多少次,它都不会离开这条线或在控制台中报告任何错误。然而,我确实注意到,当我点击播放时,主线程会推进一些操作。

我设置的方式是,我有一个在后台线程上工作的下载器(因此当它从已完成的请求中接收到它时,它可以进行解析和图像操作)。此下载器对象使用 ASINetworkQueue 来安排请求。我想知道这是否会导致僵局。

下面是在解析刚刚完成的请求(不是队列的一部分)中的一些数据后将请求添加到队列中的代码片段。

- (void)requestFinished:(ASIHTTPRequest *)request
{
    dispatch_async(serialQueue, ^{
        NSData *responseData = [request responseData];
        NSXMLParser *parser = [[NSXMLParser alloc] initWithData:responseData];
        [parser setDelegate:self];
        if ([parser parse]) {
            //Add pending operations
            for (NSNumber * key in self.currentRequests.keyEnumerator) {
                //Unrelated code getting the request from a dictionary
                [self.networkQueue addOperation:request];
            }
            [self.networkQueue go];
        }
    });
}

请注意,我还在整个代码中异步执行不相关的请求,这可能在填充/告知该队列的同时进行。

The debugger pauses within ASIHTTPRequest's scheduleReadStream method, but produces no errors.

More specifically, it's stopping on this line:

[[self readStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]];

No matter how many times I hit play, it doesn't move off this line or report any errors in the console. I did notice that the main thread advances through some of its operations when I hit play, however.

The way I have things setup, I have a downloader that's working on a background thread (so it can do parsing and image manipulation when it receives it from the completed requests). This downloader object is using an ASINetworkQueue to schedule the requests. I'm wondering if maybe this is causing a deadlock.

Here's the snippet of code that adds the requests to the queue after parsing some data from a request that just finished (not part of the queue).

- (void)requestFinished:(ASIHTTPRequest *)request
{
    dispatch_async(serialQueue, ^{
        NSData *responseData = [request responseData];
        NSXMLParser *parser = [[NSXMLParser alloc] initWithData:responseData];
        [parser setDelegate:self];
        if ([parser parse]) {
            //Add pending operations
            for (NSNumber * key in self.currentRequests.keyEnumerator) {
                //Unrelated code getting the request from a dictionary
                [self.networkQueue addOperation:request];
            }
            [self.networkQueue go];
        }
    });
}

Note that I'm also doing unrelated requests asynchronously throughout the code, which could be going on at the same time as this queue is being filled/told to go.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柳絮泡泡 2025-01-03 23:05:13

想通了。结果发现有一个 EXC_BAD_ACCESS,但在 iPhone 上运行时并未显示。当在模拟器上运行时,它实际上显示正确。这种错误的访问是由于我没有使用 initWithURL 方法,而是设置了 URL(因为在创建对象时我还没有可用的 URL)。一旦 URL 准备好并且一切都很好,我现在就调用 initWithURL

Figured it out. Turns out there was an EXC_BAD_ACCESS but it wasn't showing up when running on the iPhone. When running on the simulator it actually showed up properly. This bad access was due to the fact that I didn't use the initWithURL method, instead setting the URL (since when creating the object I didn't have the URL available yet). I call initWithURL now once the URL is ready and everything is good.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文