blob: 607c50ec79d9e5e74914c5d29b15b27aa0c8d293 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include <stdint.h>
#include <unistd.h>
#include "ipc.h"
#include "main.h"
int send(void * self, local_id dst, const Message * msg) {
if( self == NULL )
return 1;
my_info_t *me = (my_info_t *) self;
if( me->dist_info == NULL )
return 1;
if( dst < 0 || dst > MAX_PROCCNT )
return 1;
uint8_t base = me->id * (me->dist_info->proccnt - 1); // base of block of pipes for this process
uint8_t idx = 0;
if( me->id < dst )
idx = base + dst - 1;
else
idx = base + dst;
int wr_dscr = me->dist_info->pipes[idx][1];
size_t wr_size = sizeof(msg->s_header) + msg->s_header.s_payload_len;
if( write( wr_dscr, &msg, wr_size ) != wr_size )
return 1;
return 0;
}
int send_multicast(void * self, const Message * msg) {
if( self == NULL )
return 1;
my_info_t *me = (my_info_t *) self;
if( me->dist_info == NULL )
return 1;
size_t wr_size;
int wr_dscr;
uint8_t base = me->id * (me->dist_info->proccnt - 1); // base of block of pipes for this process
uint8_t i;
for( i = 0; i < me->dist_info->proccnt - 1; i++) {
wr_dscr = me->dist_info->pipes[base+i][1];
wr_size = sizeof(msg->s_header) + msg->s_header.s_payload_len;
if( write( wr_dscr, &msg, wr_size ) != wr_size )
return 1;
}
return 0;
}
int receive(void * self, local_id from, Message * msg) {
return -1;
}
int receive_any(void * self, Message * msg) {
return -1;
}
|