From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 06C202B3CD for ; Tue, 9 Apr 2019 14:12:16 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0ozNyE_pGo7G for ; Tue, 9 Apr 2019 14:12:15 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 8EF5129A3B for ; Tue, 9 Apr 2019 14:12:15 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH 2/5] test: on close of swim fake fd send its packets, not drop Date: Tue, 9 Apr 2019 21:12:09 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: kostja@tarantool.org The packets originator has already got an OK status and expects these messages sent even if the originator is closed right after that. This commit does the TCP-way and sends all the pending messages before actually closing the fake fd. Part of #3234 --- test/unit/swim_test_transport.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/unit/swim_test_transport.c b/test/unit/swim_test_transport.c index e563185ee..f30000135 100644 --- a/test/unit/swim_test_transport.c +++ b/test/unit/swim_test_transport.c @@ -135,6 +135,10 @@ swim_fd_open(struct swim_fd *fd) return 0; } +/** Send one packet to destination's recv queue. */ +static inline void +swim_fd_send_packet(struct swim_fd *fd); + /** Close a fake file descriptor. */ static inline void swim_fd_close(struct swim_fd *fd) @@ -144,8 +148,8 @@ swim_fd_close(struct swim_fd *fd) struct swim_test_packet *i, *tmp; rlist_foreach_entry_safe(i, &fd->recv_queue, in_queue, tmp) swim_test_packet_delete(i); - rlist_foreach_entry_safe(i, &fd->send_queue, in_queue, tmp) - swim_test_packet_delete(i); + while (! rlist_empty(&fd->send_queue)) + swim_fd_send_packet(fd); rlist_del_entry(fd, in_active); fd->is_opened = false; } @@ -285,12 +289,10 @@ swim_test_is_drop(double rate) return ((double) rand() / RAND_MAX) * 100 < rate; } -/** Send one packet to destination's recv queue. */ static inline void swim_fd_send_packet(struct swim_fd *fd) { - if (rlist_empty(&fd->send_queue)) - return; + assert(! rlist_empty(&fd->send_queue)); struct swim_test_packet *p = rlist_shift_entry(&fd->send_queue, struct swim_test_packet, in_queue); @@ -311,7 +313,8 @@ swim_transport_do_loop_step(struct ev_loop *loop) * order. So this reverse + libev reverse = normal order. */ rlist_foreach_entry_reverse(fd, &swim_fd_active, in_active) { - swim_fd_send_packet(fd); + if (! rlist_empty(&fd->send_queue)) + swim_fd_send_packet(fd); ev_feed_fd_event(loop, fd->evfd, EV_WRITE); } rlist_foreach_entry_reverse(fd, &swim_fd_active, in_active) { -- 2.17.2 (Apple Git-113)