This test verifies that if an EOF arrives on a socket when there is no pending `recv()` call, the EOF will be correctly received.
| 179 | // This test verifies that if an EOF arrives on a socket when there is no |
| 180 | // pending `recv()` call, the EOF will be correctly received. |
| 181 | TEST_P(NetSocketTest, EOFBeforeRecv) |
| 182 | { |
| 183 | Try<Socket> client = Socket::create(); |
| 184 | ASSERT_SOME(client); |
| 185 | |
| 186 | const string data = "Lorem ipsum dolor sit amet"; |
| 187 | |
| 188 | Try<Socket> server = Socket::create(); |
| 189 | ASSERT_SOME(server); |
| 190 | |
| 191 | Try<Address> server_address = server->bind(inet4::Address::ANY_ANY()); |
| 192 | ASSERT_SOME(server_address); |
| 193 | |
| 194 | ASSERT_SOME(server->listen(1)); |
| 195 | Future<Socket> server_accept = server->accept(); |
| 196 | |
| 197 | // Connect to the IP from the libprocess library, but use the port |
| 198 | // from the `bind` call above. The libprocess IP will always report |
| 199 | // a locally bindable IP, meaning it will also work for the server |
| 200 | // socket above. |
| 201 | // |
| 202 | // NOTE: We do not use the server socket's address directly because |
| 203 | // this contains a `0.0.0.0` IP. According to RFC1122, this is an |
| 204 | // invalid address, except when used to resolve a host's address |
| 205 | // for the first time. |
| 206 | // See: https://tools.ietf.org/html/rfc1122#section-3.2.1.3 |
| 207 | AWAIT_READY(connectSocket( |
| 208 | *client, |
| 209 | Address(process::address().ip, server_address->port))); |
| 210 | |
| 211 | AWAIT_READY(server_accept); |
| 212 | |
| 213 | Socket server_socket = server_accept.get(); |
| 214 | |
| 215 | AWAIT_READY(server_socket.send(data)); |
| 216 | AWAIT_EXPECT_EQ(data, client->recv(data.size())); |
| 217 | |
| 218 | // Shutdown the socket before the final `recv()` is called. |
| 219 | server_socket.shutdown(Socket::Shutdown::READ_WRITE); |
| 220 | |
| 221 | AWAIT_EXPECT_EQ(string(), client->recv()); |
| 222 | } |
| 223 | |
| 224 | |
| 225 | // This test verifies that if an EOF arrives on a socket when there is a |
nothing calls this directly
no test coverage detected