From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.bugs Subject: bug#62990: 30.0.50; UDP server closes connection upon receiving an empty packet Date: Wed, 26 Apr 2023 11:14:42 +0200 Message-ID: <87354nt37h.fsf@gmail.com> References: <87wn21br45.fsf@gmail.com> <87ttx49yg0.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9912"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 62990@debbugs.gnu.org To: Vasilij Schneidermann Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 26 11:15:21 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1prbFB-0002M0-48 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 26 Apr 2023 11:15:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prbEt-0007Jx-3j; Wed, 26 Apr 2023 05:15:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prbEs-0007Jp-6w for bug-gnu-emacs@gnu.org; Wed, 26 Apr 2023 05:15:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1prbEr-0004R1-U3 for bug-gnu-emacs@gnu.org; Wed, 26 Apr 2023 05:15:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1prbEr-0007m7-O2 for bug-gnu-emacs@gnu.org; Wed, 26 Apr 2023 05:15:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Robert Pluim Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 26 Apr 2023 09:15:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62990 X-GNU-PR-Package: emacs Original-Received: via spool by 62990-submit@debbugs.gnu.org id=B62990.168250049229848 (code B ref 62990); Wed, 26 Apr 2023 09:15:01 +0000 Original-Received: (at 62990) by debbugs.gnu.org; 26 Apr 2023 09:14:52 +0000 Original-Received: from localhost ([127.0.0.1]:54260 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prbEh-0007lL-Nx for submit@debbugs.gnu.org; Wed, 26 Apr 2023 05:14:52 -0400 Original-Received: from mail-wm1-f46.google.com ([209.85.128.46]:51239) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prbEg-0007l4-9k for 62990@debbugs.gnu.org; Wed, 26 Apr 2023 05:14:51 -0400 Original-Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-3f19a80a330so29087975e9.2 for <62990@debbugs.gnu.org>; Wed, 26 Apr 2023 02:14:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682500484; x=1685092484; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=PLtNr8NYo6ETpgMsLibrtqykpTcZybHRGShB0xWXEmE=; b=NT4uV/VSl8W3fh/KKDuoYNhsGuxA89FqqMGNRzZv+H9bPdci++m9oP0f78QkU62eCs geQtT2REMKcuM9w8APYeQ34II6uukiuvjGUR4Q0MNg6TQanyGOlFO5m6gUqfQi46rhyG 8nhNFknou/WKWitRUqV/lVBvseqaoeBlRX84vJwx7FlGc8eZSPGKIV/eUzxvynBjRyDK BbR7KTr4/rn0bQB5vgOKqE5Y/bdsN7dofxBAKcnAze6pvB7ruKBtBedAAfF2p1sQby5V Pi9qDz76hZ3bLvFUpGa/XFJIMG4umhjFG40ubXO6kQeS/wRuwDlipI2AmeUrEkXvw+8e a2vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682500484; x=1685092484; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PLtNr8NYo6ETpgMsLibrtqykpTcZybHRGShB0xWXEmE=; b=fXpX3ZceTRE7wJLPiRfrw6VsbxTqMIvJO0MN9ZXXzFE2F5obsxofR675Qs1/V/tCcj qZALyfX765hXzhFvm2bA1z+N38eZFXhvdvO7cFUPpBVfoqjOsrv9ains/NJhTcHxNuR1 nznE65H2ZyW3+ThwbVjh2dWLMuvTOPhy42UzWvU0J9XhLrMXVSqdzPlU7vk1Clihh8BK IjPpH0kR6sVuCM4Sg8+AvdFxOSZCEkf4yqkooL/yyQouP3VHXVifpOzKCVV/VvDGUlnT UYGlqrQwRhSsXSYyEoOI+570R2uk4JT02bbaegFxcjuvTARdwZs33rJA5gfqWNtCwjcf mVRQ== X-Gm-Message-State: AAQBX9fBLScsShbtjlnjs6QjCo+fD9kMY+YQySrg4I38y0onrf4ORt+y oqVxS8YQKqOODUIZs5hxdSB+AcWx0n8= X-Google-Smtp-Source: AKy350YFpZ5MPJB8d0rzXntgs4QCE8CKVO5zKTJcAA4By6uXv4sjZ6IDAq5oKLuaF0devCyhZgoTyA== X-Received: by 2002:a05:600c:2212:b0:3f1:6fea:790a with SMTP id z18-20020a05600c221200b003f16fea790amr11991835wml.30.1682500483691; Wed, 26 Apr 2023 02:14:43 -0700 (PDT) Original-Received: from rltb ([82.66.8.55]) by smtp.gmail.com with ESMTPSA id iz14-20020a05600c554e00b003f175954e71sm20786301wmb.32.2023.04.26.02.14.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 02:14:42 -0700 (PDT) In-Reply-To: <87ttx49yg0.fsf@gmail.com> (Robert Pluim's message of "Tue, 25 Apr 2023 10:07:59 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:260655 Archived-At: --=-=-= Content-Type: text/plain So allowing emacs to send 0-length UDP packets turned out to be not too hard. Patch for both below. Eli, is this OK for master? It does change 2 behaviours: 1. Receiving a 0-length UDP packet will no longer cause an error 2. Calling (process-send-string proc "") now actually sends out a packet for a UDP process (an empty one). Robert -- --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Allow-zero-length-UDP-send-receive.patch >From 4bb6dec25ad3c3b548e18e82b2129b53c1ee1b69 Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Tue, 25 Apr 2023 12:48:26 +0200 Subject: [PATCH] Allow zero-length UDP send/receive To: emacs-devel@gnu.org * src/process.c (wait_reading_process_output) [DATAGRAM_SOCKETS]: Don't close the network connection if we receive a zero-length UDP packet. (send_process) [DATAGRAM_SOCKETS]: Allow sending a zero-length UDP packet. * etc/NEWS: Announce the change. --- etc/NEWS | 8 ++++++++ src/process.c | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index ea233865f5a..4cc02d76b8f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -82,6 +82,14 @@ The ':keepalive-idle', ':keepalive-interval', and ':keepalive-count' options can now be used to set the various timers and counters used when TCP keepalive is enabled for a connection. +** Emacs can now send zero-length UDP packets. +Previously 'process-send-string' of an empty string to a UDP process +did nothing, now it sends out a zero-length UDP packet. + +** Emacs can now receive zero-length UDP packets. +Previously, receiving a zero-length UDP packet closed the receiving +network process. They are now silently ignored. + * Editing Changes in Emacs 30.1 diff --git a/src/process.c b/src/process.c index 8e467ff7511..e3233f5ad89 100644 --- a/src/process.c +++ b/src/process.c @@ -5947,6 +5947,11 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, #endif /* HAVE_PTYS */ /* If we can detect process termination, don't consider the process gone just because its pipe is closed. */ +#ifdef DATAGRAM_SOCKETS + /* A zero byte read on a UDP socket is not an error. */ + else if (nread == 0 && DATAGRAM_CHAN_P (channel)) + got_some_output = 1; +#endif else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc) && !PIPECONN_P (proc)) ; @@ -6616,9 +6621,16 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, cur_buf = buf; cur_object = object; } - - while (cur_len > 0) + /* UDP allows zero-length writes. */ + bool zero_length = false; +#ifdef DATAGRAM_SOCKETS + if (cur_len == 0 && NETCONN_P (proc) && 0 <= p->outfd + && DATAGRAM_CHAN_P (p->outfd)) + zero_length = true; +#endif + while (cur_len > 0 || zero_length) { + zero_length = false; /* Send this batch, using one or more write calls. */ ptrdiff_t written = 0; int outfd = p->outfd; -- 2.38.1.420.g319605f8f0 --=-=-=--