1 #ifndef _NETWORK_INTERNAL_H_
2 #define _NETWORK_INTERNAL_H_
3 
4 /* Macros for handling struct timeval values. */
5 #define tv_lt(a, b)				\
6 	(((a)->tv_sec < (b)->tv_sec) ||		\
7 	    (((a)->tv_sec == (b)->tv_sec) &&	\
8 		((a)->tv_usec < (b)->tv_usec)))
9 #define tv_add(a, b)	do {			\
10 	(a)->tv_sec += (b)->tv_sec;		\
11 	(a)->tv_usec += (b)->tv_usec;		\
12 	if ((a)->tv_usec >= 1000000) {		\
13 		(a)->tv_usec -= 1000000;	\
14 		(a)->tv_sec += 1;		\
15 	}					\
16 } while (0)
17 #define tv_sub(a, b)	do {			\
18 	(a)->tv_sec -= (b)->tv_sec;		\
19 	(a)->tv_usec -= (b)->tv_usec;		\
20 	if ((a)->tv_usec < 0) {			\
21 		(a)->tv_usec += 1000000;	\
22 		(a)->tv_sec -= 1;		\
23 	}					\
24 } while (0)
25 
26 /**
27  * network_cork(fd):
28  * Clear the TCP_NODELAY socket option, and set TCP_CORK or TCP_NOPUSH if
29  * either is defined.
30  */
31 int network_cork(int);
32 
33 /**
34  * network_uncork(fd):
35  * Set the TCP_NODELAY socket option, and clear TCP_CORK or TCP_NOPUSH if
36  * either is defined.
37  */
38 int network_uncork(int);
39 
40 /**
41  * network_register_suspend(op):
42  * Suspend ${op} operations, on all file descriptors.
43  */
44 int network_register_suspend(int);
45 
46 /**
47  * network_register_resume(op):
48  * Resume pending ${op} operations, on all file descriptors.
49  */
50 int network_register_resume(int);
51 
52 /**
53  * network_register_fini(void):
54  * Free resources allocated.
55  */
56 void network_register_fini(void);
57 
58 /**
59  * network_sleep_fini(void):
60  * Free resources allocated.
61  */
62 void network_sleep_fini(void);
63 
64 /**
65  * network_bwlimit_get(op, len):
66  * Get the amount of instantaneously allowed bandwidth for ${op} operations.
67  */
68 int network_bwlimit_get(int, size_t *);
69 
70 /**
71  * network_bwlimit_eat(op, len):
72  * Consume ${len} bytes of bandwidth quota for ${op} operations.
73  */
74 int network_bwlimit_eat(int, size_t);
75 
76 #endif /* !_NETWORK_H_ */
77