我在与我的iOS应用EPIPE一个问题,它不是在被抓@尝试/ @捕捉/ @ finally块。 我怎么能抓住这个信号(SIGPIPE,可能)...
我已经建立了一个“网络代理”到我的应用程序将处理某些类型的URL - 在这种错误下,似乎远端(也是在我的应用程序,但在iOS的库藏)关闭其插座端。 我没有得到通知(要这样呢?有什么我应该用NSFileHandle这可能有助于这里注册?)。
我基于HttpServer的马特·加拉格尔放在一起(这家代理在这里 ),而问题是在子类HTTPRequestHandler
他放在一起级。 下面的代码(该代码是相当于startResponse
在基类方法):
-(void)proxyTS:(SSProxyTSResource *)proxyTS didReceiveResource:(NSData *)resource
{
NSLog(@"[%@ %@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
CFHTTPMessageRef response =
CFHTTPMessageCreateResponse(kCFAllocatorDefault, 200, NULL, kCFHTTPVersion1_1);
CFHTTPMessageSetHeaderFieldValue(response,
(CFStringRef)@"Content-Type",
(__bridge CFStringRef)s_MIMEtype);
CFHTTPMessageSetHeaderFieldValue(response,
(CFStringRef)@"Connection",
(CFStringRef)@"close");
CFHTTPMessageSetBody(response,
(__bridge CFDataRef)resource);
CFDataRef headerData = CFHTTPMessageCopySerializedMessage(response);
@try
{
NSLog(@" -> writing %u bytes to filehandle...",[((__bridge NSData *)headerData) length]);
[self.fileHandle writeData:(__bridge NSData *)headerData];
}
@catch (NSException *exception)
{
// Ignore the exception, it normally just means the client
// closed the connection from the other end.
}
@finally
{
NSLog(@" *ding*");
CFRelease(headerData);
CFRelease(response);
[self.server closeHandler:self];
}
}
下面是在控制台日志中显示的,当它崩溃了:
Jan 15 14:55:10 AWT-NoTouch-iPhone-1 Streamer[1788] <Warning>: [SSProxyTSResponseHandler proxyTS:didReceiveResource:]
Jan 15 14:55:10 iPhone-1 Streamer[1788] <Warning>: -> writing 261760 bytes to filehandle...
Jan 15 14:55:11 iPhone-1 com.apple.launchd[1] (UIKitApplication:com.XXX.Streamer[0xf58][1788]) <Warning>: (UIKitApplication:com.XXX.Streamer[0xf58]) Exited abnormally: Broken pipe: 13
看来,由于另一端关闭了管道write()
失败,所以如果有人能在我怎样可以发现它已经关闭指向我,而不是试图将数据写入或任何会令它不会崩溃我的程序,将是非常有益的。