Changeset 5f69504 in mainline
- Timestamp:
- 2010-11-06T23:03:17Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 774e9ecd
- Parents:
- 0bbef9b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nettest2/nettest2.c
r0bbef9b r5f69504 44 44 #include <time.h> 45 45 #include <arg_parse.h> 46 #include <err.h>47 46 48 47 #include <net/in.h> … … 111 110 int main(int argc, char *argv[]) 112 111 { 113 ERROR_DECLARE;114 115 112 size_t size = 28; 116 113 int verbose = 0; … … 135 132 struct timeval time_before; 136 133 struct timeval time_after; 134 135 int rc; 137 136 138 137 // parse the command line arguments … … 144 143 // short options with only one letter 145 144 case 'f': 146 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family)); 145 rc = arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family); 146 if (rc != EOK) 147 return rc; 147 148 break; 148 149 case 'h': … … 151 152 break; 152 153 case 'm': 153 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 0)); 154 rc = arg_parse_int(argc, argv, &index, &messages, 0); 155 if (rc != EOK) 156 return rc; 154 157 break; 155 158 case 'n': 156 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 0)); 159 rc = arg_parse_int(argc, argv, &index, &sockets, 0); 160 if (rc != EOK) 161 return rc; 157 162 break; 158 163 case 'p': 159 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 164 rc = arg_parse_int(argc, argv, &index, &value, 0); 165 if (rc != EOK) 166 return rc; 160 167 port = (uint16_t) value; 161 168 break; 162 169 case 's': 163 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0)); 170 rc = arg_parse_int(argc, argv, &index, &value, 0); 171 if (rc != EOK) 172 return rc; 164 173 size = (value >= 0) ? (size_t) value : 0; 165 174 break; 166 175 case 't': 167 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type)); 176 rc = arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type); 177 if (rc != EOK) 178 return rc; 168 179 type = (sock_type_t) value; 169 180 break; … … 174 185 case '-': 175 186 if (str_lcmp(argv[index] + 2, "family=", 7) == 0) { 176 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family)); 187 rc = arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family); 188 if (rc != EOK) 189 return rc; 177 190 } else if (str_lcmp(argv[index] + 2, "help", 5) == 0) { 178 191 nettest2_print_help(); 179 192 return EOK; 180 193 } else if (str_lcmp(argv[index] + 2, "messages=", 6) == 0) { 181 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 8)); 194 rc = arg_parse_int(argc, argv, &index, &messages, 8); 195 if (rc != EOK) 196 return rc; 182 197 } else if (str_lcmp(argv[index] + 2, "sockets=", 6) == 0) { 183 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 8)); 198 rc = arg_parse_int(argc, argv, &index, &sockets, 8); 199 if (rc != EOK) 200 return rc; 184 201 } else if (str_lcmp(argv[index] + 2, "port=", 5) == 0) { 185 ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7)); 202 rc = arg_parse_int(argc, argv, &index, &value, 7); 203 if (rc != EOK) 204 return rc; 186 205 port = (uint16_t) value; 187 206 } else if (str_lcmp(argv[index] + 2, "type=", 5) == 0) { 188 ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type)); 207 rc = arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type); 208 if (rc != EOK) 209 return rc; 189 210 type = (sock_type_t) value; 190 211 } else if (str_lcmp(argv[index] + 2, "verbose", 8) == 0) { … … 233 254 234 255 // parse the last argument which should contain the address 235 if (ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))) { 236 fprintf(stderr, "Address parse error %d\n", ERROR_CODE); 237 return ERROR_CODE; 256 rc = inet_pton(family, argv[argc - 1], address_start); 257 if (rc != EOK) { 258 fprintf(stderr, "Address parse error %d\n", rc); 259 return rc; 238 260 } 239 261 … … 271 293 printf("Starting tests\n"); 272 294 273 ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type)); 274 275 if (type == SOCK_STREAM) 276 ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen)); 295 rc = sockets_create(verbose, socket_ids, sockets, family, type); 296 if (rc != EOK) 297 return rc; 298 299 if (type == SOCK_STREAM) { 300 rc = sockets_connect(verbose, socket_ids, sockets, address, addrlen); 301 if (rc != EOK) 302 return rc; 303 } 277 304 278 305 if (verbose) 279 306 printf("\n"); 280 307 281 if (ERROR_OCCURRED(gettimeofday(&time_before, NULL))) { 282 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE); 283 return ERROR_CODE; 284 } 285 286 ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages)); 287 288 if (ERROR_OCCURRED(gettimeofday(&time_after, NULL))) { 289 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE); 290 return ERROR_CODE; 308 rc = gettimeofday(&time_before, NULL); 309 if (rc != EOK) { 310 fprintf(stderr, "Get time of day error %d\n", rc); 311 return rc; 312 } 313 314 rc = sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages); 315 if (rc != EOK) 316 return rc; 317 318 rc = gettimeofday(&time_after, NULL); 319 if (rc != EOK) { 320 fprintf(stderr, "Get time of day error %d\n", rc); 321 return rc; 291 322 } 292 323 … … 296 327 printf("sendto + recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before)); 297 328 298 if (ERROR_OCCURRED(gettimeofday(&time_before, NULL))) { 299 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE); 300 return ERROR_CODE; 301 } 302 303 ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages)); 304 ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages)); 305 306 if (ERROR_OCCURRED(gettimeofday(&time_after, NULL))) { 307 fprintf(stderr, "Get time of day error %d\n", ERROR_CODE); 308 return ERROR_CODE; 329 rc = gettimeofday(&time_before, NULL); 330 if (rc != EOK) { 331 fprintf(stderr, "Get time of day error %d\n", rc); 332 return rc; 333 } 334 335 rc = sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages); 336 if (rc != EOK) 337 return rc; 338 339 rc = sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages); 340 if (rc != EOK) 341 return rc; 342 343 rc = gettimeofday(&time_after, NULL); 344 if (rc != EOK) { 345 fprintf(stderr, "Get time of day error %d\n", rc); 346 return rc; 309 347 } 310 348 … … 314 352 printf("sendto, recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before)); 315 353 316 ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets)); 354 rc = sockets_close(verbose, socket_ids, sockets); 355 if (rc != EOK) 356 return rc; 317 357 318 358 if (verbose)
Note:
See TracChangeset
for help on using the changeset viewer.