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.
 
 
 
 

57 lines
1.0 KiB

  1. #include <unistd.h>
  2. #ifdef __MINGW32__
  3. #include <windows.h>
  4. #else
  5. #include <poll.h>
  6. #endif
  7. #include <errno.h>
  8. #include "io_internal.h"
  9. #ifdef __MINGW32__
  10. int64 io_waitwrite(int64 d,const char* buf,int64 len) {
  11. long r;
  12. io_entry* e=iarray_get(&io_fds,d);
  13. if (!e) { errno=EBADF; return -3; }
  14. if (e->nonblock) {
  15. unsigned long i=0;
  16. ioctlsocket(d, FIONBIO, &i);
  17. }
  18. r=write(d,buf,len);
  19. if (e->nonblock) {
  20. unsigned long i=1;
  21. ioctlsocket(d, FIONBIO, &i);
  22. }
  23. if (r==-1)
  24. r=-3;
  25. return r;
  26. }
  27. #else
  28. int64 io_waitwrite(int64 d,const char* buf,int64 len) {
  29. long r;
  30. struct pollfd p;
  31. io_entry* e=iarray_get(&io_fds,d);
  32. io_sigpipe();
  33. if (!e) { errno=EBADF; return -3; }
  34. if (e->nonblock) {
  35. again:
  36. p.fd=d;
  37. if (p.fd != d) { errno=EBADF; return -3; } /* catch overflow */
  38. p.events=POLLOUT;
  39. switch (poll(&p,1,-1)) {
  40. case -1: if (errno==EAGAIN) goto again; return -3;
  41. }
  42. }
  43. r=write(d,buf,len);
  44. if (r==-1) {
  45. if (errno==EAGAIN)
  46. goto again;
  47. r=-3;
  48. }
  49. return r;
  50. }
  51. #endif