That was the problem, now it's solved. 
Thank you both for your time. 
Keep the great work. 

domingo, 3 de Novembro de 2019 às 05:18:23 UTC, Diogo Leitão escreveu:
>
> Hi
>
> I'm using FUSE + Cap'n Proto to build a distributed filesystem. Everything 
> seems to be fine, but when i try get the data field, on the client side, 
> using the getBuf method, i get a segmentation fault error. 
>  
> This is the code that i made. What am i doing wrong?  
>
>
> /*
>
>  * Capnp source file
>
>  */
>
> interface FilesystemOps {
>
>     ...
>     read @16 (request :ReadRequest) -> (reply :ReadReply);
>
>     ...
> }
>
>
> struct ReadRequest {
>     path @0 :Text;
>     size @1 :UInt64;
>     offset @2 :Int64;
> }
>
> struct ReadReply {
>     result @0 :Int32;
>     buf @1 :Data;
> }
>
>
> /*
>
>  * Client side
>
>  */
>
> int FilesystemOpsClient::rpc_read(const char *path, char *buf, size_t size, 
> off_t offset, struct fuse_file_info *fi) {
>     std::cout << "rpc_read begin " << size << std::endl;
>
>     int res;
>     auto clientData = getClient();
>     auto request = clientData->cap_.readRequest();
>     auto builder = request.getRequest();
>
>     builder.setPath(path);
>     builder.setSize(size);
>     builder.setOffset(offset);
>
>     auto reply = request.send().wait(clientData->waitScope_).getReply();
>
>     res = reply.getResult();
>     if (res != -1) {
>         std::memcpy(buf, reply.getBuf().begin(), res);
>
>     }
>
>     return res;
> }
>
>
> /*
>
>  * Server side
>
>  */
>
> kj::Promise<void> FilesystemOpsImpl::read(FilesystemOps::Server::ReadContext 
> context) {
>     int res;
>     auto request = context.getParams().getRequest();
>     auto reply = context.getResults().getReply();
>
>     std::string path = root_path_ + request.getPath().cStr();
>     size_t size = request.getSize();
>     off_t offset = request.getOffset();
>
>     int fd = ::open(path.c_str(), O_RDONLY);
>     if (fd == -1) {
>         res = -1;
>     } else {
>         res = pread(fd, reply.initBuf(size).begin(), size, offset);
>         close(fd);
>     }
>
>     reply.setResult(res);
>
>     return kj::READY_NOW;
> }
>
>
> Appreciate your help. Thank you. 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/c48d9231-bb98-4c65-9522-92fa8a0fd622%40googlegroups.com.

Reply via email to