MCPcopy
hub / github.com/gorilla/websocket / newConn

Function newConn

conn.go:285–324  ·  view source on GitHub ↗
(conn net.Conn, isServer bool, readBufferSize, writeBufferSize int, writeBufferPool BufferPool, br *bufio.Reader, writeBuf []byte)

Source from the content-addressed store, hash-verified

283}
284
285func newConn(conn net.Conn, isServer bool, readBufferSize, writeBufferSize int, writeBufferPool BufferPool, br *bufio.Reader, writeBuf []byte) *Conn {
286
287 if br == nil {
288 if readBufferSize == 0 {
289 readBufferSize = defaultReadBufferSize
290 } else if readBufferSize < maxControlFramePayloadSize {
291 // must be large enough for control frame
292 readBufferSize = maxControlFramePayloadSize
293 }
294 br = bufio.NewReaderSize(conn, readBufferSize)
295 }
296
297 if writeBufferSize <= 0 {
298 writeBufferSize = defaultWriteBufferSize
299 }
300 writeBufferSize += maxFrameHeaderSize
301
302 if writeBuf == nil && writeBufferPool == nil {
303 writeBuf = make([]byte, writeBufferSize)
304 }
305
306 mu := make(chan struct{}, 1)
307 mu <- struct{}{}
308 c := &Conn{
309 isServer: isServer,
310 br: br,
311 conn: conn,
312 mu: mu,
313 readFinal: true,
314 writeBuf: writeBuf,
315 writePool: writeBufferPool,
316 writeBufSize: writeBufferSize,
317 enableWriteCompression: true,
318 compressionLevel: defaultCompressionLevel,
319 }
320 c.SetCloseHandler(nil)
321 c.SetPingHandler(nil)
322 c.SetPongHandler(nil)
323 return c
324}
325
326// setReadRemaining tracks the number of bytes remaining on the connection. If n
327// overflows, an ErrReadLimit is returned.

Callers 12

newTestConnFunction · 0.85
TestWriteBufferPoolFunction · 0.85
TestWriteBufferPoolSyncFunction · 0.85
TestWriteBufferPoolErrorFunction · 0.85
TestEOFBeforeFinalFrameFunction · 0.85
TestReadLimitFunction · 0.85
TestNetConnFunction · 0.85
TestBufioReadBytesFunction · 0.85
UpgradeMethod · 0.85
DialContextMethod · 0.85

Calls 3

SetCloseHandlerMethod · 0.95
SetPingHandlerMethod · 0.95
SetPongHandlerMethod · 0.95

Tested by 10

newTestConnFunction · 0.68
TestWriteBufferPoolFunction · 0.68
TestWriteBufferPoolSyncFunction · 0.68
TestWriteBufferPoolErrorFunction · 0.68
TestEOFBeforeFinalFrameFunction · 0.68
TestReadLimitFunction · 0.68
TestNetConnFunction · 0.68
TestBufioReadBytesFunction · 0.68