Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list objects in a pool #12

Open
wcchh opened this issue Jan 26, 2015 · 4 comments
Open

Add list objects in a pool #12

wcchh opened this issue Jan 26, 2015 · 4 comments

Comments

@wcchh
Copy link

wcchh commented Jan 26, 2015

Hi, I need a list function about specified pool, and I have added this function at my local for test. Could someone could help review it and let it be support function? Thanks in advance~

[at rados.h]
...
class Ioctx : public node::ObjectWrap {
...
static NAN_METHOD(aio_objects_list);
}

[at rados.cc]
...

define ENOENT 2

NAN_METHOD(Ioctx::aio_objects_list) {
NanScope();

if (args.Length() < 1 ||
!args[0]->IsString()) {
return NanThrowError("Bad argument.");
}

Ioctx* obj = ObjectWrap::Unwrap(args.This());
if ( !obj->require_created() ) NanReturnNull();

rados_list_ctx_t h_ctx;
//Start listing objects in a pool.
int err = rados_objects_list_open(obj->ioctx, &h_ctx);
if (err < 0) {
return NanThrowError("open list failed.");
}

Local ret_list = NanNew();
uint32_t array_id = 0;
//Get the next object name and locator in the pool.

while(0 <= err) {
const char *obj_name;
err = rados_objects_list_next(h_ctx, &obj_name, NULL);
if (err == 0) {
ret_list->Set(array_id, NanNew(obj_name));
array_id++;
}
}
rados_objects_list_close(h_ctx);

if (err < 0 && err != -ENOENT) {
return NanThrowError("list_next failed.");
}

NanReturnValue(ret_list);
}

@ksperis
Copy link
Owner

ksperis commented Jan 26, 2015

Hi, Thank you, I created a branch wip-list-objects to test the code. (https://github.com/ksperis/node-rados/tree/wip-list-objects)
I will look in more detail later.

@siboulet
Copy link
Contributor

I think obj_name is leaked here. Who's responsible for freeing obj_name? Could probably NanBufferUse to hand off the buffer to V8.

@ksperis
Copy link
Owner

ksperis commented Feb 17, 2015

NanNew (obj_name) isn't it enough to hand off the buffer ?

@siboulet
Copy link
Contributor

NanNew creates a copy. For buffers you can use NanBufferUse that tells V8 it should take ownership of the buffer.

However after re-reading the code I realize obj_name is a pointer to some allocation inside h_ctx and probably freed by librados when calling rados_objects_list_close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants