1 | /* |
---|
2 | * This is "mp_pvm.c". It contains all MP's utility routines associated with |
---|
3 | * PVM. It is to be included with all applications that employ PVM to |
---|
4 | * transport MP trees. |
---|
5 | * |
---|
6 | * Note: |
---|
7 | * mp_pvm_unpack() anticipates PvmNoData error from pvm_recv(). |
---|
8 | * PVM defaults to printing an error message when encounter such |
---|
9 | * error. To disable printing of error message, use the following: |
---|
10 | * |
---|
11 | * pvm_setopt(PvmAutoErr, 0); |
---|
12 | * |
---|
13 | * See "PVM 3 User'sGuide and Reference Manual" for detail. |
---|
14 | */ |
---|
15 | |
---|
16 | /********************************************************* |
---|
17 | * mp_pvm_pack(link, where, len) |
---|
18 | * return: 0 if success, -1 if failure. |
---|
19 | * arguments: link - can be anything, even NULL. |
---|
20 | * where - pointer to data to be packed. |
---|
21 | * len - number of bytes to be packed. |
---|
22 | *********************************************************/ |
---|
23 | int |
---|
24 | #ifdef _ANSIC_ |
---|
25 | mp_pvm_pack(MP_Link_pt link, char *where, unsigned long len) |
---|
26 | #else |
---|
27 | mp_pvm_pack(link, where, len) |
---|
28 | MP_Link_pt link; |
---|
29 | char *where; |
---|
30 | unsigned long len; |
---|
31 | #endif |
---|
32 | { |
---|
33 | int status; |
---|
34 | status = pvm_pkbyte(where, len, 1); |
---|
35 | if (status < 0) return(-1); |
---|
36 | else return(len); |
---|
37 | } |
---|
38 | |
---|
39 | /********************************************************* |
---|
40 | * mp_pvm_unpack(link, where, len) |
---|
41 | * return: number of bytes actually unpacked. -1 if failure. |
---|
42 | * arguments: link - can be anything, even NULL. |
---|
43 | * where - pointer to memory location to store unpacked data. |
---|
44 | * len - number of bytes to be packed. |
---|
45 | *********************************************************/ |
---|
46 | int |
---|
47 | #ifdef _ANSIC_ |
---|
48 | mp_pvm_unpack(MP_Link_pt link, char *where, unsigned long len) |
---|
49 | #else |
---|
50 | mp_pvm_unpack(link, where, len) |
---|
51 | MP_Link_pt link; |
---|
52 | char *where; |
---|
53 | unsigned long len; |
---|
54 | #endif |
---|
55 | { |
---|
56 | int status, bufid, actual_len, lenrecv, tid, msgtag; |
---|
57 | actual_len = len; |
---|
58 | status = pvm_upkbyte(where, actual_len, 1); |
---|
59 | if (status == PvmNoData) { |
---|
60 | bufid = pvm_recv(-1, -1); |
---|
61 | if (bufid < 0) return(-1); |
---|
62 | status = pvm_bufinfo(bufid, &lenrecv, &msgtag, &tid); |
---|
63 | actual_len = (len < lenrecv) ? len : lenrecv; |
---|
64 | status = pvm_upkbyte(where, actual_len, 1); |
---|
65 | } |
---|
66 | |
---|
67 | if (status < 0) return(-1); |
---|
68 | return(actual_len); |
---|
69 | } |
---|