提交 47a089f0 编写于 作者: E Erik Skultety

admin: Introduce virAdmConnectIsAlive

Since most of our APIs rely on an acive functional connection to a daemon and
we have such a mechanism in libvirt already, there's need to have such a way in
libvirt-admin as well. By introducing a new public API, this patch provides
support to check for an active connection.
上级 64095787
无相关合并请求
......@@ -55,6 +55,7 @@ virAdmConnectPtr virAdmConnectOpen(const char *name, unsigned int flags);
int virAdmConnectClose(virAdmConnectPtr conn);
int virAdmConnectRef(virAdmConnectPtr conn);
int virAdmConnectIsAlive(virAdmConnectPtr conn);
int virAdmGetVersion(unsigned long long *libVer);
......
......@@ -420,3 +420,36 @@ virAdmGetVersion(unsigned long long *libVer)
virDispatchError(NULL);
return -1;
}
/**
* virAdmConnectIsAlive:
* @conn: connection to admin server
*
* Decide whether the connection to the admin server is alive or not.
* Connection is considered alive if the channel it is running over is not
* closed.
*
* Returns 1, if the connection is alive, 0 if there isn't an existing
* connection at all or the channel has already been closed, or -1 on error.
*/
int
virAdmConnectIsAlive(virAdmConnectPtr conn)
{
bool ret;
remoteAdminPrivPtr priv = NULL;
VIR_DEBUG("conn=%p", conn);
if (!conn)
return 0;
virCheckAdmConnectReturn(conn, -1);
virResetLastError();
priv = conn->privateData;
virObjectLock(priv);
ret = virNetClientIsOpen(priv->client);
virObjectUnlock(priv);
return ret;
}
......@@ -16,4 +16,5 @@ LIBVIRT_ADMIN_1.3.0 {
virAdmConnectClose;
virAdmConnectRef;
virAdmGetVersion;
virAdmConnectIsAlive;
};
......@@ -159,10 +159,10 @@ vshAdmConnectionHandler(vshControl *ctl)
{
vshAdmControlPtr priv = ctl->privData;
if (!priv->conn)
if (!virAdmConnectIsAlive(priv->conn))
vshAdmReconnect(ctl);
if (!priv->conn) {
if (!virAdmConnectIsAlive(priv->conn)) {
vshError(ctl, "%s", _("no valid connection"));
return NULL;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部