blob: 3a76bf3a2c74699838883d50fa7e1f74dda3c1ba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#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 )
}
}
}
}
}
|