diff options
author | Ian Lance Taylor <iant@google.com> | 2011-01-21 18:19:03 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-01-21 18:19:03 +0000 |
commit | ff5f50c52c421d75940ef9392211e3ab24d71332 (patch) | |
tree | 27d8768fb1d25696d3c40b42535eb5e073c278da /libgo/go/rpc | |
parent | d6ed1c8903e728f4233122554bab5910853338bd (diff) | |
download | gcc-ff5f50c52c421d75940ef9392211e3ab24d71332.zip gcc-ff5f50c52c421d75940ef9392211e3ab24d71332.tar.gz gcc-ff5f50c52c421d75940ef9392211e3ab24d71332.tar.bz2 |
Remove the types float and complex.
Update to current version of Go library.
Update testsuite for removed types.
* go-lang.c (go_langhook_init): Omit float_type_size when calling
go_create_gogo.
* go-c.h: Update declaration of go_create_gogo.
From-SVN: r169098
Diffstat (limited to 'libgo/go/rpc')
-rw-r--r-- | libgo/go/rpc/debug.go | 26 | ||||
-rw-r--r-- | libgo/go/rpc/server.go | 48 |
2 files changed, 48 insertions, 26 deletions
diff --git a/libgo/go/rpc/debug.go b/libgo/go/rpc/debug.go index 6bd8a91..44b32e0 100644 --- a/libgo/go/rpc/debug.go +++ b/libgo/go/rpc/debug.go @@ -21,14 +21,14 @@ const debugText = `<html> <title>Services</title> {.repeated section @} <hr> - Service {name} + Service {Name} <hr> <table> <th align=center>Method</th><th align=center>Calls</th> - {.repeated section meth} + {.repeated section Method} <tr> - <td align=left font=fixed>{name}({m.argType}, {m.replyType}) os.Error</td> - <td align=center>{m.numCalls}</td> + <td align=left font=fixed>{Name}({Type.ArgType}, {Type.ReplyType}) os.Error</td> + <td align=center>{Type.NumCalls}</td> </tr> {.end} </table> @@ -39,26 +39,26 @@ const debugText = `<html> var debug = template.MustParse(debugText, nil) type debugMethod struct { - m *methodType - name string + Type *methodType + Name string } type methodArray []debugMethod type debugService struct { - s *service - name string - meth methodArray + Service *service + Name string + Method methodArray } type serviceArray []debugService func (s serviceArray) Len() int { return len(s) } -func (s serviceArray) Less(i, j int) bool { return s[i].name < s[j].name } +func (s serviceArray) Less(i, j int) bool { return s[i].Name < s[j].Name } func (s serviceArray) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (m methodArray) Len() int { return len(m) } -func (m methodArray) Less(i, j int) bool { return m[i].name < m[j].name } +func (m methodArray) Less(i, j int) bool { return m[i].Name < m[j].Name } func (m methodArray) Swap(i, j int) { m[i], m[j] = m[j], m[i] } type debugHTTP struct { @@ -75,10 +75,10 @@ func (server debugHTTP) ServeHTTP(w http.ResponseWriter, req *http.Request) { services[i] = debugService{service, sname, make(methodArray, len(service.method))} j := 0 for mname, method := range service.method { - services[i].meth[j] = debugMethod{method, mname} + services[i].Method[j] = debugMethod{method, mname} j++ } - sort.Sort(services[i].meth) + sort.Sort(services[i].Method) i++ } server.Unlock() diff --git a/libgo/go/rpc/server.go b/libgo/go/rpc/server.go index dbb68dd..5c50bcc 100644 --- a/libgo/go/rpc/server.go +++ b/libgo/go/rpc/server.go @@ -137,8 +137,8 @@ var typeOfOsError = reflect.Typeof(unusedError).(*reflect.PtrType).Elem() type methodType struct { sync.Mutex // protects counters method reflect.Method - argType *reflect.PtrType - replyType *reflect.PtrType + ArgType *reflect.PtrType + ReplyType *reflect.PtrType numCalls uint } @@ -199,7 +199,19 @@ func isExported(name string) bool { // - one return value, of type os.Error // It returns an error if the receiver is not an exported type or has no // suitable methods. +// The client accesses each method using a string of the form "Type.Method", +// where Type is the receiver's concrete type. func (server *Server) Register(rcvr interface{}) os.Error { + return server.register(rcvr, "", false) +} + +// RegisterName is like Register but uses the provided name for the type +// instead of the receiver's concrete type. +func (server *Server) RegisterName(name string, rcvr interface{}) os.Error { + return server.register(rcvr, name, true) +} + +func (server *Server) register(rcvr interface{}, name string, useName bool) os.Error { server.Lock() defer server.Unlock() if server.serviceMap == nil { @@ -209,10 +221,13 @@ func (server *Server) Register(rcvr interface{}) os.Error { s.typ = reflect.Typeof(rcvr) s.rcvr = reflect.NewValue(rcvr) sname := reflect.Indirect(s.rcvr).Type().Name() + if useName { + sname = name + } if sname == "" { log.Exit("rpc: no service name for type", s.typ.String()) } - if s.typ.PkgPath() != "" && !isExported(sname) { + if s.typ.PkgPath() != "" && !isExported(sname) && !useName { s := "rpc Register: type " + sname + " is not exported" log.Print(s) return os.ErrorString(s) @@ -270,7 +285,7 @@ func (server *Server) Register(rcvr interface{}) os.Error { log.Println("method", mname, "returns", returnType.String(), "not os.Error") continue } - s.method[mname] = &methodType{method: method, argType: argType, replyType: replyType} + s.method[mname] = &methodType{method: method, ArgType: argType, ReplyType: replyType} } if len(s.method) == 0 { @@ -311,6 +326,13 @@ func sendResponse(sending *sync.Mutex, req *Request, reply interface{}, codec Se sending.Unlock() } +func (m *methodType) NumCalls() (n uint) { + m.Lock() + n = m.numCalls + m.Unlock() + return n +} + func (s *service) call(sending *sync.Mutex, mtype *methodType, req *Request, argv, replyv reflect.Value, codec ServerCodec) { mtype.Lock() mtype.numCalls++ @@ -403,8 +425,8 @@ func (server *Server) ServeCodec(codec ServerCodec) { continue } // Decode the argument value. - argv := _new(mtype.argType) - replyv := _new(mtype.replyType) + argv := _new(mtype.ArgType) + replyv := _new(mtype.ReplyType) err = codec.ReadRequestBody(argv.Interface()) if err != nil { log.Println("rpc: tearing down", serviceMethod[0], "connection:", err) @@ -429,15 +451,15 @@ func (server *Server) Accept(lis net.Listener) { } } -// Register publishes in the DefaultServer the set of methods -// of the receiver value that satisfy the following conditions: -// - exported method -// - two arguments, both pointers to exported structs -// - one return value, of type os.Error -// It returns an error if the receiver is not an exported type or has no -// suitable methods. +// Register publishes the receiver's methods in the DefaultServer. func Register(rcvr interface{}) os.Error { return DefaultServer.Register(rcvr) } +// RegisterName is like Register but uses the provided name for the type +// instead of the receiver's concrete type. +func RegisterName(name string, rcvr interface{}) os.Error { + return DefaultServer.RegisterName(name, rcvr) +} + // A ServerCodec implements reading of RPC requests and writing of // RPC responses for the server side of an RPC session. // The server calls ReadRequestHeader and ReadRequestBody in pairs |