OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 /* | 5 /* |
6 The rpc package provides access to the public methods of an object acros
s a | 6 The rpc package provides access to the public methods of an object acros
s a |
7 network or other I/O connection. A server registers an object, making i
t visible | 7 network or other I/O connection. A server registers an object, making i
t visible |
8 as a service with the name of the type of the object. After registratio
n, public | 8 as a service with the name of the type of the object. After registratio
n, public |
9 methods of the object will be accessible remotely. A server may registe
r multiple | 9 methods of the object will be accessible remotely. A server may registe
r multiple |
10 objects (services) of different types but it is an error to register mul
tiple | 10 objects (services) of different types but it is an error to register mul
tiple |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 continue | 207 continue |
208 } | 208 } |
209 // Method needs three ins: receiver, *args, *reply. | 209 // Method needs three ins: receiver, *args, *reply. |
210 // The args and reply must be structs until gobs are more genera
l. | 210 // The args and reply must be structs until gobs are more genera
l. |
211 if mtype.NumIn() != 3 { | 211 if mtype.NumIn() != 3 { |
212 log.Stderr("method", mname, "has wrong number of ins:",
mtype.NumIn()); | 212 log.Stderr("method", mname, "has wrong number of ins:",
mtype.NumIn()); |
213 continue; | 213 continue; |
214 } | 214 } |
215 argType, ok := mtype.In(1).(*reflect.PtrType); | 215 argType, ok := mtype.In(1).(*reflect.PtrType); |
216 if !ok { | 216 if !ok { |
217 » » » log.Stderr(mname, "arg type not a pointer:", argType.Str
ing()); | 217 » » » log.Stderr(mname, "arg type not a pointer:", mtype.In(1)
); |
218 continue; | 218 continue; |
219 } | 219 } |
220 if _, ok := argType.Elem().(*reflect.StructType); !ok { | 220 if _, ok := argType.Elem().(*reflect.StructType); !ok { |
221 » » » log.Stderr(mname, "arg type not a pointer to a struct:",
argType.String()); | 221 » » » log.Stderr(mname, "arg type not a pointer to a struct:",
argType); |
222 continue; | 222 continue; |
223 } | 223 } |
224 replyType, ok := mtype.In(2).(*reflect.PtrType); | 224 replyType, ok := mtype.In(2).(*reflect.PtrType); |
225 if !ok { | 225 if !ok { |
226 » » » log.Stderr(mname, "reply type not a pointer:", replyType
.String()); | 226 » » » log.Stderr(mname, "reply type not a pointer:", mtype.In(
2)); |
227 continue; | 227 continue; |
228 } | 228 } |
229 if _, ok := replyType.Elem().(*reflect.StructType); !ok { | 229 if _, ok := replyType.Elem().(*reflect.StructType); !ok { |
230 » » » log.Stderr(mname, "reply type not a pointer to a struct:
", replyType.String()); | 230 » » » log.Stderr(mname, "reply type not a pointer to a struct:
", replyType); |
231 continue; | 231 continue; |
232 } | 232 } |
233 if !isPublic(argType.Elem().Name()) { | 233 if !isPublic(argType.Elem().Name()) { |
234 » » » log.Stderr(mname, "argument type not public:", argType.S
tring()); | 234 » » » log.Stderr(mname, "argument type not public:", argType); |
235 continue; | 235 continue; |
236 } | 236 } |
237 if !isPublic(replyType.Elem().Name()) { | 237 if !isPublic(replyType.Elem().Name()) { |
238 » » » log.Stderr(mname, "reply type not public:", replyType.St
ring()); | 238 » » » log.Stderr(mname, "reply type not public:", replyType); |
239 continue; | 239 continue; |
240 } | 240 } |
241 // Method needs one out: os.Error. | 241 // Method needs one out: os.Error. |
242 if mtype.NumOut() != 1 { | 242 if mtype.NumOut() != 1 { |
243 log.Stderr("method", mname, "has wrong number of outs:",
mtype.NumOut()); | 243 log.Stderr("method", mname, "has wrong number of outs:",
mtype.NumOut()); |
244 continue; | 244 continue; |
245 } | 245 } |
246 if returnType := mtype.Out(0); returnType != typeOfOsError { | 246 if returnType := mtype.Out(0); returnType != typeOfOsError { |
247 log.Stderr("method", mname, "returns", returnType.String
(), "not os.Error"); | 247 log.Stderr("method", mname, "returns", returnType.String
(), "not os.Error"); |
248 continue; | 248 continue; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 io.WriteString(conn, "HTTP/1.0 "+connected+"\n\n"); | 404 io.WriteString(conn, "HTTP/1.0 "+connected+"\n\n"); |
405 server.input(conn); | 405 server.input(conn); |
406 } | 406 } |
407 | 407 |
408 // HandleHTTP registers an HTTP handler for RPC messages. | 408 // HandleHTTP registers an HTTP handler for RPC messages. |
409 // It is still necessary to invoke http.Serve(), typically in a go statement. | 409 // It is still necessary to invoke http.Serve(), typically in a go statement. |
410 func HandleHTTP() { | 410 func HandleHTTP() { |
411 http.Handle(rpcPath, http.HandlerFunc(serveHTTP)); | 411 http.Handle(rpcPath, http.HandlerFunc(serveHTTP)); |
412 http.Handle(debugPath, http.HandlerFunc(debugHTTP)); | 412 http.Handle(debugPath, http.HandlerFunc(debugHTTP)); |
413 } | 413 } |
OLD | NEW |