Permalink
Browse files

Fix screenshots by allowing blocking streams

Screenshots now work: it appears the virStreamRecv needs to be in
blocking mode. On the surface this is ok, since all libvirt commands
run in a thread but:

* virStreamSend sometimes blocks indefinitely

* virStreamRecv will block indefinitely if there is no data

* the libvirt thread blocks indefinitely if either blocks, with no way
  to terminate it

The console is still broken.
  • Loading branch information...
msantos committed Aug 24, 2012
1 parent b072d47 commit cd101af09750c8ce557134498e712965aa2515b8
Showing with 13 additions and 5 deletions.
  1. +3 −1 bin/vert
  2. +1 −1 c_src/vert_func.h
  3. +3 −1 c_src/vert_stream.c
  4. +2 −0 include/vert.hrl
  5. +4 −2 src/vert.erl
View
@@ -95,7 +95,9 @@ main(["screenshot", Host | Arg]) ->
{ok, Connect} = connect(Opt),
{ok, Domain} = domain(Connect, Host),
- {ok, Stream} = vert:virStreamNew(Connect),
+ % XXX Put the stream in blocking mode. Seems to be the only way to
+ % XXX read from a stream.
+ {ok, Stream} = vert:virStreamNew(Connect, 0),
{ok, Mime} = vert:virDomainScreenshot(Domain, Stream, Screen),
error_logger:info_report([{mime, Mime}]),
View
@@ -133,7 +133,7 @@ ErlNifFunc vert_funcs[] = {
/* stream */
{"virStreamAbort", 1, vert_virStreamAbort},
{"virStreamFinish", 1, vert_virStreamFinish},
- {"virStreamNew", 1, vert_virStreamNew},
+ {"virStreamNew", 2, vert_virStreamNew},
{"virStreamSend", 2, vert_virStreamSend},
{"virStreamRecv", 2, vert_virStreamRecv},
View
@@ -40,14 +40,16 @@ VERT_FUN_INT_RES(virStreamFinish, VERT_RES_STREAM);
vert_virStreamNew(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
VERT_RESOURCE *vp = NULL;
+ int flags = VIR_STREAM_NONBLOCK;
VERT_RESOURCE *sp = NULL;
VERT_GET_RESOURCE(0, vp, VERT_RES_CONNECT);
+ VERT_GET_INT(1, flags);
VERT_RES_ALLOC(sp, VERT_RES_STREAM, vp->res);
- sp->res = virStreamNew(vp->res, VIR_STREAM_NONBLOCK);
+ sp->res = virStreamNew(vp->res, flags);
if (sp->res == NULL) {
enif_release_resource(sp);
View
@@ -142,3 +142,5 @@
-define(VIR_KEYCODE_SET_WIN32, 8).
-define(VIR_KEYCODE_SET_RFB, 9).
-define(VIR_KEYCODE_SET_LAST, 10).
+
+-define(VIR_STREAM_NONBLOCK, 1).
View
@@ -122,7 +122,7 @@
virConnectGetLibVersion/1,
virConnectGetHostname/1,
virConnectGetCapabilities/1,
- virStreamNew/1,
+ virStreamNew/1, virStreamNew/2,
virStreamFinish/1,
virStreamAbort/1,
virStreamSend/2,
@@ -156,7 +156,9 @@ virStreamRecv(#resource{type = stream, res = Res}, Nbytes) ->
call(virStreamRecv, [Res, Nbytes]).
virStreamNew(#resource{type = connect, res = Res}) ->
- call(virStreamNew, [Res]).
+ call(virStreamNew, [Res, ?VIR_STREAM_NONBLOCK]).
+virStreamNew(#resource{type = connect, res = Res}, Flags) ->
+ call(virStreamNew, [Res, Flags]).
virStreamFinish(#resource{type = stream, res = Res}) ->
call(virStreamFinish, [Res]).

0 comments on commit cd101af

Please sign in to comment.