LEFT | RIGHT |
(no file at all) | |
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 Package rpc provides access to the exported methods of an object across
a | 6 Package rpc provides access to the exported methods of an object across
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, exported | 8 as a service with the name of the type of the object. After registratio
n, exported |
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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 err = codec.ReadRequestHeader(req) | 488 err = codec.ReadRequestHeader(req) |
489 if err != nil { | 489 if err != nil { |
490 req = nil | 490 req = nil |
491 if err == os.EOF || err == io.ErrUnexpectedEOF { | 491 if err == os.EOF || err == io.ErrUnexpectedEOF { |
492 return | 492 return |
493 } | 493 } |
494 err = os.NewError("rpc: server cannot decode request: " + err.St
ring()) | 494 err = os.NewError("rpc: server cannot decode request: " + err.St
ring()) |
495 return | 495 return |
496 } | 496 } |
497 | 497 |
498 » serviceMethod := strings.Split(req.ServiceMethod, ".", -1) | 498 » serviceMethod := strings.Split(req.ServiceMethod, ".") |
499 if len(serviceMethod) != 2 { | 499 if len(serviceMethod) != 2 { |
500 err = os.NewError("rpc: service/method request ill-formed: " + r
eq.ServiceMethod) | 500 err = os.NewError("rpc: service/method request ill-formed: " + r
eq.ServiceMethod) |
501 return | 501 return |
502 } | 502 } |
503 // Look up the request. | 503 // Look up the request. |
504 server.Lock() | 504 server.Lock() |
505 service = server.serviceMap[serviceMethod[0]] | 505 service = server.serviceMap[serviceMethod[0]] |
506 server.Unlock() | 506 server.Unlock() |
507 if service == nil { | 507 if service == nil { |
508 err = os.NewError("rpc: can't find service " + req.ServiceMethod
) | 508 err = os.NewError("rpc: can't find service " + req.ServiceMethod
) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 http.Handle(rpcPath, server) | 599 http.Handle(rpcPath, server) |
600 http.Handle(debugPath, debugHTTP{server}) | 600 http.Handle(debugPath, debugHTTP{server}) |
601 } | 601 } |
602 | 602 |
603 // HandleHTTP registers an HTTP handler for RPC messages to DefaultServer | 603 // HandleHTTP registers an HTTP handler for RPC messages to DefaultServer |
604 // on DefaultRPCPath and a debugging handler on DefaultDebugPath. | 604 // on DefaultRPCPath and a debugging handler on DefaultDebugPath. |
605 // It is still necessary to invoke http.Serve(), typically in a go statement. | 605 // It is still necessary to invoke http.Serve(), typically in a go statement. |
606 func HandleHTTP() { | 606 func HandleHTTP() { |
607 DefaultServer.HandleHTTP(DefaultRPCPath, DefaultDebugPath) | 607 DefaultServer.HandleHTTP(DefaultRPCPath, DefaultDebugPath) |
608 } | 608 } |
LEFT | RIGHT |