0015-io-implement-network-timeout-default-60s.patch 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. From baf0d1cd5a92aae1e22e11abcb38777b688ea993 Mon Sep 17 00:00:00 2001
  2. From: Gleb Pinigin <gpinigin@gmail.com>
  3. Date: Sun, 28 Jul 2013 18:32:51 +0700
  4. Subject: [PATCH 15/16] io: implement network timeout(default 60s)
  5. ---
  6. src/network/io.c | 15 ++++++++++++++-
  7. 1 file changed, 14 insertions(+), 1 deletion(-)
  8. diff --git a/src/network/io.c b/src/network/io.c
  9. index 9b13b2a..f625dd4 100644
  10. --- a/src/network/io.c
  11. +++ b/src/network/io.c
  12. @@ -33,6 +33,7 @@
  13. #endif
  14. #include <vlc_common.h>
  15. +#include <vlc_access.h>
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. @@ -69,6 +70,9 @@
  19. # define SOL_DCCP 269
  20. #endif
  21. +#define MAX_TIMEOUT 60000
  22. +#define POLL_TIMEOUT 10000
  23. +
  24. #include "libvlc.h" /* vlc_object_waitpipe */
  25. extern int rootwrap_bind (int family, int socktype, int protocol,
  26. @@ -263,6 +267,7 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
  27. ufd[1].fd = vlc_object_waitpipe (p_this);
  28. ufd[1].events = POLLIN;
  29. + int i_timepassed = 0;
  30. size_t i_total = 0;
  31. do
  32. {
  33. @@ -291,6 +296,12 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
  34. case EWOULDBLOCK:
  35. #endif
  36. case EINTR: /* asynchronous signal */
  37. + if (i_timepassed >= MAX_TIMEOUT && i_total == 0)
  38. + {
  39. + access_t *p_access = (access_t *)p_this;
  40. + p_access->info.b_eof = true;
  41. + goto error;
  42. + }
  43. break;
  44. #ifdef _WIN32
  45. case WSAEMSGSIZE: /* datagram too big */
  46. @@ -320,10 +331,12 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
  47. errno = EINTR;
  48. return -1;
  49. }
  50. - while (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1) < 0)
  51. + while (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), POLL_TIMEOUT) < 0)
  52. if (errno != EINTR)
  53. goto error;
  54. + i_timepassed += POLL_TIMEOUT;
  55. +
  56. if (ufd[1].revents)
  57. {
  58. msg_Dbg (p_this, "socket %d polling interrupted", fd);
  59. --
  60. 1.7.12.4 (Apple Git-37)