LEFT | RIGHT |
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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 server.sendResponse(sending, req, invalidRequest
, codec, err.String()) | 407 server.sendResponse(sending, req, invalidRequest
, codec, err.String()) |
408 server.freeRequest(req) | 408 server.freeRequest(req) |
409 } | 409 } |
410 continue | 410 continue |
411 } | 411 } |
412 go service.call(server, sending, mtype, req, argv, replyv, codec
) | 412 go service.call(server, sending, mtype, req, argv, replyv, codec
) |
413 } | 413 } |
414 codec.Close() | 414 codec.Close() |
415 } | 415 } |
416 | 416 |
417 // ServeSingle is like ServeCodec but synchronously serves a single request | 417 // ServeRequest is like ServeCodec but synchronously serves a single request. |
418 // without launching a goroutine. It does not close the codec upon completion. | 418 // It does not close the codec upon completion. |
419 func (server *Server) ServeSingle(codec ServerCodec) os.Error { | 419 func (server *Server) ServeRequest(codec ServerCodec) os.Error { |
420 sending := new(sync.Mutex) | 420 sending := new(sync.Mutex) |
421 service, mtype, req, argv, replyv, err := server.readRequest(codec) | 421 service, mtype, req, argv, replyv, err := server.readRequest(codec) |
422 if err != nil { | 422 if err != nil { |
423 if err == os.EOF || err == io.ErrUnexpectedEOF { | 423 if err == os.EOF || err == io.ErrUnexpectedEOF { |
424 return err | 424 return err |
425 } | 425 } |
426 // send a response if we actually managed to read a header. | 426 // send a response if we actually managed to read a header. |
427 if req != nil { | 427 if req != nil { |
428 server.sendResponse(sending, req, invalidRequest, codec,
err.String()) | 428 server.sendResponse(sending, req, invalidRequest, codec,
err.String()) |
429 server.freeRequest(req) | 429 server.freeRequest(req) |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 func ServeConn(conn io.ReadWriteCloser) { | 583 func ServeConn(conn io.ReadWriteCloser) { |
584 DefaultServer.ServeConn(conn) | 584 DefaultServer.ServeConn(conn) |
585 } | 585 } |
586 | 586 |
587 // ServeCodec is like ServeConn but uses the specified codec to | 587 // ServeCodec is like ServeConn but uses the specified codec to |
588 // decode requests and encode responses. | 588 // decode requests and encode responses. |
589 func ServeCodec(codec ServerCodec) { | 589 func ServeCodec(codec ServerCodec) { |
590 DefaultServer.ServeCodec(codec) | 590 DefaultServer.ServeCodec(codec) |
591 } | 591 } |
592 | 592 |
593 // ServeSingle is like ServeCodec but synchronously serves a single request | 593 // ServeRequest is like ServeCodec but synchronously serves a single request. |
594 // without launching a goroutine. It does not close the codec upon completion. | 594 // It does not close the codec upon completion. |
595 func ServeSingle(codec ServerCodec) os.Error { | 595 func ServeRequest(codec ServerCodec) os.Error { |
596 » return DefaultServer.ServeSingle(codec) | 596 » return DefaultServer.ServeRequest(codec) |
597 } | 597 } |
598 | 598 |
599 // Accept accepts connections on the listener and serves requests | 599 // Accept accepts connections on the listener and serves requests |
600 // to DefaultServer for each incoming connection.·· | 600 // to DefaultServer for each incoming connection.·· |
601 // Accept blocks; the caller typically invokes it in a go statement. | 601 // Accept blocks; the caller typically invokes it in a go statement. |
602 func Accept(lis net.Listener) { DefaultServer.Accept(lis) } | 602 func Accept(lis net.Listener) { DefaultServer.Accept(lis) } |
603 | 603 |
604 // Can connect to RPC service using HTTP CONNECT to rpcPath. | 604 // Can connect to RPC service using HTTP CONNECT to rpcPath. |
605 var connected = "200 Connected to Go RPC" | 605 var connected = "200 Connected to Go RPC" |
606 | 606 |
(...skipping 21 matching lines...) Expand all Loading... |
628 http.Handle(rpcPath, server) | 628 http.Handle(rpcPath, server) |
629 http.Handle(debugPath, debugHTTP{server}) | 629 http.Handle(debugPath, debugHTTP{server}) |
630 } | 630 } |
631 | 631 |
632 // HandleHTTP registers an HTTP handler for RPC messages to DefaultServer | 632 // HandleHTTP registers an HTTP handler for RPC messages to DefaultServer |
633 // on DefaultRPCPath and a debugging handler on DefaultDebugPath. | 633 // on DefaultRPCPath and a debugging handler on DefaultDebugPath. |
634 // It is still necessary to invoke http.Serve(), typically in a go statement. | 634 // It is still necessary to invoke http.Serve(), typically in a go statement. |
635 func HandleHTTP() { | 635 func HandleHTTP() { |
636 DefaultServer.HandleHTTP(DefaultRPCPath, DefaultDebugPath) | 636 DefaultServer.HandleHTTP(DefaultRPCPath, DefaultDebugPath) |
637 } | 637 } |
LEFT | RIGHT |