Changeset 126 for pjproject/trunk/pjlib/src/pjlib-test/ioq_udp.c
- Timestamp:
- Jan 20, 2006 9:03:36 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pjlib-test/ioq_udp.c
r65 r126 119 119 { 120 120 pj_sock_t ssock=-1, csock=-1; 121 pj_sockaddr_in addr ;121 pj_sockaddr_in addr, dst_addr; 122 122 int addrlen; 123 123 pj_pool_t *pool = NULL; … … 155 155 // Bind server socket. 156 156 TRACE_("bind socket..."); 157 memset(&addr, 0, sizeof(addr));157 pj_memset(&addr, 0, sizeof(addr)); 158 158 addr.sin_family = PJ_AF_INET; 159 159 addr.sin_port = pj_htons(PORT); … … 187 187 } 188 188 189 // Set destination address to send the packet.190 TRACE_("set destination address...");191 temp = pj_str("127.0.0.1");192 if ((rc=pj_sockaddr_in_init(&addr, &temp, PORT)) != 0) {193 app_perror("...error: unable to resolve 127.0.0.1", rc);194 status=-26; goto on_error;195 }196 197 189 // Randomize send_buf. 198 190 pj_create_random_string(send_buf, bufsize); … … 200 192 // Register reading from ioqueue. 201 193 TRACE_("start recvfrom..."); 194 pj_memset(&addr, 0, sizeof(addr)); 202 195 addrlen = sizeof(addr); 203 196 bytes = bufsize; … … 217 210 } 218 211 212 // Set destination address to send the packet. 213 TRACE_("set destination address..."); 214 temp = pj_str("127.0.0.1"); 215 if ((rc=pj_sockaddr_in_init(&dst_addr, &temp, PORT)) != 0) { 216 app_perror("...error: unable to resolve 127.0.0.1", rc); 217 status=-290; goto on_error; 218 } 219 219 220 // Write must return the number of bytes. 220 221 TRACE_("start sendto..."); 221 222 bytes = bufsize; 222 rc = pj_ioqueue_sendto(ckey, &write_op, send_buf, &bytes, 0, & addr,223 sizeof( addr));223 rc = pj_ioqueue_sendto(ckey, &write_op, send_buf, &bytes, 0, &dst_addr, 224 sizeof(dst_addr)); 224 225 if (rc != PJ_SUCCESS && rc != PJ_EPENDING) { 225 226 app_perror("...error: pj_ioqueue_sendto", rc); … … 269 270 } 270 271 271 if (memcmp(send_buf, recv_buf, bufsize) != 0) { 272 status=-70; goto on_error; 272 if (pj_memcmp(send_buf, recv_buf, bufsize) != 0) { 273 status=-67; goto on_error; 274 } 275 if (addrlen != sizeof(pj_sockaddr_in)) { 276 status=-68; goto on_error; 277 } 278 if (addr.sin_family != PJ_AF_INET) { 279 status=-69; goto on_error; 273 280 } 274 281 … … 296 303 297 304 on_error: 298 if (status != 0) {299 char errbuf[128];300 PJ_LOG(1, (THIS_FILE,301 "...compliance test error: status=%d, os_err=%d (%s)",302 status, pj_get_netos_error(),303 pj_strerror(pj_get_netos_error(), errbuf, sizeof(errbuf))));304 }305 305 if (ssock) 306 306 pj_sock_close(ssock); … … 432 432 433 433 // Bind server socket. 434 memset(&addr, 0, sizeof(addr));434 pj_memset(&addr, 0, sizeof(addr)); 435 435 addr.sin_family = PJ_AF_INET; 436 436 addr.sin_port = pj_htons(PORT); … … 453 453 inactive_read_op = (pj_ioqueue_op_key_t*)pj_pool_alloc(pool, 454 454 inactive_sock_count*sizeof(pj_ioqueue_op_key_t)); 455 memset(&addr, 0, sizeof(addr));455 pj_memset(&addr, 0, sizeof(addr)); 456 456 addr.sin_family = PJ_AF_INET; 457 457 for (i=0; i<inactive_sock_count; ++i) { … … 480 480 bytes = bufsize; 481 481 rc = pj_ioqueue_recv(key, &inactive_read_op[i], recv_buf, &bytes, 0); 482 if ( rc < 0 &&rc != PJ_EPENDING) {482 if (rc != PJ_EPENDING) { 483 483 pj_sock_close(inactive_sock[i]); 484 484 inactive_sock[i] = PJ_INVALID_SOCKET; … … 520 520 bytes = bufsize; 521 521 rc = pj_ioqueue_recv(skey, &read_op, recv_buf, &bytes, 0); 522 if (rc < 0 && rc!= PJ_EPENDING) {522 if (rc != PJ_EPENDING) { 523 523 app_perror("...error: pj_ioqueue_read()", rc); 524 524 break; … … 531 531 if (rc != PJ_SUCCESS && rc != PJ_EPENDING) { 532 532 app_perror("...error: pj_ioqueue_write()", bytes); 533 rc = -1;534 533 break; 535 534 } … … 549 548 t_elapsed.u64 += (t2.u64 - t1.u64); 550 549 551 if (rc < 0) 550 if (rc < 0) { 551 app_perror(" error: pj_ioqueue_poll", -rc); 552 552 break; 553 } 553 554 554 555 // Compare recv buffer with send buffer. 555 556 if (callback_read_size != bufsize || 556 memcmp(send_buf, recv_buf, bufsize))557 pj_memcmp(send_buf, recv_buf, bufsize)) 557 558 { 558 rc = -1; 559 rc = -10; 560 PJ_LOG(3,(THIS_FILE, " error: size/buffer mismatch")); 559 561 break; 560 562 } … … 581 583 582 584 } else { 583 PJ_LOG(2, (THIS_FILE, "...ERROR (buf:%d, fds:%d)",584 bufsize, inactive_sock_count+2));585 PJ_LOG(2, (THIS_FILE, "...ERROR rc=%d (buf:%d, fds:%d)", 586 rc, bufsize, inactive_sock_count+2)); 585 587 } 586 588 … … 593 595 pj_ioqueue_destroy(ioque); 594 596 pj_pool_release( pool); 595 return 0;597 return rc; 596 598 597 599 on_error: … … 639 641 640 642 for (bufsize=BUF_MIN_SIZE; bufsize <= BUF_MAX_SIZE; bufsize *= 2) { 641 if ( bench_test(bufsize, SOCK_INACTIVE_MIN))642 return -1;643 if ((status=bench_test(bufsize, SOCK_INACTIVE_MIN)) != 0) 644 return status; 643 645 } 644 646 bufsize = 512; … … 648 650 { 649 651 //PJ_LOG(3,(THIS_FILE, "...testing with %d fds", sock_count)); 650 if ( bench_test(bufsize, sock_count-2))651 return -1;652 if ((status=bench_test(bufsize, sock_count-2)) != 0) 653 return status; 652 654 } 653 655 return 0;
Note: See TracChangeset
for help on using the changeset viewer.