init initializes the connection with options
(conn Conn, opts *options)
| 376 | |
| 377 | // init initializes the connection with options |
| 378 | func (c *connection) init(conn Conn, opts *options) (err error) { |
| 379 | // init buffer, barrier, finalizer |
| 380 | c.readTrigger = make(chan error, 1) |
| 381 | c.writeTrigger = make(chan error, 1) |
| 382 | c.bookSize, c.maxSize = defaultLinkBufferSize, defaultLinkBufferSize |
| 383 | c.inputBuffer, c.outputBuffer = NewLinkBuffer(defaultLinkBufferSize), NewLinkBuffer() |
| 384 | c.outputBarrier = barrierPool.Get().(*barrier) |
| 385 | c.state = connStateNone |
| 386 | |
| 387 | c.initNetFD(conn) // conn must be *netFD{} |
| 388 | c.initFDOperator() |
| 389 | c.initFinalizer() |
| 390 | |
| 391 | syscall.SetNonblock(c.fd, true) |
| 392 | // enable TCP_NODELAY by default |
| 393 | switch c.network { |
| 394 | case "tcp", "tcp4", "tcp6": |
| 395 | setTCPNoDelay(c.fd, true) |
| 396 | } |
| 397 | |
| 398 | // connection initialized and prepare options |
| 399 | return c.onPrepare(opts) |
| 400 | } |
| 401 | |
| 402 | func (c *connection) initNetFD(conn Conn) { |
| 403 | if nfd, ok := conn.(*netFD); ok { |