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