1 | // Copyright (c) Microsoft. All rights reserved.
|
---|
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
---|
3 |
|
---|
4 | #ifndef GBNETWORK_H
|
---|
5 | #define GBNETWORK_H
|
---|
6 |
|
---|
7 | #include "azure_c_shared_utility/umock_c_prod.h"
|
---|
8 |
|
---|
9 | #ifdef __cplusplus
|
---|
10 | #include <cstddef>
|
---|
11 | #include <cstdlib>
|
---|
12 | #include <cstdint>
|
---|
13 | extern "C"
|
---|
14 | {
|
---|
15 | #else
|
---|
16 | #include <stddef.h>
|
---|
17 | #include <stdlib.h>
|
---|
18 | #include <stdint.h>
|
---|
19 | #endif
|
---|
20 |
|
---|
21 | #ifdef WIN32
|
---|
22 | #include <winsock2.h>
|
---|
23 | #else
|
---|
24 | #include <sys/socket.h>
|
---|
25 | #endif
|
---|
26 |
|
---|
27 | /* all translation units that need network measurement need to have GB_MEASURE_NETWORK_FOR_THIS defined */
|
---|
28 | /* GB_DEBUG_NETWORK is the switch that turns the measurement on/off, so that it is not on always */
|
---|
29 | #if defined(GB_DEBUG_NETWORK)
|
---|
30 |
|
---|
31 | MOCKABLE_FUNCTION(, int, gbnetwork_init);
|
---|
32 | MOCKABLE_FUNCTION(, void, gbnetwork_deinit);
|
---|
33 |
|
---|
34 | #ifdef WIN32
|
---|
35 | MOCKABLE_FUNCTION(, int, gbnetwork_send, SOCKET, sock, const char*, buf, int, len, int, flags);
|
---|
36 | #else
|
---|
37 | MOCKABLE_FUNCTION(, ssize_t, gbnetwork_send, int, sock, const void*, buf, size_t, len, int, flags);
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | #ifdef WIN32
|
---|
41 | MOCKABLE_FUNCTION(, int, gbnetwork_recv, SOCKET, sock, char*, buf, int, len, int, flags);
|
---|
42 | #else
|
---|
43 | MOCKABLE_FUNCTION(, ssize_t, gbnetwork_recv, int, sock, void*, buf, size_t, len, int, flags);
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | MOCKABLE_FUNCTION(, uint64_t, gbnetwork_getBytesSent);
|
---|
47 | MOCKABLE_FUNCTION(, uint64_t, gbnetwork_getNumSends);
|
---|
48 | MOCKABLE_FUNCTION(, uint64_t, gbnetwork_getBytesRecv);
|
---|
49 | MOCKABLE_FUNCTION(, uint64_t, gbnetwork_getNumRecv);
|
---|
50 | MOCKABLE_FUNCTION(, void, gbnetwork_resetMetrics);
|
---|
51 |
|
---|
52 | /* if GB_MEASURE_NETWORK_FOR_THIS is defined then we want to redirect network send functions to gbnetwork_xxx functions */
|
---|
53 | #ifdef GB_MEASURE_NETWORK_FOR_THIS
|
---|
54 | #define send gbnetwork_send
|
---|
55 | #define recv gbnetwork_recv
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | #else /* GB_DEBUG_NETWORK */
|
---|
59 |
|
---|
60 | #define gbnetwork_init() 0
|
---|
61 | #define gbnetwork_deinit() ((void)0)
|
---|
62 | #define gbnetwork_getBytesSent() 0
|
---|
63 | #define gbnetwork_getNumSends() 0
|
---|
64 |
|
---|
65 | #define gbnetwork_getBytesRecv() 0
|
---|
66 | #define gbnetwork_getNumRecv() 0
|
---|
67 |
|
---|
68 | #endif /* GB_DEBUG_NETWORK */
|
---|
69 |
|
---|
70 | #ifdef __cplusplus
|
---|
71 | }
|
---|
72 | #endif
|
---|
73 |
|
---|
74 | #endif /* GBNETWORK_H */
|
---|