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

Can it handle when one of the properties of the message passed is std::string? #69

Open
zeroRains opened this issue Jul 10, 2024 · 0 comments

Comments

@zeroRains
Copy link

I try to send a std::string from client to server. I modify the code in the rpc.cpp

I modify the struct Message,

struct Message {
  uint64_t count;
  uint64_t timestamp;
  uint8_t *data;
  std::string code;
};

function callback(),

bool callback(const shm::memory::Memblock &req, shm::memory::Memblock *resp) {
  auto *msg = reinterpret_cast<Message *>(req.ptr);
  auto lag = shm::current_time() - msg->timestamp;
  std::cout << current_count << ", " << msg->count <<"    "<<msg->code << "\n";
  ....
}

and function client_loop().

void client_loop(int seconds, int vector_size) {
  ...
  auto *rawptr = malloc(vector_size);
  std::memset(rawptr, 255, vector_size);
  Message *msg = reinterpret_cast<Message *>(rawptr);
  msg->count = 0;
  msg->code = "hello world!";
  ...
}

But it got a segmentation fault error when I std::cout the msg->code.

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

1 participant