forked from panjf2000/gnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacceptor_unix.go
More file actions
34 lines (30 loc) · 759 Bytes
/
Copy pathacceptor_unix.go
File metadata and controls
34 lines (30 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2019 Andy Pan. All rights reserved.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
// +build linux darwin netbsd freebsd openbsd dragonfly
package gnet
import "golang.org/x/sys/unix"
func (svr *server) acceptNewConnection(fd int) error {
nfd, sa, err := unix.Accept(fd)
if err != nil {
if err == unix.EAGAIN {
return nil
}
return err
}
if err := unix.SetNonblock(nfd, true); err != nil {
return err
}
el := svr.subLoopGroup.next(nfd)
c := newTCPConn(nfd, el, sa)
_ = el.poller.Trigger(func() (err error) {
if err = el.poller.AddRead(nfd); err != nil {
return
}
el.connections[nfd] = c
el.plusConnCount()
err = el.loopOpen(c)
return
})
return nil
}