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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 if err == os.EOF || err == io.ErrUnexpectedEOF { | 345 if err == os.EOF || err == io.ErrUnexpectedEOF { |
346 if err == io.ErrUnexpectedEOF { | 346 if err == io.ErrUnexpectedEOF { |
347 log.Stderr("rpc: ", err) | 347 log.Stderr("rpc: ", err) |
348 } | 348 } |
349 break | 349 break |
350 } | 350 } |
351 s := "rpc: server cannot decode request: " + err.String(
) | 351 s := "rpc: server cannot decode request: " + err.String(
) |
352 sendResponse(sending, req, invalidRequest, codec, s) | 352 sendResponse(sending, req, invalidRequest, codec, s) |
353 break | 353 break |
354 } | 354 } |
355 » » serviceMethod := strings.Split(req.ServiceMethod, ".", 0) | 355 » » serviceMethod := strings.Split(req.ServiceMethod, ".", -1) |
356 if len(serviceMethod) != 2 { | 356 if len(serviceMethod) != 2 { |
357 s := "rpc: service/method request ill-formed: " + req.Se
rviceMethod | 357 s := "rpc: service/method request ill-formed: " + req.Se
rviceMethod |
358 sendResponse(sending, req, invalidRequest, codec, s) | 358 sendResponse(sending, req, invalidRequest, codec, s) |
359 continue | 359 continue |
360 } | 360 } |
361 // Look up the request. | 361 // Look up the request. |
362 server.Lock() | 362 server.Lock() |
363 service, ok := server.serviceMap[serviceMethod[0]] | 363 service, ok := server.serviceMap[serviceMethod[0]] |
364 server.Unlock() | 364 server.Unlock() |
365 if !ok { | 365 if !ok { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 io.WriteString(conn, "HTTP/1.0 "+connected+"\n\n") | 460 io.WriteString(conn, "HTTP/1.0 "+connected+"\n\n") |
461 ServeConn(conn) | 461 ServeConn(conn) |
462 } | 462 } |
463 | 463 |
464 // HandleHTTP registers an HTTP handler for RPC messages. | 464 // HandleHTTP registers an HTTP handler for RPC messages. |
465 // It is still necessary to invoke http.Serve(), typically in a go statement. | 465 // It is still necessary to invoke http.Serve(), typically in a go statement. |
466 func HandleHTTP() { | 466 func HandleHTTP() { |
467 http.Handle(rpcPath, http.HandlerFunc(serveHTTP)) | 467 http.Handle(rpcPath, http.HandlerFunc(serveHTTP)) |
468 http.Handle(debugPath, http.HandlerFunc(debugHTTP)) | 468 http.Handle(debugPath, http.HandlerFunc(debugHTTP)) |
469 } | 469 } |
OLD | NEW |