Commit 83b68785 authored by Daniel P. Berrange's avatar Daniel P. Berrange

Add support for connection close callbacks

Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
parent 336a2a2f
...@@ -712,6 +712,44 @@ _domain_event_free(void *opaque) ...@@ -712,6 +712,44 @@ _domain_event_free(void *opaque)
} }
static void
_close_callback(virConnectPtr con,
int reason,
void *opaque)
{
AV *data = opaque;
SV **self;
SV **cb;
dSP;
self = av_fetch(data, 0, 0);
cb = av_fetch(data, 1, 0);
SvREFCNT_inc(*self);
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(*self);
XPUSHs(sv_2mortal(newSViv(reason)));
PUTBACK;
call_sv(*cb, G_DISCARD);
FREETMPS;
LEAVE;
}
static void
_close_callback_free(void *opaque)
{
SV *sv = opaque;
SvREFCNT_dec(sv);
}
static int static int
_event_add_handle(int fd, _event_add_handle(int fd,
int events, int events,
...@@ -2260,6 +2298,32 @@ domain_event_deregister_any(con, callbackID) ...@@ -2260,6 +2298,32 @@ domain_event_deregister_any(con, callbackID)
virConnectDomainEventDeregisterAny(con, callbackID); virConnectDomainEventDeregisterAny(con, callbackID);
void
register_close_callback(conref, cb)
SV* conref;
SV* cb;
PREINIT:
AV *opaque;
virConnectPtr con;
PPCODE:
con = (virConnectPtr)SvIV((SV*)SvRV(conref));
opaque = newAV();
SvREFCNT_inc(cb);
SvREFCNT_inc(conref);
av_push(opaque, conref);
av_push(opaque, cb);
if (virConnectRegisterCloseCallback(con, _close_callback,
opaque, _close_callback_free) < 0)
_croak_error();
void
unregister_close_callback(con)
virConnectPtr con;
PPCODE:
virConnectUnregisterCloseCallback(con, _close_callback);
void void
interface_change_begin(conn, flags=0) interface_change_begin(conn, flags=0)
virConnectPtr conn; virConnectPtr conn;
...@@ -5770,6 +5834,10 @@ BOOT: ...@@ -5770,6 +5834,10 @@ BOOT:
REGISTER_CONSTANT(VIR_NODE_CPU_STATS_ALL_CPUS, NODE_CPU_STATS_ALL_CPUS); REGISTER_CONSTANT(VIR_NODE_CPU_STATS_ALL_CPUS, NODE_CPU_STATS_ALL_CPUS);
REGISTER_CONSTANT(VIR_NODE_MEMORY_STATS_ALL_CELLS, NODE_MEMORY_STATS_ALL_CELLS); REGISTER_CONSTANT(VIR_NODE_MEMORY_STATS_ALL_CELLS, NODE_MEMORY_STATS_ALL_CELLS);
REGISTER_CONSTANT(VIR_CONNECT_CLOSE_REASON_CLIENT, CLOSE_REASON_CLIENT);
REGISTER_CONSTANT(VIR_CONNECT_CLOSE_REASON_EOF, CLOSE_REASON_EOF);
REGISTER_CONSTANT(VIR_CONNECT_CLOSE_REASON_ERROR, CLOSE_REASON_ERROR);
REGISTER_CONSTANT(VIR_CONNECT_CLOSE_REASON_KEEPALIVE, CLOSE_REASON_KEEPALIVE);
stash = gv_stashpv( "Sys::Virt::Event", TRUE ); stash = gv_stashpv( "Sys::Virt::Event", TRUE );
......
...@@ -1382,6 +1382,18 @@ unregistering the event. ...@@ -1382,6 +1382,18 @@ unregistering the event.
Unregister a callback, associated with the C<$callbackID> previously Unregister a callback, associated with the C<$callbackID> previously
obtained from C<domain_event_register_any>. obtained from C<domain_event_register_any>.
=item $conn->register_close_callback($coderef);
Register a callback to be invoked when the connection is closed.
The callback will be invoked with two parameters, the C<$conn>
it was registered against, and the reason for the close event.
The reason value will be one of the C<CLOSE REASON CONSTANTS>
listed later in this document.
=item $conn->unregister_close_callback();
Remove the previously registered close callback.
=item my $xml = $con->baseline_cpu(\@xml, $flags=0) =item my $xml = $con->baseline_cpu(\@xml, $flags=0)
Given an array ref whose elements are XML documents describing host CPUs, Given an array ref whose elements are XML documents describing host CPUs,
...@@ -1538,6 +1550,32 @@ Request statistics for all CPUs ...@@ -1538,6 +1550,32 @@ Request statistics for all CPUs
Request statistics for all memory cells Request statistics for all memory cells
=back
=head2 CLOSE REASON CONSTANTS
The following constants related to the connection close callback,
describe the reason for the closing of the connection.
=over 4
=item Sys::Virt::CLOSE_REASON_CLIENT
The client application requested the connection be closed
=item Sys::Virt::CLOSE_REASON_EOF
End-of-file was encountered reading data from the connection
=item Sys::Virt::CLOSE_REASON_ERROR
An I/O error was encountered reading/writing data from/to the
connection
=item Sys::Virt::CLOSE_REASON_KEEPALIVE
The connection keepalive timer triggered due to lack of response
from the server
=back =back
......
...@@ -91,6 +91,8 @@ virStreamEventCallback ...@@ -91,6 +91,8 @@ virStreamEventCallback
virStreamSinkFunc virStreamSinkFunc
virStreamSourceFunc virStreamSourceFunc
virConnectCloseFunc
); );
foreach my $func (sort { $a cmp $b } @functions) { foreach my $func (sort { $a cmp $b } @functions) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment