Changeset 3257 for pjproject/trunk
- Timestamp:
- Aug 6, 2010 8:40:55 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/src/pjlib-util-test/http_client.c
r3147 r3257 65 65 { 66 66 struct server_t *srv = (struct server_t*)p; 67 char *pkt = (char*)pj_pool_alloc(pool, srv->buf_size); 67 68 pj_sock_t newsock; 68 69 69 70 while (!thread_quit) { 70 char *pkt = (char*)pj_pool_alloc(pool, srv->buf_size);71 71 pj_ssize_t pkt_len; 72 72 int rc; 73 73 pj_fd_set_t rset; 74 pj_time_val timeout = {0, 100}; 75 76 rc = pj_sock_accept(srv->sock, &newsock, NULL, NULL); 77 if (rc != 0) 78 continue; 79 80 PJ_FD_ZERO(&rset); 81 PJ_FD_SET(newsock, &rset); 82 rc = pj_sock_select(newsock+1, &rset, NULL, NULL, &timeout); 83 if (rc != 1) 84 continue; 85 86 pkt_len = srv->buf_size; 87 do { 88 rc = pj_sock_recv(newsock, pkt, &pkt_len, 0); 89 if (rc != 0) { 90 app_perror("Server error receiving packet", rc); 74 pj_time_val timeout = {0, 500}; 75 76 while (!thread_quit) { 77 PJ_FD_ZERO(&rset); 78 PJ_FD_SET(srv->sock, &rset); 79 rc = pj_sock_select(srv->sock+1, &rset, NULL, NULL, &timeout); 80 if (rc != 1) { 81 continue; 82 } 83 84 rc = pj_sock_accept(srv->sock, &newsock, NULL, NULL); 85 if (rc == PJ_SUCCESS) { 86 break; 87 } 88 } 89 90 if (thread_quit) 91 break; 92 93 while (!thread_quit) { 94 PJ_FD_ZERO(&rset); 95 PJ_FD_SET(newsock, &rset); 96 rc = pj_sock_select(newsock+1, &rset, NULL, NULL, &timeout); 97 if (rc != 1) { 98 PJ_LOG(3,("http test", "client timeout")); 91 99 continue; 92 100 } 93 rc = pj_sock_select(newsock+1, &rset, NULL, NULL, &timeout); 94 if (rc < 1) 101 102 pkt_len = srv->buf_size; 103 rc = pj_sock_recv(newsock, pkt, &pkt_len, 0); 104 if (rc == PJ_SUCCESS) { 95 105 break; 96 } while(1); 106 } 107 } 108 109 if (thread_quit) 110 break; 97 111 98 112 /* Simulate network RTT */ … … 111 125 pj_ansi_sprintf(pkt + pj_ansi_strlen(pkt), "\r\n"); 112 126 pkt_len = pj_ansi_strlen(pkt); 113 pj_sock_send(newsock, pkt, &pkt_len, 0); 127 rc = pj_sock_send(newsock, pkt, &pkt_len, 0); 128 if (rc != PJ_SUCCESS) { 129 pj_sock_close(newsock); 130 continue; 131 } 114 132 while (send_size < srv->data_size) { 115 133 pkt_len = srv->data_size - send_size; … … 120 138 pj_ansi_sprintf(pkt, "\nPacket: %d", ++ctr); 121 139 pkt[pj_ansi_strlen(pkt)] = '\n'; 122 pj_sock_send(newsock, pkt, &pkt_len, 0); 140 rc = pj_sock_send(newsock, pkt, &pkt_len, 0); 141 if (rc != PJ_SUCCESS) 142 break; 123 143 } 124 144 pj_sock_close(newsock); … … 208 228 209 229 if (test_cancel) { 230 /* Need to delay closing the client socket here, otherwise the 231 * server will get SIGPIPE when sending response. 232 */ 233 pj_thread_sleep(100); 210 234 pj_http_req_cancel(hreq, PJ_TRUE); 211 235 test_cancel = PJ_FALSE; … … 356 380 #ifdef USE_LOCAL_SERVER 357 381 thread_quit = PJ_TRUE; 382 pj_thread_join(g_server.thread); 358 383 pj_sock_close(g_server.sock); 359 384 #endif … … 491 516 #ifdef USE_LOCAL_SERVER 492 517 thread_quit = PJ_TRUE; 518 pj_thread_join(g_server.thread); 493 519 pj_sock_close(g_server.sock); 494 520 #endif … … 593 619 #ifdef USE_LOCAL_SERVER 594 620 thread_quit = PJ_TRUE; 621 pj_thread_join(g_server.thread); 595 622 pj_sock_close(g_server.sock); 596 623 #endif … … 693 720 #ifdef USE_LOCAL_SERVER 694 721 thread_quit = PJ_TRUE; 722 pj_thread_join(g_server.thread); 695 723 pj_sock_close(g_server.sock); 696 724 #endif … … 783 811 #ifdef USE_LOCAL_SERVER 784 812 thread_quit = PJ_TRUE; 813 pj_thread_join(g_server.thread); 785 814 pj_sock_close(g_server.sock); 786 815 #endif
Note: See TracChangeset
for help on using the changeset viewer.