Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6)

Delta Between Two Patch Sets: state/apiserver/server.go

Issue 9410043: rpc: refactor
Left Patch Set: Created 11 years, 11 months ago
Right Patch Set: rpc: refactor Created 11 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « state/apiserver/apiserver.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package apiserver 4 package apiserver
5 5
6 import ( 6 import (
7 "code.google.com/p/go.net/websocket" 7 "code.google.com/p/go.net/websocket"
8 "crypto/tls" 8 "crypto/tls"
9 "launchpad.net/juju-core/log" 9 "launchpad.net/juju-core/log"
10 "launchpad.net/juju-core/rpc" 10 "launchpad.net/juju-core/rpc"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // If we've got to this stage and the tomb is still 77 // If we've got to this stage and the tomb is still
78 // alive, we know that any tomb.Kill must occur after we 78 // alive, we know that any tomb.Kill must occur after we
79 // have called wg.Add, so we avoid the possibility of a 79 // have called wg.Add, so we avoid the possibility of a
80 // handler goroutine running after Stop has returned. 80 // handler goroutine running after Stop has returned.
81 if srv.tomb.Err() != tomb.ErrStillAlive { 81 if srv.tomb.Err() != tomb.ErrStillAlive {
82 return 82 return
83 } 83 }
84 if err := srv.serveConn(conn); err != nil { 84 if err := srv.serveConn(conn); err != nil {
85 log.Errorf("state/api: error serving RPCs: %v", err) 85 log.Errorf("state/api: error serving RPCs: %v", err)
86 } 86 }
87 log.Infof("serveConn done")
88 }) 87 })
89 // The error from http.Serve is not interesting. 88 // The error from http.Serve is not interesting.
90 http.Serve(lis, handler) 89 http.Serve(lis, handler)
91 } 90 }
92 91
93 // Addr returns the address that the server is listening on. 92 // Addr returns the address that the server is listening on.
94 func (srv *Server) Addr() string { 93 func (srv *Server) Addr() string {
95 return srv.addr.String() 94 return srv.addr.String()
96 } 95 }
97 96
98 func (srv *Server) serveConn(wsConn *websocket.Conn) error { 97 func (srv *Server) serveConn(wsConn *websocket.Conn) error {
99 » codec := jsoncodec.NewWS(wsConn) 98 » conn := rpc.NewConn(jsoncodec.NewWebsocket(wsConn))
100 » conn, err := rpc.NewServer(codec, newStateServer(srv), serverError) 99 » if err := conn.Serve(newStateServer(srv), serverError); err != nil {
101 » if err != nil {
102 return err 100 return err
103 } 101 }
102 conn.Start()
104 select { 103 select {
105 case <-conn.Dead(): 104 case <-conn.Dead():
106 case <-srv.tomb.Dying(): 105 case <-srv.tomb.Dying():
107 log.Infof("Server.serveConn saw dying")
108 } 106 }
109 » log.Infof("closing conn") 107 » return conn.Close()
110 » err = conn.Close()
111 » log.Infof("closed conn: %v", err)
112 » return err
113 } 108 }
114 109
115 var logRequests = true 110 var logRequests = true
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b