Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
017edaf7
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
017edaf7
编写于
7月 02, 2012
作者:
M
Matthias Bolte
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
esx: Wrap libcurl multi handle
上级
60687546
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
129 addition
and
0 deletion
+129
-0
src/esx/esx_vi.c
src/esx/esx_vi.c
+111
-0
src/esx/esx_vi.h
src/esx/esx_vi.h
+18
-0
未找到文件。
src/esx/esx_vi.c
浏览文件 @
017edaf7
...
@@ -86,6 +86,7 @@ ESX_VI__TEMPLATE__ALLOC(CURL)
...
@@ -86,6 +86,7 @@ ESX_VI__TEMPLATE__ALLOC(CURL)
ESX_VI__TEMPLATE__FREE
(
CURL
,
ESX_VI__TEMPLATE__FREE
(
CURL
,
{
{
esxVI_SharedCURL
*
shared
=
item
->
shared
;
esxVI_SharedCURL
*
shared
=
item
->
shared
;
esxVI_MultiCURL
*
multi
=
item
->
multi
;
if
(
shared
!=
NULL
)
{
if
(
shared
!=
NULL
)
{
esxVI_SharedCURL_Remove
(
shared
,
item
);
esxVI_SharedCURL_Remove
(
shared
,
item
);
...
@@ -95,6 +96,14 @@ ESX_VI__TEMPLATE__FREE(CURL,
...
@@ -95,6 +96,14 @@ ESX_VI__TEMPLATE__FREE(CURL,
}
}
}
}
if
(
multi
!=
NULL
)
{
esxVI_MultiCURL_Remove
(
multi
,
item
);
if
(
multi
->
count
==
0
)
{
esxVI_MultiCURL_Free
(
&
multi
);
}
}
if
(
item
->
handle
!=
NULL
)
{
if
(
item
->
handle
!=
NULL
)
{
curl_easy_cleanup
(
item
->
handle
);
curl_easy_cleanup
(
item
->
handle
);
}
}
...
@@ -555,11 +564,15 @@ esxVI_SharedCURL_Add(esxVI_SharedCURL *shared, esxVI_CURL *curl)
...
@@ -555,11 +564,15 @@ esxVI_SharedCURL_Add(esxVI_SharedCURL *shared, esxVI_CURL *curl)
}
}
}
}
virMutexLock
(
&
curl
->
lock
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_SHARE
,
shared
->
handle
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_SHARE
,
shared
->
handle
);
curl
->
shared
=
shared
;
curl
->
shared
=
shared
;
++
shared
->
count
;
++
shared
->
count
;
virMutexUnlock
(
&
curl
->
lock
);
return
0
;
return
0
;
}
}
...
@@ -583,11 +596,109 @@ esxVI_SharedCURL_Remove(esxVI_SharedCURL *shared, esxVI_CURL *curl)
...
@@ -583,11 +596,109 @@ esxVI_SharedCURL_Remove(esxVI_SharedCURL *shared, esxVI_CURL *curl)
return
-
1
;
return
-
1
;
}
}
virMutexLock
(
&
curl
->
lock
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_SHARE
,
NULL
);
curl_easy_setopt
(
curl
->
handle
,
CURLOPT_SHARE
,
NULL
);
curl
->
shared
=
NULL
;
curl
->
shared
=
NULL
;
--
shared
->
count
;
--
shared
->
count
;
virMutexUnlock
(
&
curl
->
lock
);
return
0
;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* MultiCURL
*/
/* esxVI_MultiCURL_Alloc */
ESX_VI__TEMPLATE__ALLOC
(
MultiCURL
)
/* esxVI_MultiCURL_Free */
ESX_VI__TEMPLATE__FREE
(
MultiCURL
,
{
if
(
item
->
count
>
0
)
{
/* Better leak than crash */
VIR_ERROR
(
_
(
"Trying to free MultiCURL object that is still in use"
));
return
;
}
if
(
item
->
handle
!=
NULL
)
{
curl_multi_cleanup
(
item
->
handle
);
}
})
int
esxVI_MultiCURL_Add
(
esxVI_MultiCURL
*
multi
,
esxVI_CURL
*
curl
)
{
if
(
curl
->
handle
==
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Cannot add uninitialized CURL handle to a multi handle"
));
return
-
1
;
}
if
(
curl
->
multi
!=
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Cannot add CURL handle to a multi handle twice"
));
return
-
1
;
}
if
(
multi
->
handle
==
NULL
)
{
multi
->
handle
=
curl_multi_init
();
if
(
multi
->
handle
==
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Could not initialize CURL (multi)"
));
return
-
1
;
}
}
virMutexLock
(
&
curl
->
lock
);
curl_multi_add_handle
(
multi
->
handle
,
curl
->
handle
);
curl
->
multi
=
multi
;
++
multi
->
count
;
virMutexUnlock
(
&
curl
->
lock
);
return
0
;
}
int
esxVI_MultiCURL_Remove
(
esxVI_MultiCURL
*
multi
,
esxVI_CURL
*
curl
)
{
if
(
curl
->
handle
==
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Cannot remove uninitialized CURL handle from a "
"multi handle"
));
return
-
1
;
}
if
(
curl
->
multi
==
NULL
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Cannot remove CURL handle from a multi handle when it "
"wasn't added before"
));
return
-
1
;
}
if
(
curl
->
multi
!=
multi
)
{
ESX_VI_ERROR
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"CURL (multi) mismatch"
));
return
-
1
;
}
virMutexLock
(
&
curl
->
lock
);
curl_multi_remove_handle
(
multi
->
handle
,
curl
->
handle
);
curl
->
multi
=
NULL
;
--
multi
->
count
;
virMutexUnlock
(
&
curl
->
lock
);
return
0
;
return
0
;
}
}
...
...
src/esx/esx_vi.h
浏览文件 @
017edaf7
...
@@ -85,6 +85,7 @@ typedef enum _esxVI_Occurrence esxVI_Occurrence;
...
@@ -85,6 +85,7 @@ typedef enum _esxVI_Occurrence esxVI_Occurrence;
typedef
struct
_esxVI_ParsedHostCpuIdInfo
esxVI_ParsedHostCpuIdInfo
;
typedef
struct
_esxVI_ParsedHostCpuIdInfo
esxVI_ParsedHostCpuIdInfo
;
typedef
struct
_esxVI_CURL
esxVI_CURL
;
typedef
struct
_esxVI_CURL
esxVI_CURL
;
typedef
struct
_esxVI_SharedCURL
esxVI_SharedCURL
;
typedef
struct
_esxVI_SharedCURL
esxVI_SharedCURL
;
typedef
struct
_esxVI_MultiCURL
esxVI_MultiCURL
;
typedef
struct
_esxVI_Context
esxVI_Context
;
typedef
struct
_esxVI_Context
esxVI_Context
;
typedef
struct
_esxVI_Response
esxVI_Response
;
typedef
struct
_esxVI_Response
esxVI_Response
;
typedef
struct
_esxVI_Enumeration
esxVI_Enumeration
;
typedef
struct
_esxVI_Enumeration
esxVI_Enumeration
;
...
@@ -160,6 +161,7 @@ struct _esxVI_CURL {
...
@@ -160,6 +161,7 @@ struct _esxVI_CURL {
struct
curl_slist
*
headers
;
struct
curl_slist
*
headers
;
char
error
[
CURL_ERROR_SIZE
];
char
error
[
CURL_ERROR_SIZE
];
esxVI_SharedCURL
*
shared
;
esxVI_SharedCURL
*
shared
;
esxVI_MultiCURL
*
multi
;
};
};
int
esxVI_CURL_Alloc
(
esxVI_CURL
**
curl
);
int
esxVI_CURL_Alloc
(
esxVI_CURL
**
curl
);
...
@@ -187,6 +189,22 @@ int esxVI_SharedCURL_Remove(esxVI_SharedCURL *shared, esxVI_CURL *curl);
...
@@ -187,6 +189,22 @@ int esxVI_SharedCURL_Remove(esxVI_SharedCURL *shared, esxVI_CURL *curl);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* MultiCURL
*/
struct
_esxVI_MultiCURL
{
CURLM
*
handle
;
size_t
count
;
};
int
esxVI_MultiCURL_Alloc
(
esxVI_MultiCURL
**
multi
);
void
esxVI_MultiCURL_Free
(
esxVI_MultiCURL
**
multi
);
int
esxVI_MultiCURL_Add
(
esxVI_MultiCURL
*
multi
,
esxVI_CURL
*
curl
);
int
esxVI_MultiCURL_Remove
(
esxVI_MultiCURL
*
multi
,
esxVI_CURL
*
curl
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Context
* Context
*/
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录