Hi Tomas,

Apparently, inserting some kind of socketSelect() is essential when using non-blocking sockets and a client/erve architecture. That is at least one thing that I have learned ;-).

In C++, between sending and requesting, I inserted a call to this function:
bool wait(int s) {
  fd_set read_set;
  struct timeval timeout {};
  memset(&timeout, 0, sizeof(timeout));
  bool done{};
  while (!done ) {
    FD_ZERO(&read_set);
    FD_SET(s, &read_set);
    int rc = select(s + 1, &read_set, NULL, NULL, &timeout);
    done = (rc == 1) && FD_ISSET(s, &read_set);
  };
  return done;
};

Inserting this call was essential in solving my problem.

Ben

Op 15-02-2023 om 17:17 schreef Tomas Kalibera:
In the example you are waiting only for a single byte. But if the response may be longer, one needs to take into account in the client that not all bytes of the response may be available right away. One would keep receiving the data in a loop, as they become available (e.g. socketSelect() would tell), keep appending them to a buffer, and keep looking for when they are complete.

Tomas
Ben

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to