Add simple back pressure mechanism

This commit is contained in:
2020-04-22 12:33:05 +02:00
parent 4e1fd36aa1
commit cccba2f771
2 changed files with 33 additions and 3 deletions
+10
View File
@@ -47,12 +47,17 @@ int main (int argc, char *argv[]) {
auto ctx = zmq_ctx_new();
auto socket = zmq_socket(ctx, ZMQ_PUSH);
auto more_socket = zmq_socket(ctx, ZMQ_SUB);
//TODO: Use ipc?
if (zmq_connect(socket, "tcp://localhost:50000") != 0) {
throw runtime_error(strerror (errno));
}
if (zmq_connect(more_socket, "tcp://localhost:50001") != 0) {
throw runtime_error(strerror (errno));
}
int status = 0;
int sndhwm = 1000;
@@ -121,6 +126,11 @@ int main (int argc, char *argv[]) {
(char*) (image_buffer.get() + (i_frame * 512 * 1024)),
512 * 1024 * 2,
0);
if ((i_frame>0) && (i_frame % 100 == 0)) {
// Waiting to send more.
zmq_recv(more_socket, nullptr, 0, 0);
}
}
}