#include "dist.h" void close_redundant_pipes( dist_info_t *info, uint8_t id ) { uint8_t i, j; for(i = 0; i < info->proccnt; i++) { uint8_t base = i * (info->proccnt-1); // base of block of pipes for this process if( i == id ) { for(j = 0; j < info->proccnt - 1; j++) close( info->pipes[base + j][0] ); // close only read descriptor of ( ID -> Y ) } else { uint8_t idx = ( id > i ? id - 1: id ); // index number in block of pipes for ( X -> ID ) for(j = 0; j < info->proccnt - 1; j++) { if( j == idx ) { close( info->pipes[base + j][1] ); // close only write descriptor of ( X -> ID ) } else { close( info->pipes[base + j][0] ); // close read descriptor of ( X -> Y, where Y != ID ) close( info->pipes[base + j][1] ); // close write descriptor of ( X -> Y, where Y != ID ) } } } } }