-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon_rpc.go
More file actions
64 lines (52 loc) · 970 Bytes
/
common_rpc.go
File metadata and controls
64 lines (52 loc) · 970 Bytes
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
package mr
import (
"fmt"
"log"
"net/rpc"
)
//
// RPC definitions.
//
// Add your RPC definitions here.
// Shutdown worker
type ShutdownArgs struct {}
type ShutdownReply struct {
Success bool
}
// Register worker
type RegisterWorkerArgs struct {
WorkerAddress string
}
type RegisterWorkerReply struct {
WorkerAddress string
Success bool
}
// Task
type DoTaskArgs struct {
JobName string
Phase jobPhase
TaskNumber int
NumberOtherPhase int
File string
}
type DoTaskReply struct {
Filename string
Success bool
}
//
// send an RPC request to the master->worker or worker->master,
// wait for the response. usually returns true.
// returns false if something goes wrong.
func call(rpcname, addr string, args interface{}, reply interface{}) bool {
c, err := rpc.Dial("tcp", addr)
if err != nil {
log.Fatal("dialing:", err)
}
defer c.Close()
err = c.Call(rpcname, args, reply)
if err == nil {
return true
}
fmt.Println(err)
return false
}