winlin

research st: update test for st.

@@ -147,6 +147,8 @@ void* io_client(void* arg) @@ -147,6 +147,8 @@ void* io_client(void* arg)
147 return NULL; 147 return NULL;
148 } 148 }
149 149
  150 + st_netfd_close(stfd);
  151 +
150 return NULL; 152 return NULL;
151 } 153 }
152 154
@@ -211,10 +213,59 @@ int io_test() @@ -211,10 +213,59 @@ int io_test()
211 } 213 }
212 srs_trace("9. server io completed."); 214 srs_trace("9. server io completed.");
213 215
  216 + st_netfd_close(stfd);
  217 + st_netfd_close(client_stfd);
  218 +
214 srs_trace("io test: end"); 219 srs_trace("io test: end");
215 return 0; 220 return 0;
216 } 221 }
217 222
  223 +int pipe_test()
  224 +{
  225 + srs_trace("===================================================");
  226 + srs_trace("pipe test: start");
  227 +
  228 + int fds[2];
  229 + if (pipe(fds) < 0) {
  230 + srs_trace("pipe failed");
  231 + return -1;
  232 + }
  233 + srs_trace("1. pipe ok, %d=>%d", fds[1], fds[0]);
  234 +
  235 + st_netfd_t fdw;
  236 + if ((fdw = st_netfd_open_socket(fds[1])) == NULL) {
  237 + srs_trace("st_netfd_open_socket open socket failed.");
  238 + return -1;
  239 + }
  240 + srs_trace("2. open write fd ok");
  241 +
  242 + st_netfd_t fdr;
  243 + if ((fdr = st_netfd_open_socket(fds[0])) == NULL) {
  244 + srs_trace("st_netfd_open_socket open socket failed.");
  245 + return -1;
  246 + }
  247 + srs_trace("3. open read fd ok");
  248 +
  249 + char buf[1024];
  250 + if (st_write(fdw, buf, sizeof(buf), ST_UTIME_NO_TIMEOUT) < 0) {
  251 + srs_trace("st_write socket failed.");
  252 + return -1;
  253 + }
  254 + srs_trace("4. write to pipe ok");
  255 +
  256 + if (st_read(fdr, buf, sizeof(buf), ST_UTIME_NO_TIMEOUT) < 0) {
  257 + srs_trace("st_read socket failed.");
  258 + return -1;
  259 + }
  260 + srs_trace("5. read from pipe ok");
  261 +
  262 + st_netfd_close(fdw);
  263 + st_netfd_close(fdr);
  264 +
  265 + srs_trace("pipe test: end");
  266 + return 0;
  267 +}
  268 +
218 int main(int argc, char** argv) 269 int main(int argc, char** argv)
219 { 270 {
220 if (st_set_eventsys(ST_EVENTSYS_ALT) < 0) { 271 if (st_set_eventsys(ST_EVENTSYS_ALT) < 0) {
@@ -237,6 +288,11 @@ int main(int argc, char** argv) @@ -237,6 +288,11 @@ int main(int argc, char** argv)
237 return -1; 288 return -1;
238 } 289 }
239 290
  291 + if (pipe_test() < 0) {
  292 + srs_trace("pipe_test failed");
  293 + return -1;
  294 + }
  295 +
240 // cleanup. 296 // cleanup.
241 st_thread_exit(NULL); 297 st_thread_exit(NULL);
242 298