MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / Serve

Method Serve

rpc/jsonrpc/websocket.go:24–60  ·  view source on GitHub ↗

Serve accepts incoming connections and serve each.

()

Source from the content-addressed store, hash-verified

22
23// Serve accepts incoming connections and serve each.
24func (ws *WebsocketServer) Serve() error {
25 var (
26 mux = http.NewServeMux()
27 upgrader = websocket.Upgrader{CheckOrigin: func(r *http.Request) bool { return true }}
28 handler = ws.RPCHandler
29 )
30
31 if handler == nil {
32 handler = defaultHandler
33 }
34
35 mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
36 conn, err := upgrader.Upgrade(rw, r, nil)
37 if err != nil {
38 log.WithError(err).Error("jsonrpc: upgrade http connection to websocket failed")
39 http.Error(rw, errors.WithMessage(err, "could not upgrade to websocket").Error(), http.StatusBadRequest)
40 return
41 }
42 defer conn.Close()
43
44 // TODO: add metric for the connections
45 <-jsonrpc2.NewConn(
46 context.Background(),
47 wsstream.NewObjectStream(conn),
48 handler,
49 ).DisconnectNotify()
50 })
51
52 addr := ws.Addr
53 listener, err := net.Listen("tcp", addr)
54 if err != nil {
55 return errors.Wrapf(err, "couldn't bind to address %q", addr)
56 }
57
58 ws.Handler = mux
59 return ws.Server.Serve(listener)
60}
61
62// Stop stops the server and returns a channel indicating server is stopped.
63func (ws *WebsocketServer) Stop() {

Callers 14

TestRawCallerFunction · 0.45
TestIncCounterFunction · 0.45
TestIncCounterSimpleArgsFunction · 0.45
TestETLSBugFunction · 0.45
TestEncPingFindNeighborFunction · 0.45
BenchmarkSessionPool_GetFunction · 0.45
TestNewSessionPoolFunction · 0.45
TestCaller_CallNodeFunction · 0.45
TestNewPersistentCallerFunction · 0.45

Calls 3

WithErrorFunction · 0.92
ErrorMethod · 0.80
CloseMethod · 0.65

Tested by 12

TestRawCallerFunction · 0.36
TestIncCounterFunction · 0.36
TestIncCounterSimpleArgsFunction · 0.36
TestETLSBugFunction · 0.36
TestEncPingFindNeighborFunction · 0.36
BenchmarkSessionPool_GetFunction · 0.36
TestNewSessionPoolFunction · 0.36
TestCaller_CallNodeFunction · 0.36
TestNewPersistentCallerFunction · 0.36