public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: <sten.kristian.ivarsson@gmail.com>
To: <cygwin@cygwin.com>
Subject: AF_UNIX/SOCK_DGRAM is dropping messages
Date: Tue, 23 Mar 2021 16:37:52 +0100	[thread overview]
Message-ID: <04cc01d71ffa$7d1e6cf0$775b46d0$@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 744 bytes --]

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

[-- Attachment #2: af_unix.cpp --]
[-- Type: text/plain, Size: 2538 bytes --]

#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=gnu++17 af_unix.cpp

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

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

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

    struct sockaddr_un address{};

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

    char buffer[size] = {};

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

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

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

    close( fd);
    return 0;
}

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

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

    struct sockaddr_un address{};

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

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

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

    return fd;
}

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

    if( fd != -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));
    
        char buffer[size] = {};

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

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

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

            if( index != 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;
}

             reply	other threads:[~2021-03-23 15:37 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23 15:37 sten.kristian.ivarsson [this message]
2021-03-23 19:20 ` Glenn Strauss
2021-03-24  9:18   ` sten.kristian.ivarsson
2021-03-30 14:17     ` Ken Brown
2021-03-31  8:24       ` sten.kristian.ivarsson
2021-03-31 15:07         ` Ken Brown
2021-04-01 16:02           ` Ken Brown
2021-04-06  7:52             ` Noel Grandin
2021-04-06 14:59               ` Ken Brown
2021-04-06 14:50             ` sten.kristian.ivarsson
2021-04-06 15:24               ` Ken Brown
2021-04-07 14:56               ` Ken Brown
2021-04-08  8:37                 ` sten.kristian.ivarsson
2021-04-08 19:47                   ` sten.kristian.ivarsson
2021-04-08 21:02                     ` Ken Brown
2021-04-13 14:06                 ` sten.kristian.ivarsson
2021-04-13 14:47                   ` Ken Brown
2021-04-13 22:43                     ` Ken Brown
2021-04-14 15:53                       ` Ken Brown
2021-04-14 17:14                       ` sten.kristian.ivarsson
2021-04-14 21:58                         ` Ken Brown
2021-04-15 13:15                           ` sten.kristian.ivarsson
2021-04-15 15:01                             ` Ken Brown
2021-04-27 14:56                               ` Ken Brown
2021-04-28  7:15                                 ` sten.kristian.ivarsson
2021-08-12 12:56                                   ` sten.kristian.ivarsson
2021-08-13 11:19                                     ` Ken Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='04cc01d71ffa$7d1e6cf0$775b46d0$@gmail.com' \
    --to=sten.kristian.ivarsson@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).