delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2021/03/23/11:38:10

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C79A8385480E
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1616513886;
bh=I5uyaroIvb3qLwMmNJIQ5+GLDIbdddRVammiOhGFzug=;
h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post:
List-Help:List-Subscribe:From:Reply-To:From;
b=FXITpd1z6rZXdvCzkKiCoPAjNk+QLyMBOQaNf7i7+vEOVaN10jQW14kOS6EDt9+/X
x0BJS2Z3JgUoRqv2Mup1rT08IBJ5y/dZKl+mckiH0OiUd7/fO/ukaTMLbpySm0WLk4
3IRNcGgLd3v6HD/pzMF/snz7Ga94EwOqMR4MOOGE=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4A6B2385BF9E
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:from:to:subject:date:message-id:mime-version
:content-language:thread-index;
bh=GaYAIHBrDA6AaoxnREepfsIBCHTODFJ5RhjT5OC6P6I=;
b=EzDqS/+9FZ5tBc7RbXgyHxsvCBl6A9WdQ2rBB2u2eamVXyg/0CGkhWLAyORRomHt+j
6DE5GaX9hRoYKORiyw5fpWfRm8qAuaipzxYaLvzlaTcQiuf+//TM7mAxNfs/yBg68NZP
nI9vtfIjnH8i8h9YRnoZVk4NfWlTLRjHCVYwaO4xc//h2qmjarEuyryou8qOEZvV8rXd
paxfWjzWAQOvkW78qX3WKgYiXLvN5Db6Yiwb9p39gmMpOLGtDc66/f1UxAhqCA7tNrQE
9wrB7rZGTsbep0ZBY7ehrRR4/Z603l/XIoLFqg3ZAHsNV+RIoTgzcFjrSZCLJZFxYVSQ
oV0Q==
X-Gm-Message-State: AOAM532e6KRiR3b6vCkhQinPP/QRRV1Bz/QZBYtB4jYumzemeQvWlCoP
R6iezRw9eCn/gRAEH2S7Z3KO6oZ8+zkZvg==
X-Google-Smtp-Source: ABdhPJyrABSjUE512Az6uhT8qC66uCnbYZag6nFTzZzvgb93BxfAMdNM68NK1aM5UwE6y1CYsyJc4g==
X-Received: by 2002:a19:cd1:: with SMTP id 200mr2973441lfm.480.1616513873036;
Tue, 23 Mar 2021 08:37:53 -0700 (PDT)
To: <cygwin AT cygwin DOT com>
Subject: AF_UNIX/SOCK_DGRAM is dropping messages
Date: Tue, 23 Mar 2021 16:37:52 +0100
Message-ID: <04cc01d71ffa$7d1e6cf0$775b46d0$@gmail.com>
MIME-Version: 1.0
X-Mailer: Microsoft Outlook 16.0
Thread-Index: Adcf+Ru9MZOaiVQtQ0esx7k4nMjxfA==
X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,
SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Kristian Ivarsson via Cygwin <cygwin AT cygwin DOT com>
Reply-To: sten DOT kristian DOT ivarsson AT gmail DOT com
Sender: "Cygwin" <cygwin-bounces AT cygwin DOT com>

This is a multipart message in MIME format.

------=_NextPart_000_04CD_01D72002.DEE34A20
Content-Type: text/plain;
	charset="utf-8"
Content-Transfer-Encoding: quoted-printable

Hi all

Using AF_UNIX/SOCK_DGRAM with current version (3.2.0) seems to drop =
messages or at least they are not received in the same order they are =
sent

Attached C:ish (with C++ threads though) sample program that essentially =
creates a "client" that writes as much as possible and a "server" that =
consumes as much as possible

It seems like some buffer is filled and then messages are dropped (or at =
least it appears so) (if someone is about to test this, the "sleep" =
might need to be adjusted in order to make this happen)

Hopefully it's just a flaw in our application (and sample), but as far =
as we can see, this should work


Does anyone, perhaps named Ken, have any insightful thoughts about this =
?


Best regards,
Kristian

------=_NextPart_000_04CD_01D72002.DEE34A20
Content-Type: text/plain;
	name="af_unix.cpp"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="af_unix.cpp"

#include <sys/socket.h>
#include <sys/un.h>

#include <unistd.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <thread>
#include <chrono>


// $ g++ --std=3Dgnu++17 af_unix.cpp

const char* const path =3D "address";
const int count =3D 1000;
const int size =3D BUFSIZ * 2;

int client()
{
    const int fd =3D socket( AF_UNIX, SOCK_DGRAM, 0);

    if( fd =3D=3D -1)
    {
        perror( "socket error");
        return -1;
    }

    struct sockaddr_un address{};

    strcpy( address.sun_path, path);
    address.sun_family =3D AF_UNIX;

    char buffer[size] =3D {};

    for( int idx =3D 0; idx < count; ++idx)
    {
        memcpy( buffer, &idx, sizeof idx);

        const ssize_t result =3D sendto( fd, buffer, size, 0, (struct =
sockaddr*)&address, sizeof address);

        if( result =3D=3D -1)
        {
            perror( "sendto error");
            return -1;
        }
    }

    close( fd);
    return 0;
}

int server()
{
    const int fd =3D socket( AF_UNIX, SOCK_DGRAM, 0);

    if( fd =3D=3D -1)
    {
        perror( "socket error");
        return -1;
    }

    struct sockaddr_un address{};

    strcpy( address.sun_path, path);
    address.sun_family =3D AF_UNIX;

    const int result =3D bind( fd, (struct sockaddr*)&address, sizeof =
address);

    if( result =3D=3D -1)
    {
        perror( "bind error");
        return -1;
    }

    return fd;
}

int main( int argc, char* argv[])
{
    const int fd =3D server( );

    if( fd !=3D -1)
    {
        fprintf( stdout, "%d\tnumber of packages\n", count);
        fprintf( stdout, "%d\tbytes per package\n", size);

        std::thread c{ [&](){client( );}};

        std::this_thread::sleep_for( std::chrono::microseconds( 500));
   =20
        char buffer[size] =3D {};

        for( int idx =3D 0; idx < count; ++idx)
        {
            const ssize_t result =3D recv( fd, buffer, size, 0);

            if( result =3D=3D -1)
            {
                perror("recv error");
                c.join();
                unlink( path);
                return -1;
            }

            int index =3D 0;
            memcpy( &index, buffer, sizeof idx);

            if( index !=3D idx)
            {
                fprintf( stderr, "expected %d but got %d\n", idx, =
index);
                c.join();
                unlink( path);
                return -1;
            }
        }

        c.join();
        close( fd);
        unlink( path);
    }

    return 0;
}
------=_NextPart_000_04CD_01D72002.DEE34A20
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

------=_NextPart_000_04CD_01D72002.DEE34A20--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019