diff options
Diffstat (limited to 'testing/Lossless_UDP_testserver.c')
-rw-r--r-- | testing/Lossless_UDP_testserver.c | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c index 0ed214e9..a8097048 100644 --- a/testing/Lossless_UDP_testserver.c +++ b/testing/Lossless_UDP_testserver.c | |||
@@ -43,7 +43,6 @@ | |||
43 | 43 | ||
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | |||
47 | #define PORT 33445 | 46 | #define PORT 33445 |
48 | 47 | ||
49 | void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) | 48 | void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) |
@@ -51,14 +50,14 @@ void printpacket(uint8_t * data, uint32_t length, IP_Port ip_port) | |||
51 | uint32_t i; | 50 | uint32_t i; |
52 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); | 51 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); |
53 | printf("--------------------BEGIN-----------------------------\n"); | 52 | printf("--------------------BEGIN-----------------------------\n"); |
54 | for(i = 0; i < length; i++) | 53 | for(i = 0; i < length; i++) { |
55 | { | ||
56 | if(data[i] < 16) | 54 | if(data[i] < 16) |
57 | printf("0"); | 55 | printf("0"); |
58 | printf("%hhX",data[i]); | 56 | printf("%hhX",data[i]); |
59 | } | 57 | } |
60 | printf("\n--------------------END-----------------------------\n\n\n"); | 58 | printf("\n--------------------END-----------------------------\n\n\n"); |
61 | } | 59 | } |
60 | |||
62 | /* | 61 | /* |
63 | void printpackets(Data test) | 62 | void printpackets(Data test) |
64 | { | 63 | { |
@@ -113,23 +112,20 @@ void printconnection(int connection_id) | |||
113 | 112 | ||
114 | } | 113 | } |
115 | */ | 114 | */ |
116 | //recieve packets and send them to the packethandler | 115 | |
117 | //run doLossless_UDP(); | 116 | /* recieve packets and send them to the packethandler |
117 | * run doLossless_UDP(); */ | ||
118 | void Lossless_UDP() | 118 | void Lossless_UDP() |
119 | { | 119 | { |
120 | IP_Port ip_port; | 120 | IP_Port ip_port; |
121 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 121 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
122 | uint32_t length; | 122 | uint32_t length; |
123 | while(receivepacket(&ip_port, data, &length) != -1) | 123 | while(receivepacket(&ip_port, data, &length) != -1) { |
124 | { | ||
125 | //if(rand() % 3 != 1)//add packet loss | 124 | //if(rand() % 3 != 1)//add packet loss |
126 | //{ | 125 | //{ |
127 | if(LosslessUDP_handlepacket(data, length, ip_port)) | 126 | if(LosslessUDP_handlepacket(data, length, ip_port)) { |
128 | { | ||
129 | printpacket(data, length, ip_port); | 127 | printpacket(data, length, ip_port); |
130 | } | 128 | } else { |
131 | else | ||
132 | { | ||
133 | //printconnection(0); | 129 | //printconnection(0); |
134 | printf("Received handled packet with length: %u\n", length); | 130 | printf("Received handled packet with length: %u\n", length); |
135 | } | 131 | } |
@@ -137,14 +133,12 @@ void Lossless_UDP() | |||
137 | } | 133 | } |
138 | 134 | ||
139 | doLossless_UDP(); | 135 | doLossless_UDP(); |
140 | |||
141 | } | 136 | } |
142 | 137 | ||
143 | 138 | ||
144 | int main(int argc, char *argv[]) | 139 | int main(int argc, char *argv[]) |
145 | { | 140 | { |
146 | if (argc < 2) | 141 | if (argc < 2) { |
147 | { | ||
148 | printf("usage: %s filename\n", argv[0]); | 142 | printf("usage: %s filename\n", argv[0]); |
149 | exit(0); | 143 | exit(0); |
150 | } | 144 | } |
@@ -167,14 +161,11 @@ int main(int argc, char *argv[]) | |||
167 | uint64_t timer = current_time(); | 161 | uint64_t timer = current_time(); |
168 | 162 | ||
169 | 163 | ||
170 | while(1) | 164 | while(1) { |
171 | { | ||
172 | Lossless_UDP(); | 165 | Lossless_UDP(); |
173 | connection = incoming_connection(); | 166 | connection = incoming_connection(); |
174 | if(connection != -1) | 167 | if(connection != -1) { |
175 | { | 168 | if(is_connected(connection) == 2) { |
176 | if(is_connected(connection) == 2) | ||
177 | { | ||
178 | printf("Recieved the connection.\n"); | 169 | printf("Recieved the connection.\n"); |
179 | 170 | ||
180 | } | 171 | } |
@@ -185,25 +176,20 @@ int main(int argc, char *argv[]) | |||
185 | 176 | ||
186 | timer = current_time(); | 177 | timer = current_time(); |
187 | 178 | ||
188 | while(1) | 179 | while(1) { |
189 | { | ||
190 | //printconnection(0); | 180 | //printconnection(0); |
191 | Lossless_UDP(); | 181 | Lossless_UDP(); |
192 | if(is_connected(connection) >= 2) | 182 | if(is_connected(connection) >= 2) { |
193 | { | ||
194 | kill_connection_in(connection, 3000000); | 183 | kill_connection_in(connection, 3000000); |
195 | read = read_packet(connection, buffer); | 184 | read = read_packet(connection, buffer); |
196 | if(read != 0) | 185 | if(read != 0) { |
197 | { | ||
198 | // printf("Recieved data.\n"); | 186 | // printf("Recieved data.\n"); |
199 | if(!fwrite(buffer, read, 1, file)) | 187 | if(!fwrite(buffer, read, 1, file)) { |
200 | { | ||
201 | printf("file write error\n"); | 188 | printf("file write error\n"); |
202 | } | 189 | } |
203 | } | 190 | } |
204 | } | 191 | } |
205 | if(is_connected(connection) == 4) | 192 | if(is_connected(connection) == 4) { |
206 | { | ||
207 | printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); | 193 | printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); |
208 | fclose(file); | 194 | fclose(file); |
209 | return 1; | 195 | return 1; |