From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id CP/yAKC0bGR0VwEASxT56A (envelope-from ) for ; Tue, 23 May 2023 14:42:08 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id iAcCAKC0bGQ7pwAAG6o9tA (envelope-from ) for ; Tue, 23 May 2023 14:42:08 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A31A02DACE for ; Tue, 23 May 2023 14:42:07 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1RK9-0001iY-Dm; Tue, 23 May 2023 08:41:09 -0400 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 1q1RK6-0001gv-DJ for bug-guix@gnu.org; Tue, 23 May 2023 08:41:06 -0400 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 1q1RK4-0003Vq-2u for bug-guix@gnu.org; Tue, 23 May 2023 08:41:06 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q1RK3-00035l-Vb for bug-guix@gnu.org; Tue, 23 May 2023 08:41:03 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#63516: [PATCH Guile-Netlink 04/11] connection: Add support for suspendable sockets. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Tue, 23 May 2023 12:41:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63516 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 63516@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 63516-submit@debbugs.gnu.org id=B63516.168484562611740 (code B ref 63516); Tue, 23 May 2023 12:41:03 +0000 Received: (at 63516) by debbugs.gnu.org; 23 May 2023 12:40:26 +0000 Received: from localhost ([127.0.0.1]:38535 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q1RJR-00033B-Fc for submit@debbugs.gnu.org; Tue, 23 May 2023 08:40:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44336) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q1RJK-00031l-9F for 63516@debbugs.gnu.org; Tue, 23 May 2023 08:40:18 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1RJF-0003DI-22; Tue, 23 May 2023 08:40:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=5Sf0BlFTZb/+7gIB1vr0wD/T5wQaBY2pRjut+ynAQig=; b=Es9EjUZPL02hEtsqQFOu unb5dQ3Sw8u5Kvva249/EkoUb1lue23xpxVm+//HqV51Fpst841HEGic4Dz7yEkMChX9fH1puOWkY EEdKK9msvGnLQvJC2S7i4SDnAM3XOge+avNjbfnknEjhom/8dhKbubLPvYUfeBOMIThUeGTrEMXdZ 5BUvN1bZ3SGb3yyOLFaQCkkXpwaNqZNlDUntmyqxbI9SVy9+1yVg7XCQj1zopaDe4Mb9DKnT0aIov saBoTnkv3kXK3SLnmRZL0o0N+r7+Rr2enCeFsxBQbGqXd2fhWlDIlGYEEmKYfyQc4VUxO5azuDpaq 8QpGY5fdQ8G6og==; Received: from [193.50.110.247] (helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1RJ9-00081G-GY; Tue, 23 May 2023 08:40:12 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 23 May 2023 14:39:44 +0200 Message-Id: <20230523123951.6225-5-ludo@gnu.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523123951.6225-1-ludo@gnu.org> References: <871qjawqpt.fsf@gnu.org> <20230523123951.6225-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: bug-guix-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Seal: i=1; s=key1; d=yhetil.org; t=1684845727; a=rsa-sha256; cv=none; b=pzFxnhCnK3oSrYW84NwueYfl9JjPDKpRw9akLXvRsXMV6PtiFl3TsquUiOLyFuu+fLSEjh dNL70g1WP0+o8m2mAEYMKTXxNkTakzeSQqcI5nHvUWz91RdqodR6rhoBem0fTddEVN7faN uPNsJ0SIY8bvXOtMVNhL3cF0FX8MNQ2She8+lsmRlXot+/Fm8ZJrqF5T+xSOdf5uw8eyue Rqk3yOrTfROY7wuVOXpm/N1m2ZR/U2C8YYqsII5lgY2AgyoRP2Xb+bEOSHRmMr526xhK9E ajwLKhxEslYDZgxYyjIkC/mI8CY0sem84WLbTUHOjKg6/shzeg+iwPqdChCoDA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=Es9EjUZP; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1684845727; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=5Sf0BlFTZb/+7gIB1vr0wD/T5wQaBY2pRjut+ynAQig=; b=lc7VvNN3KF7oTmlj3LgELxqP4Z0KwHgc7b7HqgWN/Z2moT2gxn1ixbrvse8zH64M6KG2Xx 1HpvvYBqt+J6Bgx71g1m0zl+8ngwRQKJoiAbe+RAX+kBgS574p84RWF4AZ/2INbOFcPdqi csTmfX4+BOh3YELSt1Ds0TWVyHjsGh+xBJSg5M40MGhI4XRBqigbhcQKSYKtVS8Vc5Yd3h I5seHlDDIp8W+12PViFoE8fJECeccQJz0sATzggUASdjdx3CVgnDRpBwYHuuKVRjRo8bw+ lnlIJxc1QCIFWoUiJaDY1A45YYnphjl45vIrJGs7JCkV14Fx1qB+OTJ78ZFhjQ== X-Migadu-Scanner: scn1.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=Es9EjUZP; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.07 X-Spam-Score: -1.07 X-Migadu-Queue-Id: A31A02DACE X-TUID: X80jCXOqkFlk * netlink/connection.scm (syscall->procedure): Add #:waiter. Distinguish first argument and call WAITER upon EWOULDBLOCK or EAGAIN when the first argument is a port. (ffi-sendto, ffi-recvmsg, ffi-bind): Pass #:waiter. (connect, send-msg, receive-msg): Pass SOCK instead of (fileno sock). --- netlink/connection.scm | 45 ++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/netlink/connection.scm b/netlink/connection.scm index f4a5cc6..42f7dbb 100644 --- a/netlink/connection.scm +++ b/netlink/connection.scm @@ -26,6 +26,8 @@ #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) #:use-module (srfi srfi-71) + #:autoload (ice-9 suspendable-ports) (current-read-waiter + current-write-waiter) #:export (connect connect-route close-socket @@ -36,27 +38,40 @@ (define libc (dynamic-link)) -(define (syscall->procedure return-type function - argument-types) +(define* (syscall->procedure return-type function + argument-types + #:key waiter) "Return a procedure that calls FUNCTION, a syscall wrapper from the C library -with the given RETURN-TYPE and ARGUMENT-TYPES." +with the given RETURN-TYPE and ARGUMENT-TYPES. When WAITER is true and the +first argument is a port, call it upon EAGAIN or EWOULDBLOCK." (let ((proc (pointer->procedure return-type (dynamic-func function libc) argument-types #:return-errno? #t))) - (lambda args - (let ((ret errno (apply proc args))) - (when (< ret 0) - (throw 'system-error function "~A" - (list (strerror errno)) (list errno))) - ret)))) + (lambda (first . rest) + (let loop () + (let ((ret errno (apply proc + (if (port? first) (fileno first) first) + rest))) + (if (< ret 0) + (if (and (memv errno (list EAGAIN EWOULDBLOCK)) + (port? first) waiter) + (begin + ((waiter) first) + (loop)) + (throw 'system-error function "~A" + (list (strerror errno)) (list errno))) + ret)))))) (define ffi-sendto - (syscall->procedure int "sendto" (list int '* size_t int '* int))) + (syscall->procedure int "sendto" (list int '* size_t int '* int) + #:waiter (lambda () (current-write-waiter)))) (define ffi-recvmsg - (syscall->procedure int "recvmsg" (list int '* int))) + (syscall->procedure int "recvmsg" (list int '* int) + #:waiter (lambda () (current-read-waiter)))) (define ffi-bind - (syscall->procedure int "bind" (list int '* int))) + (syscall->procedure int "bind" (list int '* int) + #:waiter (lambda () (current-read-waiter)))) ;; define simple functions to open/close sockets (define (open-socket proto) @@ -89,7 +104,7 @@ such as 'bind' cannot handle." (define* (connect proto addr) (let ((sock (open-socket proto))) - (ffi-bind (fileno sock) + (ffi-bind sock (bytevector->pointer addr) 12) sock)) @@ -105,7 +120,7 @@ such as 'bind' cannot handle." (let* ((len (data-size msg)) (bv (make-bytevector len))) (serialize msg 0 bv) - (ffi-sendto (fileno sock) (bytevector->pointer bv) len 0 %null-pointer 0))) + (ffi-sendto sock (bytevector->pointer bv) len 0 %null-pointer 0))) (define* (receive-msg sock #:key (addr (get-addr AF_NETLINK 0 0))) (let* ((len (* 1024 32)) @@ -115,7 +130,7 @@ such as 'bind' cannot handle." iovec 1 %null-pointer 0 0)) - (size (ffi-recvmsg (fileno sock) msghdr 0)) + (size (ffi-recvmsg sock msghdr 0)) (answer (make-bytevector size))) (when (> size (* 1024 32)) (raise (condition (&netlink-answer-too-big-error (size size))))) -- 2.40.1