forked from kubernetes/minikube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
srv_respond.go
166 lines (148 loc) · 3.44 KB
/
srv_respond.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright 2009 The Go9p Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package go9p
import "fmt"
// SrvRequest operations. This interface should be implemented by all file servers.
// The operations correspond directly to most of the 9P2000 message types.
type SrvReqOps interface {
Attach(*SrvReq)
Walk(*SrvReq)
Open(*SrvReq)
Create(*SrvReq)
Read(*SrvReq)
Write(*SrvReq)
Clunk(*SrvReq)
Remove(*SrvReq)
Stat(*SrvReq)
Wstat(*SrvReq)
}
// Respond to the request with Rerror message
func (req *SrvReq) RespondError(err interface{}) {
switch e := err.(type) {
case *Error:
PackRerror(req.Rc, e.Error(), uint32(e.Errornum), req.Conn.Dotu)
case error:
PackRerror(req.Rc, e.Error(), uint32(EIO), req.Conn.Dotu)
default:
PackRerror(req.Rc, fmt.Sprintf("%v", e), uint32(EIO), req.Conn.Dotu)
}
req.Respond()
}
// Respond to the request with Rversion message
func (req *SrvReq) RespondRversion(msize uint32, version string) {
err := PackRversion(req.Rc, msize, version)
if err != nil {
req.RespondError(err)
} else {
req.Respond()
}
}
// Respond to the request with Rauth message
func (req *SrvReq) RespondRauth(aqid *Qid) {
err := PackRauth(req.Rc, aqid)
if err != nil {
req.RespondError(err)
} else {
req.Respond()
}
}
// Respond to the request with Rflush message
func (req *SrvReq) RespondRflush() {
err := PackRflush(req.Rc)
if err != nil {
req.RespondError(err)
} else {
req.Respond()
}
}
// Respond to the request with Rattach message
func (req *SrvReq) RespondRattach(aqid *Qid) {
err := PackRattach(req.Rc, aqid)
if err != nil {
req.RespondError(err)
} else {
req.Respond()
}
}
// Respond to the request with Rwalk message
func (req *SrvReq) RespondRwalk(wqids []Qid) {
err := PackRwalk(req.Rc, wqids)
if err != nil {
req.RespondError(err)
} else {
req.Respond()
}
}
// Respond to the request with Ropen message
func (req *SrvReq) RespondRopen(qid *Qid, iounit uint32) {
err := PackRopen(req.Rc, qid, iounit)
if err != nil {
req.RespondError(err)
} else {
req.Respond()
}
}
// Respond to the request with Rcreate message
func (req *SrvReq) RespondRcreate(qid *Qid, iounit uint32) {
err := PackRcreate(req.Rc, qid, iounit)
if err != nil {
req.RespondError(err)
} else {
req.Respond()
}
}
// Respond to the request with Rread message
func (req *SrvReq) RespondRread(data []byte) {
err := PackRread(req.Rc, data)
if err != nil {
req.RespondError(err)
} else {
req.Respond()
}
}
// Respond to the request with Rwrite message
func (req *SrvReq) RespondRwrite(count uint32) {
err := PackRwrite(req.Rc, count)
if err != nil {
req.RespondError(err)
} else {
req.Respond()
}
}
// Respond to the request with Rclunk message
func (req *SrvReq) RespondRclunk() {
err := PackRclunk(req.Rc)
if err != nil {
req.RespondError(err)
} else {
req.Respond()
}
}
// Respond to the request with Rremove message
func (req *SrvReq) RespondRremove() {
err := PackRremove(req.Rc)
if err != nil {
req.RespondError(err)
} else {
req.Respond()
}
}
// Respond to the request with Rstat message
func (req *SrvReq) RespondRstat(st *Dir) {
err := PackRstat(req.Rc, st, req.Conn.Dotu)
if err != nil {
req.RespondError(err)
} else {
req.Respond()
}
}
// Respond to the request with Rwstat message
func (req *SrvReq) RespondRwstat() {
err := PackRwstat(req.Rc)
if err != nil {
req.RespondError(err)
} else {
req.Respond()
}
}