Skip to content

Commit

Permalink
fix halfclose bug, See detail cloudwu#1358
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Mar 9, 2021
1 parent 0d9bfcb commit 600a643
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lualib/skynet/socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ function socket.close(id)
if s == nil then
return
end
driver.close(id)
if s.connected then
driver.close(id)
if s.co then
-- reading this socket on another coroutine, so don't shutdown (clear the buffer) immediately
-- wait reading coroutine read the buffer.
Expand Down
7 changes: 4 additions & 3 deletions skynet-src/socket_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ send_socket(struct socket_server *ss, struct request_send * request, struct sock
so.free_func((void *)request->buffer);
return -1;
}
if (send_buffer_empty(s) && type == SOCKET_TYPE_CONNECTED) {
if (send_buffer_empty(s)) {
if (s->protocol == PROTOCOL_TCP) {
append_sendbuffer(ss, s, request); // add to high priority list, even priority == PRIORITY_LOW
} else {
Expand Down Expand Up @@ -1148,8 +1148,9 @@ close_socket(struct socket_server *ss, struct request_close *request, struct soc
int r = shutdown_read ? -1 : SOCKET_CLOSE;
force_close(ss,s,&l,result);
return r;
} else if (!shutdown_read) {
s->closing = true;
}
s->closing = true;
if (!shutdown_read) {
// don't read socket after socket.close()
close_read(ss, s, result);
return SOCKET_CLOSE;
Expand Down

0 comments on commit 600a643

Please sign in to comment.