mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Improve test coverage for service TCP/UDP.
This commit is contained in:
parent
265b70863c
commit
02c1bd0946
2 changed files with 8 additions and 5 deletions
|
@ -263,27 +263,22 @@ srs_error_t do_srs_udp_listen(int fd, addrinfo* r, srs_netfd_t* pfd)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
if ((err = srs_fd_closeexec(fd)) != srs_success) {
|
if ((err = srs_fd_closeexec(fd)) != srs_success) {
|
||||||
::close(fd);
|
|
||||||
return srs_error_wrap(err, "set closeexec");
|
return srs_error_wrap(err, "set closeexec");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = srs_fd_reuseaddr(fd)) != srs_success) {
|
if ((err = srs_fd_reuseaddr(fd)) != srs_success) {
|
||||||
::close(fd);
|
|
||||||
return srs_error_wrap(err, "set reuseaddr");
|
return srs_error_wrap(err, "set reuseaddr");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = srs_fd_reuseport(fd)) != srs_success) {
|
if ((err = srs_fd_reuseport(fd)) != srs_success) {
|
||||||
::close(fd);
|
|
||||||
return srs_error_wrap(err, "set reuseport");
|
return srs_error_wrap(err, "set reuseport");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bind(fd, r->ai_addr, r->ai_addrlen) == -1) {
|
if (bind(fd, r->ai_addr, r->ai_addrlen) == -1) {
|
||||||
::close(fd);
|
|
||||||
return srs_error_new(ERROR_SOCKET_BIND, "bind");
|
return srs_error_new(ERROR_SOCKET_BIND, "bind");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*pfd = srs_netfd_open_socket(fd)) == NULL){
|
if ((*pfd = srs_netfd_open_socket(fd)) == NULL){
|
||||||
::close(fd);
|
|
||||||
return srs_error_new(ERROR_ST_OPEN_SOCKET, "st open");
|
return srs_error_new(ERROR_ST_OPEN_SOCKET, "st open");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -914,5 +914,13 @@ VOID TEST(TCPServerTest, TCPClientServer)
|
||||||
HELPER_ASSERT_SUCCESS(c.read_fully(buf, 5, NULL));
|
HELPER_ASSERT_SUCCESS(c.read_fully(buf, 5, NULL));
|
||||||
EXPECT_STREQ("Hello", buf);
|
EXPECT_STREQ("Hello", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
HELPER_ASSERT_SUCCESS(c.write((void*)"Hello", 5, NULL));
|
||||||
|
|
||||||
|
char buf[6]; HELPER_ARRAY_INIT(buf, 6, 0);
|
||||||
|
HELPER_ASSERT_SUCCESS(srs_read(c.stfd, buf, 5, NULL));
|
||||||
|
EXPECT_STREQ("Hello", buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue