delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2025/04/07/04:40:10

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 5378e9HL1335500
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 5378e9HL1335500
Authentication-Results: delorie.com;
dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=vmj5F3sz
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF09D384D196
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1744015208;
bh=ZeIgh7zsQBgFBuhWdlqhW0N21ZU7HQoFzTN1TsaxPEY=;
h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=vmj5F3szgec5opnObRhIrATD6jBtoBI0gyIRoYJOkMuv4QVFdIRiK1oB6qc37k/tZ
3sRvHXF5YfLMMPhi9k1dZ+66lyVzBMXzikweC4jAaVo03cRYWe+61F/emwuJZmAQR2
30IoLlSlHolse5n/RniWS/YuojWkJFfPdRPZZKfQ=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C190D386484B
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C190D386484B
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1744015181; cv=none;
b=c4c56lF0HEqkJdgd3YmnlY+oELuL1egUoc3I/7yKwA2zZa8e8PUCZ6n0JJhR8MhFfSL9b/R0Ne2VKFmnmW08vInBpW82blGwQ53qbJcPLVr0jCp4da+WsfRi6SjbHe1PgF5ffXGmbLnbY6RSwqdlm8xLB9G44cdez+U3az1a9iw=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1744015181; c=relaxed/simple;
bh=qTZeurzDf7ssPxvbfDITWMU3X+n0dQ6H71+fEy0p6RY=;
h=Date:From:To:Subject:Message-Id:Mime-Version:DKIM-Signature;
b=klHX+AHKFkDG9LOkCwDR9MbsWuNFmprfp1IvOyXzf9amzT3UG24ui6eDorpKqAnBGmzS1QKRx4WGIx696WTLK9yGmu2ELj+gbrZRajP+Ty1t9JqY5u6a5fKsEaXlFSpNl23SJ65nes2bCmeoFKdMgLylSwFhuMw3geFGdpW+leY=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C190D386484B
Date: Mon, 7 Apr 2025 17:39:37 +0900
To: cygwin AT cygwin DOT com
Subject: Re: unix socket hang when connect
Message-Id: <20250407173937.3c2c1e2d5e148b446a558ff4@nifty.ne.jp>
In-Reply-To: <TYCPR01MB10926FF8926CA63704867ADC8F8AA2@TYCPR01MB10926.jpnprd01.prod.outlook.com>
References: <TYCPR01MB10926FF8926CA63704867ADC8F8AA2 AT TYCPR01MB10926 DOT jpnprd01 DOT prod DOT outlook DOT com>
X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
Mime-Version: 1.0
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
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: Takashi Yano via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp>
Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>

On Mon,  7 Apr 2025 15:08:32 +0800
Yuyi Wang wrote:
> Below is a simple unix socket testing code. It creates a unix socket server and
> a client to connect to it immediately. It works on Linux and macOS, but hangs on
> cygwin. bind + listen work well, but seems that the connect method never returns.
> 
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <unistd.h>
> #include <sys/socket.h>
> #include <sys/un.h>
> #include <errno.h>
> 
> #define SOCKET_PATH "/tmp/example_socket"
> 
> int main() {
>     int server_fd, client_fd;
>     struct sockaddr_un server_addr;
>     socklen_t client_len;
> 
>     server_fd = socket(AF_UNIX, SOCK_STREAM, 0);
>     if (server_fd == -1) {
>         perror("server socket");
>         exit(EXIT_FAILURE);
>     }
> 
>     memset(&server_addr, 0, sizeof(server_addr));
>     server_addr.sun_family = AF_UNIX;
>     strncpy(server_addr.sun_path, SOCKET_PATH, sizeof(server_addr.sun_path) - 1);
> 
>     if (bind(server_fd, (struct sockaddr*)&server_addr, sizeof(server_addr)) == -1) {
>         perror("bind");
>         exit(EXIT_FAILURE);
>     }
> 
>     if (listen(server_fd, 1) == -1) {
>         perror("listen");
>         exit(EXIT_FAILURE);
>     }
> 
>     printf("Server is listening on %s\n", SOCKET_PATH);
> 
>     client_fd = socket(AF_UNIX, SOCK_STREAM, 0);
>     if (client_fd == -1) {
>         perror("client socket");
>         exit(EXIT_FAILURE);
>     }
> 
>     if (connect(client_fd, (struct sockaddr*)&server_addr, sizeof(server_addr)) == -1) {
>         perror("connect");
>         exit(EXIT_FAILURE);
>     }
> 
>     printf("Client connected to server\n");
> 
>     close(client_fd);
>     close(server_fd);
>     unlink(SOCKET_PATH);
> 
>     return 0;
> }

I guess connect() just is just waiting accept().

-- 
Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp>

-- 
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

- Raw text -


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