Изменить размер буфера именованного канала в macOS

Есть ли способ контролировать размер буфера именованного канала, созданного через mkfifo?

Я использую macOS 10.13.2 и размер буфера кажется фиксированным в 8192 байта. Я смог добраться до этого числа с помощью этого фрагмента кода:

#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <thread>

#define BUFFER_SIZE 1024*1024
#define FIFO_PATH "/Users/joao/Desktop/fifo"
void readFifo() {
auto fd = open(FIFO_PATH, O_RDONLY);

if (fd < 0) {
std::cerr << "Failed to open fifo for reading" << std::endl;
return;
}

std::cout << "Ready to read!" << std::endl;

char buffer[BUFFER_SIZE];
auto total_bytes_read = 0;

while (total_bytes_read < BUFFER_SIZE) {
auto bytes_read = read(fd, buffer, BUFFER_SIZE);
std::cout << "Read " << bytes_read << " bytes" << std::endl;

total_bytes_read += bytes_read;
}

close(fd);
}

int main(int argc, const char * argv[]) {
unlink(FIFO_PATH);

if (mkfifo(FIFO_PATH, 0666) != 0) {
std::cerr << "Failed to create fifo" << std::endl;
return 1;
}

std::thread reader(readFifo);

auto fd = open(FIFO_PATH, O_WRONLY);

if (fd < 0) {
std::cerr << "Failed to open fifo for writing" << std::endl;
return 1;
}

char buffer[BUFFER_SIZE];

for (int i = 0; i < BUFFER_SIZE; i++) {
buffer[i] = 'a';
}

auto bytes_written = write(fd, buffer, BUFFER_SIZE);

reader.join();
std::cout << "Wrote " << bytes_written << " bytes" << std::endl;

unlink(FIFO_PATH);
return 0;
}

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector