Skip to content

Commit 948f230

Browse files
posix: Fix TCP posix hanging when data and FIN is recv right after eachother resulting in os block not getting time
Co-authored-by: Martin Nordsletten <mnordsletten@gmail.com>
1 parent b94c9f7 commit 948f230

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

api/net/tcp/connection_states.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,15 @@ class Connection::LastAck : public State {
352352
*/
353353
virtual Result handle(Connection&, Packet_view& in) override;
354354

355-
inline virtual std::string to_string() const override {
355+
std::string to_string() const override {
356356
return "LAST-ACK";
357357
};
358358

359-
inline virtual bool is_closing() const override {
359+
bool is_closing() const override {
360+
return true;
361+
}
362+
363+
bool is_closed() const override {
360364
return true;
361365
}
362366

src/posix/tcp_fd.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,10 @@ ssize_t TCP_FD_Conn::recv(void* dest, size_t len, int)
311311
bytes = buffer->size();
312312
});
313313

314-
// BLOCK HERE
315-
while (!done || !conn->is_readable()) {
314+
// BLOCK HERE:
315+
// 1. if we havent read the data we asked for
316+
// 2. or we aren't readable but not closed (not 100% sure here hehe..)
317+
while (!done || (!conn->is_readable() and !conn->is_closed())) {
316318
OS::block();
317319
}
318320
// restore

test/posix/integration/tcp/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def TCP_connect():
5050
sock.connect((HOST, PORT))
5151
MESSAGE = "POSIX is for hipsters"
5252
sock.send(MESSAGE)
53+
sock.close()
5354

5455
def TCP_recv(trigger_line):
5556
server.listen(1)

0 commit comments

Comments
 (0)