[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 2/2] Always open files in binary mode in virFDStreamOpenFileInternal



At Tue, 24 Sep 2013 11:16:39 +0100,
Daniel P. Berrange wrote:
> 
> On Tue, Sep 24, 2013 at 11:57:38AM +0200, Claudio Bley wrote:
> > On win32, using text mode for binary files might result in short
> > reads since ASCII character 0x1A is interpreted as EOF. Also, it
> > could lead to problems using the seek functions because of the \r
> > handling.
> > 
> > Signed-off-by: Claudio Bley <cbley av-test de>
> 
> What did you do to hit this problem ?  AFAIK the virFDStream code
> isn't useful on Windows at all, since it requires the iohelper
> process and we haven't got that working on Windows.

AFAIS, the iohelper is only needed for non-blocking I/O which I
haven't used.

Here's my code:

,----
|   virConnectPtr conn = virConnectOpen("test:///default");
|   
|   unsigned long libVer;
|   int ret = virConnectGetLibVersion(conn, &libVer);
| 
|   virDomainPtr domain = virDomainLookupByName(conn, "test");
| 
|   virStreamPtr stream = virStreamNew(conn, 0);
| 
|   char* mimetype = virDomainScreenshot(domain, stream, 0, 0);
|   char buf[8192];
|   int got = 0;
| 
|   puts(mimetype);
| 
|   do {
|     got = virStreamRecv(stream, buf, 8192);
| 
|     switch (got) {
|     case 0:
|       virStreamFinish(stream);
|       break;
| 
|     case -1:
|       puts("error");
|       virStreamAbort(stream);
|       goto cleanup;
| 
|     default:
|       printf("got %d bytes\n", got);
|     }
|   } while(got > 0);
| 
|  cleanup:
|   virDomainFree(domain);
|   virConnectClose(conn);
`----

Here's the output:

2013-09-24 07:30:46.823+0000: 3052: debug : virDomainScreenshot:3241 : dom=0000000000681D30, (VM: name=test, uuid=6695eb01-f6a4-8304-79aa-97f2502e193f), stream=0000000000681E30, flags=0
2013-09-24 07:30:46.823+0000: 3052: debug : virFDStreamOpenFileInternal:599 : st=0000000000681E30 path=/usr/x86_64-w64-mingw32/sys-root/mingw/share/libvirt/libvirtLogo.png oflags=0 offset=0 length=0 mode=0
2013-09-24 07:30:46.825+0000: 3052: debug : virFDStreamOpenInternal:490 : st=0000000000681E30 fd=3 cmd=0000000000000000 errfd=-1 length=0
image/png
2013-09-24 07:30:46.826+0000: 3052: debug : virStreamRecv:17138 : stream=0000000000681E30, data=000000000022DE20, nbytes=8192
got 5 bytes
2013-09-24 07:30:46.828+0000: 3052: debug : virStreamRecv:17138 : stream=0000000000681E30, data=000000000022DE20, nbytes=8192
2013-09-24 07:30:46.830+0000: 3052: debug : virStreamFinish:17506 : stream=0000000000681E30
2013-09-24 07:30:46.831+0000: 3052: debug : virFDStreamCloseInt:260 : st=0000000000681E30
2013-09-24 07:30:46.831+0000: 3052: debug : virFileClose:90 : Closed fd 3

/ Claudio
-- 
AV-Test GmbH, Henricistra├če 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:<http://www.av-test.org>

Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]