0010-MINOR-implement-network-timeout-default-60s.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. From 0b816ffc8447a88cac3dd99e7a576637f96692a9 Mon Sep 17 00:00:00 2001
  2. From: Gleb Pinigin <gpinigin@gmail.com>
  3. Date: Mon, 25 Mar 2013 11:09:33 +0700
  4. Subject: [PATCH 4/4] MINOR implement network timeout(default 60s)
  5. ---
  6. src/network/io.c | 19 +++++++++++++++++--
  7. 1 file changed, 17 insertions(+), 2 deletions(-)
  8. diff --git a/src/network/io.c b/src/network/io.c
  9. index 7cc9764..16ea48c 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. @@ -265,15 +269,19 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
  27. if (ufd[1].fd == -1)
  28. return -1; /* vlc_object_waitpipe() sets errno */
  29. + int i_timepassed = 0;
  30. +
  31. while (i_buflen > 0)
  32. {
  33. - if (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1) < 0)
  34. + if (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), POLL_TIMEOUT) < 0)
  35. {
  36. if (errno != EINTR)
  37. goto error;
  38. continue;
  39. }
  40. + i_timepassed += POLL_TIMEOUT;
  41. +
  42. if (i_total > 0)
  43. {
  44. /* Errors (-1) and EOF (0) will be returned on next call,
  45. @@ -357,7 +365,14 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
  46. case EWOULDBLOCK:
  47. #endif
  48. case EINTR: /* asynchronous signal */
  49. - continue;
  50. + if (i_timepassed >= MAX_TIMEOUT && i_total == 0)
  51. + {
  52. + access_t *p_access = (access_t *)p_this;
  53. + p_access->info.b_eof = true;
  54. + goto error;
  55. + }
  56. + else
  57. + continue;
  58. }
  59. #endif
  60. goto error;
  61. --
  62. 1.7.12.4 (Apple Git-37)