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.
 
 
 
 

36 lines
744 B

  1. #include "async.h"
  2. #include <stdint.h>
  3. #include <errno.h>
  4. #include <unistd.h>
  5. #define LOG_MODULE "async"
  6. #define LOG_ENABLE_DBG 0
  7. #include "log.h"
  8. enum async_write_status
  9. async_write(int fd, const void *_data, size_t len, size_t *idx)
  10. {
  11. const uint8_t *const data = _data;
  12. size_t left = len - *idx;
  13. while (left > 0) {
  14. ssize_t ret = write(fd, &data[*idx], left);
  15. if (ret < 0) {
  16. if (errno == EAGAIN || errno == EWOULDBLOCK)
  17. return ASYNC_WRITE_REMAIN;
  18. return ASYNC_WRITE_ERR;
  19. }
  20. LOG_DBG("wrote %zd bytes of %zu (%zu left) to FD=%d",
  21. ret, left, left - ret, fd);
  22. *idx += ret;
  23. left -= ret;
  24. }
  25. return ASYNC_WRITE_DONE;
  26. }