kvm tools: add kvm_ipc__send() and kvm_ipc__send_msg()

Current code write the sock manually. There is nothing constrains the format of
the written data is expect. Use kvm_ipc__send() and kvm_ipc__send_msg() for
such constraint.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
Lai Jiangshan
2011-12-20 17:08:51 +08:00
committed by Will Deacon
parent a9aae6c580
commit 50dc18ae65
2 changed files with 26 additions and 0 deletions
+3
View File
@@ -17,4 +17,7 @@ int kvm_ipc__register_handler(u32 type, void (*cb)(int fd, u32 type, u32 len, u8
int kvm_ipc__start(int sock);
int kvm_ipc__stop(void);
int kvm_ipc__send(int fd, u32 type);
int kvm_ipc__send_msg(int fd, u32 type, u32 len, u8 *msg);
#endif
+23
View File
@@ -33,6 +33,29 @@ int kvm_ipc__register_handler(u32 type, void (*cb)(int fd, u32 type, u32 len, u8
return 0;
}
int kvm_ipc__send(int fd, u32 type)
{
struct kvm_ipc_head head = {.type = type, .len = 0,};
if (write_in_full(fd, &head, sizeof(head)) != sizeof(head))
return -1;
return 0;
}
int kvm_ipc__send_msg(int fd, u32 type, u32 len, u8 *msg)
{
struct kvm_ipc_head head = {.type = type, .len = len,};
if (write_in_full(fd, &head, sizeof(head)) != sizeof(head))
return -1;
if (write_in_full(fd, msg, len) != len)
return -1;
return 0;
}
static int kvm_ipc__handle(int fd, u32 type, u32 len, u8 *data)
{
void (*cb)(int fd, u32 type, u32 len, u8 *msg);