1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

research st: update test for st.

This commit is contained in:
winlin 2014-11-06 12:50:27 +08:00
parent 0f293802c8
commit f8f18fffa7

View file

@ -147,6 +147,8 @@ void* io_client(void* arg)
return NULL; return NULL;
} }
st_netfd_close(stfd);
return NULL; return NULL;
} }
@ -211,10 +213,59 @@ int io_test()
} }
srs_trace("9. server io completed."); srs_trace("9. server io completed.");
st_netfd_close(stfd);
st_netfd_close(client_stfd);
srs_trace("io test: end"); srs_trace("io test: end");
return 0; return 0;
} }
int pipe_test()
{
srs_trace("===================================================");
srs_trace("pipe test: start");
int fds[2];
if (pipe(fds) < 0) {
srs_trace("pipe failed");
return -1;
}
srs_trace("1. pipe ok, %d=>%d", fds[1], fds[0]);
st_netfd_t fdw;
if ((fdw = st_netfd_open_socket(fds[1])) == NULL) {
srs_trace("st_netfd_open_socket open socket failed.");
return -1;
}
srs_trace("2. open write fd ok");
st_netfd_t fdr;
if ((fdr = st_netfd_open_socket(fds[0])) == NULL) {
srs_trace("st_netfd_open_socket open socket failed.");
return -1;
}
srs_trace("3. open read fd ok");
char buf[1024];
if (st_write(fdw, buf, sizeof(buf), ST_UTIME_NO_TIMEOUT) < 0) {
srs_trace("st_write socket failed.");
return -1;
}
srs_trace("4. write to pipe ok");
if (st_read(fdr, buf, sizeof(buf), ST_UTIME_NO_TIMEOUT) < 0) {
srs_trace("st_read socket failed.");
return -1;
}
srs_trace("5. read from pipe ok");
st_netfd_close(fdw);
st_netfd_close(fdr);
srs_trace("pipe test: end");
return 0;
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
if (st_set_eventsys(ST_EVENTSYS_ALT) < 0) { if (st_set_eventsys(ST_EVENTSYS_ALT) < 0) {
@ -237,6 +288,11 @@ int main(int argc, char** argv)
return -1; return -1;
} }
if (pipe_test() < 0) {
srs_trace("pipe_test failed");
return -1;
}
// cleanup. // cleanup.
st_thread_exit(NULL); st_thread_exit(NULL);