Revision 5f3adef4 ml/util/udpSocket.h
ml/util/udpSocket.h | ||
---|---|---|
49 | 49 |
#ifndef UDPSOCKET_H |
50 | 50 |
#define UDPSOCKET_H |
51 | 51 |
|
52 |
#include <stdlib.h> |
|
53 |
#include <unistd.h> |
|
54 |
#include <sys/types.h> |
|
55 |
#include <event2/event.h> |
|
56 |
#include <time.h> |
|
57 |
|
|
58 |
#ifndef WIN32 |
|
59 |
#include <arpa/inet.h> |
|
60 |
#include <netdb.h> |
|
52 |
#include <string.h> |
|
61 | 53 |
#include <netinet/in.h> |
62 |
#include <sys/socket.h> |
|
63 |
#include <fcntl.h> |
|
64 |
#else |
|
65 |
|
|
66 |
#include <winsock2.h> |
|
67 |
|
|
68 |
struct iovec { |
|
69 |
void *iov_base; |
|
70 |
size_t iov_len; |
|
71 |
}; |
|
72 |
|
|
73 |
const char *inet_ntop(int af, const void *src, |
|
74 |
char *dst, size_t size); |
|
75 |
int inet_pton(int af, const char * src, void * dst); |
|
76 |
#endif |
|
77 | 54 |
|
78 | 55 |
/** |
79 | 56 |
* The maximum buffer size for a send or received packet. |
... | ... | |
135 | 112 |
* @param bufferSize The size of the send buffer. |
136 | 113 |
* @param *socketaddr The address of the remote socket |
137 | 114 |
*/ |
138 |
int sendPacketFinal(const int udpSocket, struct iovec *iov, int len, struct sockaddr_in *socketaddr);
|
|
115 |
int sendPacket(const int udpSocket, struct iovec *iov, int len, struct sockaddr_in *socketaddr); |
|
139 | 116 |
|
117 |
/** |
|
118 |
* Decide if a packet should be throttled |
|
119 |
* The implementation follows a leaky bucket algorithm: |
|
120 |
* if the packet would fill the bucket beyond its limit, it is to be discarded |
|
121 |
* |
|
122 |
* @param len The length of the packet to be sent |
|
123 |
* @return OK or THROTTLE |
|
124 |
*/ |
|
125 |
int outputRateControl(int len); |
|
126 |
|
|
127 |
/** |
|
128 |
* Configure the parameters for output rate control. |
|
129 |
* These values may also be set while packets are being transmitted. |
|
130 |
* @param bucketsize The size of the bucket in kbytes |
|
131 |
* @param drainrate The amount of kbytes draining in a second. If drainrate is 0, then rateControl is completely disabled (all packets are passed). |
|
132 |
*/ |
|
133 |
void setOutputRateParams(int bucketsize, int drainrate); |
|
140 | 134 |
|
141 | 135 |
/** |
142 | 136 |
* Receive a udp packet |
... | ... | |
169 | 163 |
*/ |
170 | 164 |
int closeSocket(const int udpSocket); |
171 | 165 |
|
172 |
/** |
|
173 |
* Decide if a packet should be throttled |
|
174 |
* The implementation follows a leaky bucket algorithm: |
|
175 |
* if the packet would fill the bucket beyond its limit, it is to be discarded |
|
176 |
* |
|
177 |
* @param len The length of the packet to be sent |
|
178 |
* @return OK or THROTTLE |
|
179 |
*/ |
|
180 |
int outputRateControl(int len); |
|
181 |
|
|
182 |
/** |
|
183 |
* Configure the parameters for output rate control. |
|
184 |
* These values may also be set while packets are being transmitted. |
|
185 |
* @param bucketsize The size of the bucket in bytes |
|
186 |
* @param drainrate The darining rate in bits/s. If drainrate is 0, then rateControl is completely disabled (all packets are passed). |
|
187 |
*/ |
|
188 |
void setOutputRateParams(int bucketsize, int drainrate); |
|
189 |
|
|
190 |
|
|
191 |
|
|
192 | 166 |
#endif |
Also available in: Unified diff