From f07267c602f91c7c1ec207e1168b7a3a4b05678f Mon Sep 17 00:00:00 2001
From: Hamish Morrison <hamishm53@gmail.com>
Date: Sat, 30 May 2015 16:52:21 +0100
Subject: [PATCH 2/2] tcp: wait for connection to complete before notifying
B_SELECT_WRITE
---
.../kernel/network/protocols/tcp/TCPEndpoint.cpp | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp
index dc3a4a1..ce4769b 100644
a
|
b
|
segment_in_sequence(const tcp_segment_header& segment, int size,
|
320 | 320 | static inline bool |
321 | 321 | is_writable(tcp_state state) |
322 | 322 | { |
323 | | return state == SYNCHRONIZE_SENT || state == SYNCHRONIZE_RECEIVED |
324 | | || state == ESTABLISHED || state == FINISH_RECEIVED; |
| 323 | return state == ESTABLISHED || state == FINISH_RECEIVED; |
| 324 | } |
| 325 | |
| 326 | |
| 327 | static inline bool |
| 328 | is_establishing(tcp_state state) |
| 329 | { |
| 330 | return state == SYNCHRONIZE_SENT || state == SYNCHRONIZE_RECEIVED; |
325 | 331 | } |
326 | 332 | |
327 | 333 | |
… |
… |
TCPEndpoint::SendData(net_buffer *buffer)
|
786 | 792 | return ENOTCONN; |
787 | 793 | if (fState == LISTEN) |
788 | 794 | return EDESTADDRREQ; |
789 | | if (!is_writable(fState)) { |
| 795 | if (!is_writable(fState) && !is_establishing(fState)) { |
790 | 796 | // we only send signals when called from userland |
791 | 797 | if (gStackModule->is_syscall()) |
792 | 798 | send_signal(find_thread(NULL), SIGPIPE); |
… |
… |
TCPEndpoint::SendData(net_buffer *buffer)
|
812 | 818 | return posix_error(status); |
813 | 819 | } |
814 | 820 | |
815 | | if (!is_writable(fState)) { |
| 821 | if (!is_writable(fState) && !is_establishing(fState)) { |
816 | 822 | // we only send signals when called from userland |
817 | 823 | if (gStackModule->is_syscall()) |
818 | 824 | send_signal(find_thread(NULL), SIGPIPE); |
… |
… |
TCPEndpoint::SendAvailable()
|
873 | 879 | |
874 | 880 | if (is_writable(fState)) |
875 | 881 | available = fSendQueue.Free(); |
| 882 | else if (is_establishing(fState)) |
| 883 | available = 0; |
876 | 884 | else |
877 | 885 | available = EPIPE; |
878 | 886 | |
… |
… |
TCPEndpoint::_MarkEstablished()
|
1182 | 1190 | } |
1183 | 1191 | |
1184 | 1192 | fSendList.Signal(); |
| 1193 | gSocketModule->notify(socket, B_SELECT_WRITE, fSendQueue.Free()); |
1185 | 1194 | } |
1186 | 1195 | |
1187 | 1196 | |
… |
… |
TCPEndpoint::_Acknowledged(tcp_segment_header& segment)
|
2185 | 2194 | if (is_writable(fState)) { |
2186 | 2195 | // notify threads waiting on the socket to become writable again |
2187 | 2196 | fSendList.Signal(); |
2188 | | gSocketModule->notify(socket, B_SELECT_WRITE, fSendQueue.Used()); |
| 2197 | gSocketModule->notify(socket, B_SELECT_WRITE, fSendQueue.Free()); |
2189 | 2198 | } |
2190 | 2199 | |
2191 | 2200 | if (fCongestionWindow < fSlowStartThreshold) |