From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.user Subject: Re: wayland client in Guile without libwayland-client Date: Fri, 18 Nov 2022 14:58:02 -0800 Message-ID: References: <5f21001f-00cf-6636-5ea4-ed2b97263b0b@telenet.be> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6420"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 To: Maxime Devos , Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri Nov 18 23:58:59 2022 Return-path: Envelope-to: guile-user@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 1owAJz-0001E2-7x for guile-user@m.gmane-mx.org; Fri, 18 Nov 2022 23:58:55 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1owAJG-0005x0-Ky; Fri, 18 Nov 2022 17:58:11 -0500 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 1owAJE-0005wW-KI for guile-user@gnu.org; Fri, 18 Nov 2022 17:58:08 -0500 Original-Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1owAJC-0007Vn-Hu for guile-user@gnu.org; Fri, 18 Nov 2022 17:58:08 -0500 Original-Received: by mail-pf1-x42b.google.com with SMTP id c203so6207901pfc.11 for ; Fri, 18 Nov 2022 14:58:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=QHzULba29/6U08G0wwSDPscvJAFqt7mn+x0G4IYU9FM=; b=fpZzFnk3aEjg4Ke9+atjxNyP8HMECl0zsVOl29B/ZZUKbybrhzM0LDaLDkaW9UYgls vSEzDubUMRAKl9I3US+h+caUoptKGpkUc9n2Px5PwCiI1bMaOQ7Y0z2mcSLjE6reNHTj CMT4OAVqYaEGOE2wAIXWEridXaXb6N9dsOJovJx+gLhx2UU/2HLtYYdU3aIHfOyOw0Vb nE7r8iL1fp/Utxb1pG2y3FKkO4hsK5qGqUjpLbBrZy1oU3OVgq+9WvztWAkawl/hDA5L I1kaTKXDSz9ZbDmrc8QIKsCCw5oHeIBhoNEfQA0qUrvMNYQ8QeQ09zex6t4dTz9uuxeT ukwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=QHzULba29/6U08G0wwSDPscvJAFqt7mn+x0G4IYU9FM=; b=0I2ey5sOrzlw0Sifl6sVWHDJPXZH2D9Mlr6HifhUOv2A3s0Ys/qq04fwFEzvTZKQxG o8ZT62SnU0IEHj2gsGHGaZ+1MtWEXCJydWQCaA5FoowibWc2tJqSQNMTxsM5aRlMYctA JIXLjMvEWJcm8dMIJNOFMQnLNoZcrPN3JCA0v/LQmNivHdr0pEtBNWfW1Sk3Qp0gY8M5 KWwX5wp6SARA777sN6SPa1UkCIWGvvw8ShY/wll9uJaOx009QN7zBclrV861l6MFZVsY tnitnHs1XCYgomoDUB0+c5ZWIERZc81+fyuil7/WLoLubULaNYUWyp95ApQKKIvFqi80 FEiw== X-Gm-Message-State: ANoB5pmIxWBkaCTDc0jnRl7zkZO3voU+tz3Bz13A4KQkK5k6CcAaNTe5 sD84XSSgQQZw4cGvRv3Oxoo= X-Google-Smtp-Source: AA0mqf5MPkMi0uyEcEm11t8NRi5cKPftp48AIZPSBS2l55ZIXmHh14BMvpEhF0KIPxid/TcZ0qs/ow== X-Received: by 2002:a05:6a02:117:b0:477:55c:847c with SMTP id bg23-20020a056a02011700b00477055c847cmr8448834pgb.224.1668812284542; Fri, 18 Nov 2022 14:58:04 -0800 (PST) Original-Received: from [192.168.2.158] (64-52-138-37.championbroadband.com. [64.52.138.37]) by smtp.gmail.com with ESMTPSA id k89-20020a17090a3ee200b002005fcd2cb4sm6005464pjc.2.2022.11.18.14.58.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Nov 2022 14:58:04 -0800 (PST) Content-Language: en-US In-Reply-To: <5f21001f-00cf-6636-5ea4-ed2b97263b0b@telenet.be> Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=matt.wette@gmail.com; helo=mail-pf1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:18740 Archived-At: On 11/18/22 2:34 PM, Maxime Devos wrote: > > > On 18-11-2022 17:54, Matt Wette wrote: >> cm-buf is a bytevector of control messages (`man cmsg`).  To deal >> with control messages I have generated these procedures: >> >>    (cmsg-list->bytevector cmsg-list) => bytevector >>    (bytevector->cmsg-list bytevector) => cmsg-list > > I have previously written an implementation for encoding/decoding cmsg > at > , > with a bunch of tests at > (no > bindings for sendmsg, recvmsg!, though). > > To compare, could you share your implementation of > cmsg-list->bytevector and bytevector->cmsg-list?. > > Greetings, > Maxime. OK.  I have not used yet. And I want to mention, because my sendmsg() recvmsg() explanation was not clear, those routines will accept a bytevector or vector of bytevectors for iobuf. Here is the cmsg code.  I have not used it yet, so not really tested. I will check your stuff out. #define CMSG_SZ(cmsg) ((cmsg->cmsg_len) - sizeof(struct cmsghdr)) size_t scm_c_cmsg_len (SCM cmsg) {   SCM bv;   size_t ln;   // SCM_ASSERT (scm_is_vector (cmsg), cmsg, 0, scm_c_cmsg_len);   bv = scm_c_vector_ref (cmsg, 2);   // SCM_ASSERT (scm_is_bytevector (bv), cmsg, 0, scm_c_cmsg_len);   ln = CMSG_LEN (scm_c_bytevector_length (bv));   return ln; } SCM_DEFINE(scm_cmsg_list_to_bytevector, "cmsg-list->bytevector", 1, 0, 0,        (SCM cmsgl),        "control message list to bytevector") #define FUNC_NAME s_scm_cmsg_list_to_bytevector {   SCM ml, cm, bv, cb;   size_t ln;   struct cmsghdr *cmsg;   for (ml = cmsgl, ln = 0; ml != SCM_EOL; ml = SCM_CDR (ml)) {     cm = SCM_CAR (ml);     ln += CMSG_ALIGN (scm_c_cmsg_len (cm));   }   bv = scm_c_make_bytevector (ln);   cmsg = (struct cmsghdr *) SCM_BYTEVECTOR_CONTENTS (bv);   memset(cmsg, 0, ln);   for (ml = cmsgl, ln = 0; ml != SCM_EOL; ml = SCM_CDR (ml)) {     cm = SCM_CAR (ml);     cmsg->cmsg_len = scm_c_cmsg_len (cm);     cmsg->cmsg_level = scm_to_int (scm_c_vector_ref (cm, 0));     cmsg->cmsg_type = scm_to_int (scm_c_vector_ref (cm, 1));     cb = scm_c_vector_ref (cm, 2);     memcpy (CMSG_DATA(cmsg), SCM_BYTEVECTOR_CONTENTS (cb),         scm_c_bytevector_length (cb));     cmsg = (struct cmsghdr *)((unsigned char *) cmsg                   + CMSG_ALIGN (cmsg->cmsg_len));   }   return bv; } #undef FUNC_NAME SCM_DEFINE(scm_bytevector_to_cmsg_list, "bytevector->cmsg-list", 1, 0, 0,        (SCM bv),        "extract cmsg-list from bytevector") #define FUNC_NAME s_scm_bytevector_to_cmsg_list {   SCM res, bv1, ctl;   struct msghdr *mhp;   struct cmsghdr *cmsg;   union { struct msghdr mh; double d; } x;   mhp = &x.mh;   SCM_VALIDATE_BYTEVECTOR (1, bv);   mhp->msg_control = (struct cmsghdr *) SCM_BYTEVECTOR_CONTENTS (bv);   mhp->msg_controllen = SCM_BYTEVECTOR_LENGTH (bv);   res = SCM_EOL;   for (cmsg = CMSG_FIRSTHDR (mhp); cmsg != NULL;        cmsg = CMSG_NXTHDR (mhp, cmsg)) {     ctl = scm_c_make_vector (3, SCM_BOOL_F);     scm_c_vector_set_x (ctl, 0, scm_from_int (cmsg->cmsg_level));     scm_c_vector_set_x (ctl, 1, scm_from_int (cmsg->cmsg_type));     bv1 = scm_c_make_bytevector (CMSG_SZ (cmsg));     memcpy(SCM_BYTEVECTOR_CONTENTS (bv1), CMSG_DATA (cmsg), CMSG_SZ (cmsg));     scm_c_vector_set_x (ctl, 2, bv1);     res = scm_cons(ctl, res);   }   res = scm_reverse_x (res, SCM_UNDEFINED);   return res; } #undef FUNC_NAME