Read the requested range of bytes
- iOS 9.0+
- macOS 10.11+
The minimum number of bytes the caller wants to read.
The maximum number of bytes the caller wants to read.
The completion handler to be invoked when data has been read or an error occurred.
The completion handler will be invoked when:
The exact number of requested bytes have been read;
datawill be non-
Fewer than the requested number of bytes, or no bytes, have been read, and the connection's read side has been closed.
nil, depending on whether there was any data to be read when the connection's read side was closed.
Some fatal error has occurred, returned in
datawill be nil.
To know when to schedule a read again, check for the condition whether an error has occurred.
For better performance, the caller should pick the effective minimum and maximum lengths. For example, if the caller absolutely needs a specific number of bytes before it can make any progress, use that value as the minimum. The maximum bytes can be the upperbound that the caller wants to read. Typically, the minimum length can be the caller protocol fixed-size header and the maximum length can be the maximum size of the payload or the size of the current read buffer.