| 283 | } |
| 284 | |
| 285 | func 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. |