tsnetwork_internal.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef NETWORK_INTERNAL_H_
  2. #define NETWORK_INTERNAL_H_
  3. /* Macros for handling struct timeval values. */
  4. #define tv_lt(a, b) \
  5. (((a)->tv_sec < (b)->tv_sec) || \
  6. (((a)->tv_sec == (b)->tv_sec) && \
  7. ((a)->tv_usec < (b)->tv_usec)))
  8. #define tv_add(a, b) do { \
  9. (a)->tv_sec += (b)->tv_sec; \
  10. (a)->tv_usec += (b)->tv_usec; \
  11. if ((a)->tv_usec >= 1000000) { \
  12. (a)->tv_usec -= 1000000; \
  13. (a)->tv_sec += 1; \
  14. } \
  15. } while (0)
  16. #define tv_sub(a, b) do { \
  17. (a)->tv_sec -= (b)->tv_sec; \
  18. (a)->tv_usec -= (b)->tv_usec; \
  19. if ((a)->tv_usec < 0) { \
  20. (a)->tv_usec += 1000000; \
  21. (a)->tv_sec -= 1; \
  22. } \
  23. } while (0)
  24. /**
  25. * network_register_suspend(op):
  26. * Suspend ${op} operations, on all file descriptors.
  27. */
  28. int network_register_suspend(int);
  29. /**
  30. * network_register_resume(op):
  31. * Resume pending ${op} operations, on all file descriptors.
  32. */
  33. int network_register_resume(int);
  34. /**
  35. * network_register_fini(void):
  36. * Free resources allocated.
  37. */
  38. void network_register_fini(void);
  39. /**
  40. * network_sleep_fini(void):
  41. * Free resources allocated.
  42. */
  43. void network_sleep_fini(void);
  44. /**
  45. * network_bwlimit_get(op, len):
  46. * Get the amount of instantaneously allowed bandwidth for ${op} operations.
  47. */
  48. int network_bwlimit_get(int, size_t *);
  49. /**
  50. * network_bwlimit_eat(op, len):
  51. * Consume ${len} bytes of bandwidth quota for ${op} operations.
  52. */
  53. int network_bwlimit_eat(int, size_t);
  54. #endif /* !NETWORK_INTERNAL_H_ */