summaryrefslogtreecommitdiff
path: root/dist.c
diff options
context:
space:
mode:
Diffstat (limited to 'dist.c')
-rw-r--r--dist.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/dist.c b/dist.c
new file mode 100644
index 0000000..3a76bf3
--- /dev/null
+++ b/dist.c
@@ -0,0 +1,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 )
+ }
+ }
+ }
+ }
+}