X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org MIME-Version: 1.0 Date: Wed, 16 Sep 2009 22:16:21 +0200 Message-ID: Subject: Opening a socket connection in a fork ? From: Gu1ll4um3r0m41n To: cygwin AT cygwin DOT com Content-Type: multipart/mixed; boundary=00504502d2d6868ede0473b7922d Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com --00504502d2d6868ede0473b7922d Content-Type: text/plain; charset=ISO-8859-1 Hello, I'm trying to run a program on cygwin that forks, opens a socket connection and sends the status of the connection to the parent process using pipes. The parent process then sends data through the opened socket. The program works well on linux but on cygwin, i cannot use recv on a socket opened in a fork. The recv function always return -1, errno 22 ("EINVAL"). The weird thing is that the socket stays open and send still works... I attached a short example. I don't know if this is a bug or a limitation due to the fork() implementation in cygwin... I searched on google but couldn't find anything really useful. Gu1 --00504502d2d6868ede0473b7922d Content-Type: application/octet-stream; name="test.c" Content-Disposition: attachment; filename="test.c" Content-Transfer-Encoding: base64 X-Attachment-Id: f_fzoifpo70 I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDx1bmlzdGQuaD4KI2luY2x1 ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RyaW5nLmg+CiNpbmNsdWRlIDxz eXMvdHlwZXMuaD4KI2luY2x1ZGUgPHN5cy9zb2NrZXQuaD4KI2luY2x1ZGUg PG5ldGluZXQvaW4uaD4KI2luY2x1ZGUgPGFycGEvaW5ldC5oPgojaW5jbHVk ZSA8bmV0ZGIuaD4KI2luY2x1ZGUgPGVycm5vLmg+CgpzdHJ1Y3Qgc2RhdGEg ewoJaW50IGNoaWxkX3JlYWQ7CglpbnQg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IG1haW4oKSB7Cglz dHJ1Y3Qgc2RhdGEgKmRhdGE7CglwaWRfdCBwaWQ7CglkYXRhID0gbWFsbG9j KHNpemVvZigqZGF0YSkpOwoJCglpZihpbml0KGRhdGEpIDwgMSkgewoJCXJl dHVybiAwOwoJfQoJCgkvKioqKiovCglzd2l0Y2gocGlkID0gZm9yaygpKSB7 CgkJLyogZm9yayBmYWlsZWQgKi8KCQljYXNlIC0xOgoJCQlwcmludGYoImZv cmsgZmFpbGVkIik7CgkJCXJldHVybjsKCQkvKiBjaGlsZCBwcm9jZXNzICov CgkJY2FzZSAwOgoJCQlzZXR1aWQoZ2V0dWlkKCkpOwoJCQljbG9zZShkYXRh LT5jaGlsZF9yZWFkKTsKCQkJb3BlbkNvbm5lY3Rpb24oZGF0YSk7CgkJCV9l eGl0KEVYSVRfU1VDQ0VTUyk7Cgl9CgkKCXdhaXRSZXN1bHQoZGF0YSk7IC8v IHdvbid0IHdvcms6IG9wZW5Db25uZWN0aW9uIGlzIGluc2lkZSBhIGZvcmsK CQoJY2xvc2UoZGF0YS0+Y2hpbGRfcmVhZCk7CgljbG9zZShkYXRhLT5jaGls ZF93cml0ZSk7CgljbG9zZShkYXRhLT5zb2NrKTsKCQoJLyoqKioqLwoJCglp Zihpbml0KGRhdGEpIDwgMSkgewoJCXJldHVybiAwOwoJfQoJCglvcGVuQ29u bmVjdGlvbihkYXRhKTsKCXdhaXRSZXN1bHQoZGF0YSk7IC8vIHdpbGwgd29y awoJCgljbG9zZShkYXRhLT5jaGlsZF9yZWFkKTsKCWNsb3NlKGRhdGEtPmNo aWxkX3dyaXRlKTsKCWNsb3NlKGRhdGEtPnNvY2spOwoJCglyZXR1cm4gMDsK fQo= --00504502d2d6868ede0473b7922d Content-Type: text/plain; charset=us-ascii -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple --00504502d2d6868ede0473b7922d--