0009-io-implement-network-timeout-default-60s.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From 9cc3ad4781392ff526b4ba5e25c6fd287a219303 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 09/15] 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 dc5ef12..effaf15 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. @@ -73,6 +74,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. @@ -267,6 +271,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. @@ -288,6 +293,13 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
  34. if (n < 0)
  35. {
  36. + if (i_timepassed >= MAX_TIMEOUT && i_total == 0)
  37. + {
  38. + access_t *p_access = (access_t *)p_this;
  39. + p_access->info.b_eof = true;
  40. + goto error;
  41. + }
  42. +
  43. switch (net_errno)
  44. {
  45. case EAGAIN: /* no data */
  46. @@ -326,8 +338,9 @@ net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
  47. return -1;
  48. }
  49. + i_timepassed += POLL_TIMEOUT;
  50. /* Wait for more data */
  51. - if (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), -1) < 0)
  52. + if (poll (ufd, sizeof (ufd) / sizeof (ufd[0]), POLL_TIMEOUT) < 0)
  53. {
  54. if (errno == EINTR)
  55. continue;
  56. --
  57. 1.8.3.4 (Apple Git-47)