Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
580 B

  1. #include <unistd.h>
  2. #include <poll.h>
  3. #include <errno.h>
  4. #include "io_internal.h"
  5. int64 io_waitread(int64 d,char* buf,int64 len) {
  6. long r;
  7. struct pollfd p;
  8. io_entry* e=array_get(&io_fds,sizeof(io_entry),d);
  9. if (!e) { errno=EBADF; return -3; }
  10. if (e->nonblock) {
  11. again:
  12. p.fd=d;
  13. if (p.fd != d) { errno=EBADF; return -3; } /* catch overflow */
  14. p.events=POLLIN;
  15. switch (poll(&p,1,-1)) {
  16. case -1: if (errno==EAGAIN) goto again; return -3;
  17. }
  18. }
  19. r=read(d,buf,len);
  20. if (r==-1) {
  21. if (errno==EAGAIN)
  22. goto again;
  23. r=-3;
  24. }
  25. return r;
  26. }