mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 01:08:27 +00:00
Refactor streams: rename is_* to wait_* for clarity (#2069)
- Replace is_readable() with wait_readable() and is_writable() with wait_writable() in the Stream interface. - Implement a new is_readable() function with semantics that more closely reflect its name. It returns immediately whether data is available for reading, without waiting. - Update call sites of is_writable(), removing redundant checks.
This commit is contained in:
parent
a4b2c61a65
commit
550f728165
3 changed files with 45 additions and 33 deletions
10
test/test.cc
10
test/test.cc
|
@ -156,7 +156,7 @@ TEST_F(UnixSocketTest, abstract) {
|
|||
}
|
||||
#endif
|
||||
|
||||
TEST(SocketStream, is_writable_UNIX) {
|
||||
TEST(SocketStream, wait_writable_UNIX) {
|
||||
int fds[2];
|
||||
ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, fds));
|
||||
|
||||
|
@ -167,17 +167,17 @@ TEST(SocketStream, is_writable_UNIX) {
|
|||
};
|
||||
asSocketStream(fds[0], [&](Stream &s0) {
|
||||
EXPECT_EQ(s0.socket(), fds[0]);
|
||||
EXPECT_TRUE(s0.is_writable());
|
||||
EXPECT_TRUE(s0.wait_writable());
|
||||
|
||||
EXPECT_EQ(0, close(fds[1]));
|
||||
EXPECT_FALSE(s0.is_writable());
|
||||
EXPECT_FALSE(s0.wait_writable());
|
||||
|
||||
return true;
|
||||
});
|
||||
EXPECT_EQ(0, close(fds[0]));
|
||||
}
|
||||
|
||||
TEST(SocketStream, is_writable_INET) {
|
||||
TEST(SocketStream, wait_writable_INET) {
|
||||
sockaddr_in addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
|
@ -212,7 +212,7 @@ TEST(SocketStream, is_writable_INET) {
|
|||
};
|
||||
asSocketStream(disconnected_svr_sock, [&](Stream &ss) {
|
||||
EXPECT_EQ(ss.socket(), disconnected_svr_sock);
|
||||
EXPECT_FALSE(ss.is_writable());
|
||||
EXPECT_FALSE(ss.wait_writable());
|
||||
|
||||
return true;
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue