From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:58477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAfDs-0003S0-1b for qemu-devel@nongnu.org; Mon, 03 Oct 2011 05:54:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RAfDq-0005nS-L2 for qemu-devel@nongnu.org; Mon, 03 Oct 2011 05:54:08 -0400 Received: from mel.act-europe.fr ([194.98.77.210]:58617) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAfDq-0005kA-Dt for qemu-devel@nongnu.org; Mon, 03 Oct 2011 05:54:06 -0400 Message-ID: <4E898617.4000406@adacore.com> Date: Mon, 03 Oct 2011 11:53:27 +0200 From: Fabien Chouteau MIME-Version: 1.0 References: <1317227322-12666-1-git-send-email-chouteau@adacore.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH V3] Add stdio char device on windows List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: pbonzini@redhat.com, mars@linux.vnet.ibm.com, qemu-devel@nongnu.org On 01/10/2011 08:40, Blue Swirl wrote: > On Wed, Sep 28, 2011 at 4:28 PM, Fabien Chouteau wrote: >> Simple implementation of an stdio char device on Windows. >> >> Signed-off-by: Fabien Chouteau >> --- >> qemu-char.c | 216 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- >> 1 files changed, 214 insertions(+), 2 deletions(-) >> >> diff --git a/qemu-char.c b/qemu-char.c >> index 09d2309..0ec449b 100644 >> --- a/qemu-char.c >> +++ b/qemu-char.c >> @@ -538,6 +538,9 @@ int send_all(int fd, const void *_buf, int len1) >> } >> #endif /* !_WIN32 */ >> >> +#define STDIO_MAX_CLIENTS 1 >> +static int stdio_nb_clients; >> + >> #ifndef _WIN32 >> >> typedef struct { >> @@ -545,8 +548,6 @@ typedef struct { >> int max_size; >> } FDCharDriver; >> >> -#define STDIO_MAX_CLIENTS 1 >> -static int stdio_nb_clients = 0; >> >> static int fd_chr_write(CharDriverState *chr, const uint8_t *buf, int len) >> { >> @@ -1451,6 +1452,8 @@ static int qemu_chr_open_pp(QemuOpts *opts, CharDriverState **_chr) >> >> #else /* _WIN32 */ >> >> +static CharDriverState *stdio_clients[STDIO_MAX_CLIENTS]; >> + >> typedef struct { >> int max_size; >> HANDLE hcom, hrecv, hsend; >> @@ -1809,6 +1812,214 @@ static int qemu_chr_open_win_file_out(QemuOpts *opts, CharDriverState **_chr) >> >> return qemu_chr_open_win_file(fd_out, _chr); >> } >> + >> +static int win_stdio_write(CharDriverState *chr, const uint8_t *buf, int len) >> +{ >> + HANDLE *hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); >> + DWORD dwSize; >> + int len1; >> + >> + len1 = len; >> + >> + while (len1 > 0) { >> + if (!WriteFile(hStdOut, buf, len1, &dwSize, NULL)) { >> + break; >> + } >> + buf += dwSize; >> + len1 -= dwSize; >> + } >> + >> + return len - len1; >> +} >> + >> +static HANDLE *hStdIn; > > I think you could avoid these variables by introducing a structure > that is passed as opaque in place of CharDriverState below. > Alright, you're not the first one to ask for this, so I'll do it :) Thanks for the review, -- Fabien Chouteau