我正在将数据写入事件内部的流:
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode
如下(取自苹果的文档):
case NSStreamEventHasSpaceAvailable:
uint8_t *readBytes = (uint8_t *)[self.outData mutableBytes];
readBytes += byteIndex;
int dataLength = [self.outData length];
unsigned int length = ((dataLength - byteIndex >= 1024) ? 1024 : (dataLength - byteIndex));
uint8_t buffer[length];
(void)memcpy(buffer, readBytes, length);
length = [self.outputStream write:(const uint8_t *)buffer maxLength:length];
byteIndex += length;
break;
但是,NSStreamEventEndEncountered
当输出流中没有其他内容要写入时,会调用该事件,因此会丢弃输出流。我怎样才能保持这个流打开写作?根据Apple 的文档,此事件被正确调用,因为没有任何内容写入输出流。有任何想法吗?