Guest User

Untitled

a guest
Dec 11th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. DISPATCH_SOURCE_TYPE_READ : file descriptor를 모니터한다.
  2.  
  3. dispatch_queue_t globalQueue = dispatch_get_global_queue
  4. (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  5.  
  6. dispatch_source_t stdinSource
  7. = dispatch_source_create ( DISPATCH_SOURCE_TYPE_READ,
  8. STDIN_FILENO, //file descriptors
  9. 0,
  10. globalQueue );
  11.  
  12. dispatch_source_set_event_handler ( stdinSource,
  13. ^{
  14. char buf[1024];
  15. int len = read(STDIN_FILENO, buf, sizeof(buf));
  16. if(len > 0)
  17. NSLog(@"Got data from stdin: %.*s", len, buf);
  18. });
  19.  
  20. dispatch_resume(stdinSource);
Add Comment
Please, Sign In to add comment