Commit 85b5a924 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

protobuf: add ability to collect objects in a shared memory (v2)

v2: s/shcollect_image/collect_image_sh/
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 67b6748f
......@@ -100,4 +100,6 @@ extern void do_pb_show_plain(int fd, int type, int single_entry,
int collect_image(int fd_t, int obj_t, unsigned size,
int (*collect)(void *obj, ProtobufCMessage *msg));
int collect_image_sh(int fd_t, int obj_t, unsigned size,
int (*collect)(void *obj, ProtobufCMessage *msg));
#endif /* PROTOBUF_H__ */
......@@ -639,8 +639,10 @@ err:
return ret;
}
int collect_image(int fd_t, int obj_t, unsigned size,
int (*collect)(void *obj, ProtobufCMessage *msg))
static int __collect_image(int fd_t, int obj_t, unsigned size,
int (*collect)(void *obj, ProtobufCMessage *msg),
void * (*alloc)(size_t size),
void (*free)(void *ptr))
{
int fd, ret;
......@@ -654,7 +656,7 @@ int collect_image(int fd_t, int obj_t, unsigned size,
if (size) {
ret = -1;
obj = xmalloc(size);
obj = alloc(size);
if (!obj)
break;
} else
......@@ -662,13 +664,13 @@ int collect_image(int fd_t, int obj_t, unsigned size,
ret = pb_read_one_eof(fd, &msg, obj_t);
if (ret <= 0) {
xfree(obj);
free(obj);
break;
}
ret = collect(obj, msg);
if (ret < 0) {
xfree(obj);
free(obj);
cr_pb_descs[obj_t].free(msg, NULL);
break;
}
......@@ -677,3 +679,15 @@ int collect_image(int fd_t, int obj_t, unsigned size,
close(fd);
return ret;
}
int collect_image(int fd_t, int obj_t, unsigned size,
int (*collect)(void *obj, ProtobufCMessage *msg))
{
return __collect_image(fd_t, obj_t, size, collect, malloc, free);
}
int collect_image_sh(int fd_t, int obj_t, unsigned size,
int (*collect)(void *obj, ProtobufCMessage *msg))
{
return __collect_image(fd_t, obj_t, size, collect, shmalloc, shfree_last);
}
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