objective c - NSStream: Is there any airtight defense against blocking? -


under stream programming guide: polling versus run-loop scheduling section, last para says:

it should pointed out neither polling nor run-loop scheduling approaches airtight defenses against blocking. if nsinputstream hasbytesavailable method or nsoutputstream hasspaceavailable method returns no, means in both cases stream has no available bytes or space. however, if either of these methods returns yes, can mean there available bytes or space or way find out attempt read or write operation (which lead momentary block). nsstreameventhasbytesavailable , nsstreameventhasspaceavailable stream events have identical semantics.

so, seems neither hasbytesavailable/hasspaceavailable, nor stream events provide guarantee against blocking. there way guaranteed non-blocking behaviour streams? create background thread guaranteed non blocking behaviour, want avoid doing that.

also, fail understand why nsstream can't provide gauranteed non-blocking behaviour given low-level apis (select, kqueue, etc.) can so. can explain why case?

you either run reading or writing in different thread or can't use nsstream. there no other ways guaranteed non-blocking behavior.

for regular files , sockets non-blocking behavior if schedule stream on runloop. there other types of stream not implemented on top of file descriptor. documenting base class not non-blocking apple keeps options open of implementing different streams in way can't guarantee non-blocking property.

but since can't check source code can speculate on this. might want file bug apple requesting them update docs information.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -