network.patch 1022 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. diff --git a/sanei/sanei_tcp.c b/sanei/sanei_tcp.c
  2. index a57d7c7..d0a1e92 100644
  3. --- a/sanei/sanei_tcp.c
  4. +++ b/sanei/sanei_tcp.c
  5. @@ -45,6 +45,7 @@
  6. #include <unistd.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. +#include <time.h>
  10. #ifdef HAVE_WINSOCK2_H
  11. #include <winsock2.h>
  12. @@ -123,14 +124,27 @@ sanei_tcp_write(int fd, const u_char * buf, int count)
  13. ssize_t
  14. sanei_tcp_read(int fd, u_char * buf, int count)
  15. {
  16. - ssize_t bytes_recv = 0, rc = 1;
  17. + ssize_t bytes_recv = 0, rc = 1;
  18. + int retry = 5;
  19. while (bytes_recv < count && rc > 0)
  20. {
  21. rc = recv(fd, buf+bytes_recv, count-bytes_recv, 0);
  22. + DBG(1, "%s: bytes received %d\n", __FUNCTION__, rc);
  23. if (rc > 0)
  24. bytes_recv += rc;
  25. -
  26. + else {
  27. + if ( errno == EAGAIN && retry-- ) {
  28. + DBG(1, "%s: waiting %d\n", __FUNCTION__, retry);
  29. + /* wait for max 1s */
  30. + struct timespec req;
  31. + struct timespec rem;
  32. + req.tv_sec = 0;
  33. + req.tv_nsec= 100000000;
  34. + nanosleep(&req, &rem);
  35. + rc = 1;
  36. + }
  37. + }
  38. }
  39. return bytes_recv;
  40. }