Changeset b5cf742a in mainline for uspace/app/nettest2/nettest2.c
- Timestamp:
- 2013-06-28T16:22:42Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- edf0d27
- Parents:
- e52b4b5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nettest2/nettest2.c
re52b4b5 rb5cf742a 55 55 56 56 /** Echo module name. */ 57 #define NAME "Nettest2"57 #define NAME "nettest2" 58 58 59 59 /** Packet data pattern. */ 60 #define NETTEST2_TEXT 60 #define NETTEST2_TEXT "Networking test 2 - transfer" 61 61 62 62 static size_t size; … … 107 107 static void nettest2_fill_buffer(char *buffer, size_t size) 108 108 { 109 size_t length; 110 111 length = 0; 109 size_t length = 0; 112 110 while (size > length + sizeof(NETTEST2_TEXT) - 1) { 113 111 memcpy(buffer + length, NETTEST2_TEXT, … … 115 113 length += sizeof(NETTEST2_TEXT) - 1; 116 114 } 117 115 118 116 memcpy(buffer + length, NETTEST2_TEXT, size - length); 119 117 buffer[size] = '\0'; … … 130 128 int value; 131 129 int rc; 132 130 133 131 switch (argv[*index][1]) { 134 132 /* … … 136 134 */ 137 135 case 'f': 138 rc = arg_parse_name_int(argc, argv, index, & family, 0,136 rc = arg_parse_name_int(argc, argv, index, &value, 0, 139 137 socket_parse_protocol_family); 140 138 if (rc != EOK) 141 139 return rc; 140 141 family = (uint16_t) value; 142 142 break; 143 143 case 'h': 144 144 nettest2_print_help(); 145 145 return EOK; 146 break;147 146 case 'm': 148 147 rc = arg_parse_int(argc, argv, index, &messages, 0); 149 148 if (rc != EOK) 150 149 return rc; 150 151 151 break; 152 152 case 'n': … … 154 154 if (rc != EOK) 155 155 return rc; 156 156 157 break; 157 158 case 'p': … … 159 160 if (rc != EOK) 160 161 return rc; 162 161 163 port = (uint16_t) value; 162 164 break; … … 165 167 if (rc != EOK) 166 168 return rc; 169 167 170 size = (value >= 0) ? (size_t) value : 0; 168 171 break; … … 172 175 if (rc != EOK) 173 176 return rc; 177 174 178 type = (sock_type_t) value; 175 179 break; … … 177 181 verbose = true; 178 182 break; 183 179 184 /* 180 185 * Long options with double dash ('-') … … 182 187 case '-': 183 188 if (str_lcmp(argv[*index] + 2, "family=", 7) == 0) { 184 rc = arg_parse_name_int(argc, argv, index, & family, 9,189 rc = arg_parse_name_int(argc, argv, index, &value, 9, 185 190 socket_parse_protocol_family); 186 191 if (rc != EOK) 187 192 return rc; 193 194 family = (uint16_t) value; 188 195 } else if (str_lcmp(argv[*index] + 2, "help", 5) == 0) { 189 196 nettest2_print_help(); … … 201 208 if (rc != EOK) 202 209 return rc; 210 203 211 port = (uint16_t) value; 204 212 } else if (str_lcmp(argv[*index] + 2, "type=", 5) == 0) { … … 207 215 if (rc != EOK) 208 216 return rc; 217 209 218 type = (sock_type_t) value; 210 219 } else if (str_lcmp(argv[*index] + 2, "verbose", 8) == 0) { … … 219 228 return EINVAL; 220 229 } 221 230 222 231 return EOK; 223 232 } … … 266 275 } 267 276 } 268 277 269 278 /* If not before the last argument containing the host */ 270 279 if (index >= argc) { … … 312 321 } 313 322 } 314 323 315 324 /* Check data buffer size. */ 316 325 if (size <= 0) { … … 319 328 size = 1024; 320 329 } 321 330 322 331 /* 323 332 * Prepare the buffer. Allocate size bytes plus one for terminating … … 329 338 return ENOMEM; 330 339 } 331 340 332 341 /* Fill buffer with a pattern. */ 333 342 nettest2_fill_buffer(data, size); 334 343 335 344 /* Check socket count. */ 336 345 if (sockets <= 0) { … … 339 348 sockets = 2; 340 349 } 341 350 342 351 /* 343 352 * Prepare the socket buffer. … … 350 359 } 351 360 socket_ids[sockets] = 0; 352 361 353 362 if (verbose) 354 363 printf("Starting tests\n"); 355 364 356 365 rc = sockets_create(verbose, socket_ids, sockets, family, type); 357 366 if (rc != EOK) 358 367 return rc; 359 368 360 369 if (type == SOCK_STREAM) { 361 370 rc = sockets_connect(verbose, socket_ids, sockets, … … 364 373 return rc; 365 374 } 366 375 367 376 if (verbose) 368 377 printf("\n"); 369 378 370 379 rc = gettimeofday(&time_before, NULL); 371 380 if (rc != EOK) { … … 373 382 return rc; 374 383 } 375 384 376 385 rc = sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, 377 386 &addrlen, data, size, messages); 378 387 if (rc != EOK) 379 388 return rc; 380 389 381 390 rc = gettimeofday(&time_after, NULL); 382 391 if (rc != EOK) { … … 384 393 return rc; 385 394 } 386 395 387 396 if (verbose) 388 397 printf("\tOK\n"); 389 398 390 399 printf("sendto + recvfrom tested in %ld microseconds\n", 391 400 tv_sub(&time_after, &time_before)); 392 401 393 402 rc = gettimeofday(&time_before, NULL); 394 403 if (rc != EOK) { … … 396 405 return rc; 397 406 } 398 407 399 408 rc = sockets_sendto(verbose, socket_ids, sockets, address, addrlen, 400 409 data, size, messages); 401 410 if (rc != EOK) 402 411 return rc; 403 412 404 413 rc = sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, 405 414 data, size, messages); 406 415 if (rc != EOK) 407 416 return rc; 408 417 409 418 rc = gettimeofday(&time_after, NULL); 410 419 if (rc != EOK) { … … 412 421 return rc; 413 422 } 414 423 415 424 if (verbose) 416 425 printf("\tOK\n"); 417 426 418 427 printf("sendto, recvfrom tested in %ld microseconds\n", 419 428 tv_sub(&time_after, &time_before)); 420 429 421 430 rc = sockets_close(verbose, socket_ids, sockets); 422 431 if (rc != EOK) 423 432 return rc; 424 433 425 434 if (verbose) 426 435 printf("\nExiting\n"); 427 436 428 437 return EOK; 429 438 }
Note:
See TracChangeset
for help on using the changeset viewer.