MCPcopy Index your code
hub / github.com/coder/websocket / init

Method init

ws_js.go:82–125  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

80}
81
82func (c *Conn) init() {
83 c.closed = make(chan struct{})
84 c.readSignal = make(chan struct{}, 1)
85
86 c.msgReadLimit.Store(32768)
87
88 c.releaseOnClose = c.ws.OnClose(func(e wsjs.CloseEvent) {
89 err := CloseError{
90 Code: StatusCode(e.Code),
91 Reason: e.Reason,
92 }
93 // We do not know if we sent or received this close as
94 // its possible the browser triggered it without us
95 // explicitly sending it.
96 c.close(err, e.WasClean)
97
98 c.releaseOnClose()
99 c.releaseOnError()
100 c.releaseOnMessage()
101 })
102
103 c.releaseOnError = c.ws.OnError(func(v js.Value) {
104 c.setCloseErr(errors.New(v.Get("message").String()))
105 c.closeWithInternal()
106 })
107
108 c.releaseOnMessage = c.ws.OnMessage(func(e wsjs.MessageEvent) {
109 c.readBufMu.Lock()
110 defer c.readBufMu.Unlock()
111
112 c.readBuf = append(c.readBuf, e)
113
114 // Lets the read goroutine know there is definitely something in readBuf.
115 select {
116 case c.readSignal <- struct{}{}:
117 default:
118 }
119 })
120
121 runtime.SetFinalizer(c, func(c *Conn) {
122 c.setCloseErr(errors.New("connection garbage collected"))
123 c.closeWithInternal()
124 })
125}
126
127func (c *Conn) closeWithInternal() {
128 c.Close(StatusInternalError, "something went wrong")

Callers 2

dialFunction · 0.95
resetFlateMethod · 0.45

Calls 9

closeMethod · 0.95
setCloseErrMethod · 0.95
closeWithInternalMethod · 0.95
OnCloseMethod · 0.80
OnErrorMethod · 0.80
OnMessageMethod · 0.80
StatusCodeTypeAlias · 0.70
StringMethod · 0.45
LockMethod · 0.45

Tested by

no test coverage detected