qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>,
	"Stefan Weil" <sw@weilnetz.de>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Joel Stanley" <joel@jms.id.au>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	qemu-arm@nongnu.org, "Stefan Berger" <stefanb@linux.vnet.ibm.com>
Subject: Re: [PATCH 3/4] win32: stop mixing SOCKET and file descriptor space
Date: Tue, 21 Feb 2023 09:18:32 +0100	[thread overview]
Message-ID: <55e488cf-0b5f-f1e9-0a15-5d3e8c155abe@redhat.com> (raw)
In-Reply-To: <CAMxuvaxiN1jYr70k2yK0CUSjo4UQF8DqjPX_COvCdtAWhf3zNw@mail.gmail.com>

On 2/20/23 16:29, Marc-André Lureau wrote:
>> 7. A Windows SOCKET is also a HANDLE.  Maybe.  I guess.  Docs are
>>     confusing.
>>
> Kind of, but not really. I think a HANDLE is a kind of void*. You need to
> be careful using it appropriately with the right functions. Sometime, a
> HANDLE can work with generic functions, like ReadFile, but you should not
> use a CloseHandle on SOCKET, or registry key..

A Windows SOCKET *is* a file HANDLE except it's always in overlapped 
mode so Windows provides send()/recv() in case you don't want to deal 
with overlapped mode.  But you can use it with ReadFile too (Windows API 
documentation says that is only true sometimes, but Winsock API is 30 
years old and right now you pretty much always can).

However, sockets also has some extra information on the side, so you 
need to close them with closesocket() and CloseHandle() is not enough.

The problem is that close() of something opened with _open_osfhandle() 
*does* do that CloseHandle(), so basically you are closing the handle 
twice.  IIRC there used to be undocumented functions _alloc_osfhnd() and 
similar, but they don't exist anymore (even Wine does not have them), so 
we're stuck; unfortunately this is the reason why QEMU is not already 
doing something like what you have in this patch.

Is this a real bug or is it theoretical?  Do file descriptor and socket 
spaces overlap in practice?

Paolo



  parent reply	other threads:[~2023-02-21  8:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-12 20:49 [PATCH 0/4] win32: do not mix SOCKET and fd space marcandre.lureau
2023-02-12 20:49 ` [PATCH 1/4] tests: use closesocket() marcandre.lureau
2023-02-13  8:03   ` Thomas Huth
2023-02-12 20:49 ` [PATCH 2/4] io: " marcandre.lureau
2023-02-13  8:04   ` Thomas Huth
2023-02-12 20:49 ` [PATCH 3/4] win32: stop mixing SOCKET and file descriptor space marcandre.lureau
2023-02-20 11:27   ` Marc-André Lureau
2023-02-20 12:38   ` Markus Armbruster
2023-02-20 15:29     ` Marc-André Lureau
2023-02-20 15:58       ` Daniel P. Berrangé
2023-02-21  8:18       ` Paolo Bonzini [this message]
2023-02-21  9:12         ` Marc-André Lureau
2023-02-21 10:40           ` Marc-André Lureau
2023-02-21 10:52             ` Paolo Bonzini
2023-02-12 20:49 ` [PATCH 4/4] win32: replace closesocket() with close() wrapper marcandre.lureau

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=55e488cf-0b5f-f1e9-0a15-5d3e8c155abe@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=joel@jms.id.au \
    --cc=lvivier@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanb@linux.vnet.ibm.com \
    --cc=sw@weilnetz.de \
    --cc=thuth@redhat.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 NNTP newsgroup(s).