Is calling read:maxLength: once for every NSStreamEventHasBytesAvailable correct?

前端 未结 1 356
伪装坚强ぢ
伪装坚强ぢ 2021-01-23 08:30

Sample code from Stream Programming Guide:

- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {

    switch(eventCode) {
        case NSStrea         


        
相关标签:
1条回答
  • 2021-01-23 08:56

    Calling read:maxLength: once will work. If you do not read all of the available data then you will receive another HasBytesAvailable event.

    Looping to read all of the data can be a problem. If data continues to arrive then you may starve other tasks scheduled on that run loop. If you instead only read once then other run loop tasks will be allowed to run before the next HasBytesAvailable event is delivered.

    0 讨论(0)
提交回复
热议问题