func (bt *Bluetooth) Accept() (*Bluetooth, error) {
	mu.Lock()
	defer mu.Unlock()
	var nFd int
	var rAddr *SockaddrL2
	fds := &FdSet{Bits: [32]int32{0}}
	setFd(bt.fd, fds)
	for {
		var raddr RawSockaddrL2
		var addrlen _Socklen = _Socklen(unsafe.Sizeof(RawSockaddrL2{}))
		rFd, _, err := unix.Syscall(unix.SYS_ACCEPT, uintptr(bt.fd), uintptr(unsafe.Pointer(&raddr)), uintptr(unsafe.Pointer(&addrlen)))
		if err != 0 {
			switch err {
			case syscall.EAGAIN:
				time.Sleep(1 * time.Millisecond)
				continue
			case syscall.ECONNABORTED:
				continue
			}
			btlog.Debug("Accept: Socket Error", err)
			unix.Close(int(rFd))
			return nil, err
		}
		nFd = int(rFd)
		rAddr = &SockaddrL2{
			PSM:    raddr.Psm,
			Bdaddr: raddr.Bdaddr,
		}
		break
	}
	btlog.Debug("Remote Address Info", rAddr)
	rbt := &Bluetooth{
		family: bt.family,
		typ:    bt.typ,
		proto:  bt.proto,
		block:  bt.block,
		fd:     nFd,
		saddr:  *rAddr,
	}
	unix.CloseOnExec(nFd)
	btlog.Debug("Accept closeonexec")
	if err := rbt.SetBlocking(false); err != nil {
		_err := bt.Close()
		_err = rbt.Close()
		btlog.Debug(_err, "SetBlocking", err)
		return nil, err
	}
	btlog.Debug("Accepted Socket could set blocking mode")
	return rbt, nil
}
Accepts on listening socket and return received connection
package bluetooth
import (
	"fmt"
	"sync"
	"syscall"
	"time"
	"unsafe"
	btlog "github.com/potch8228/gobt/log"
	"golang.org/x/sys/unix"
)
type _Socklen uint32
type RawSockaddrL2 struct {
	Family uint16
	Psm    uint16
	Bdaddr [6]uint8
}
type SockaddrL2 struct {
	PSM    uint16
	Bdaddr [6]uint8
	raw    RawSockaddrL2
}
func (sa *SockaddrL2) sockaddr() (unsafe.Pointer, _Socklen, error) {
	sa.raw.Family = unix.AF_BLUETOOTH
	sa.raw.Psm = uint16(sa.PSM)
	sa.raw.Bdaddr = sa.Bdaddr
	return unsafe.Pointer(&sa.raw), _Socklen(unsafe.Sizeof(RawSockaddrL2{})), nil
}
func (sa *SockaddrL2) String() string {
	return fmt.Sprintf("[PSM: %d, Bdaddr: %v]", sa.PSM, sa.Bdaddr)
}
const (
	PSMCTRL = 0x11
	PSMINTR = 0x13
	BUFSIZE = 1024
	FDBITS = 32
)
var mu sync.Mutex
type FdSet struct {
	Bits [32]int32
}
func setFd(fd int, fdset *FdSet) {
	mask := uint(1) << (uint(fd) % uint(FDBITS))
	fdset.Bits[fd/FDBITS] |= int32(mask)
}
func isSetFd(fd int, fdset *FdSet) bool {
	mask := uint(1) << (uint(fd) % uint(FDBITS))
	return ((fdset.Bits[fd/FDBITS] & int32(mask)) != 0)
}
type Bluetooth struct {
	fd     int
	family int
	proto  int
	typ    int
	saddr  SockaddrL2
	block bool
	mu    sync.Mutex
}
func (bt *Bluetooth) SetBlocking(block bool) error {
	bt.mu.Lock()
	defer bt.mu.Unlock()
	dFlgPtr, _, err := unix.Syscall(unix.SYS_FCNTL, uintptr(bt.fd), unix.F_GETFL, 0)
	if err != 0 {
		btlog.Debug("Error SetBlocking set state", err)
		return err
	}
	var delayFlag uint
	if block {
		delayFlag = uint(dFlgPtr) & (^(uint)(unix.O_NONBLOCK))
	} else {
		delayFlag = uint(dFlgPtr) | ((uint)(unix.O_NONBLOCK))
	}
	_, _, err = unix.Syscall(unix.SYS_FCNTL, uintptr(bt.fd), unix.F_SETFL, uintptr(delayFlag))
	if err != 0 {
		btlog.Debug("Error SetBlocking set state", err)
		return err
	}
	return nil
}
func NewBluetoothSocket(fd int) (*Bluetooth, error) {
	bt := &Bluetooth{
		fd:     fd,
		family: unix.AF_BLUETOOTH,
		typ:    unix.SOCK_SEQPACKET,
		proto:  unix.BTPROTO_L2CAP,
		block:  false,
	}
	var rsa RawSockaddrL2
	var addrlen _Socklen = _Socklen(unsafe.Sizeof(RawSockaddrL2{}))
	_, _, err := unix.RawSyscall(unix.SYS_GETSOCKNAME, uintptr(fd), uintptr(unsafe.Pointer(&rsa)), uintptr(unsafe.Pointer(&addrlen)))
	if int(err) != 0 {
		btlog.Debug("Failure on getsockname", err)
		unix.Close(fd)
		return nil, err
	}
	bt.saddr = SockaddrL2{
		PSM:    rsa.Psm,
		Bdaddr: rsa.Bdaddr,
	}
	btlog.Debug("Resolved sockname", bt.saddr, "New Socket is created")
	return bt, nil
}
func Listen(psm uint, bklen int, block bool) (*Bluetooth, error) {
	mu.Lock()
	defer mu.Unlock()
	bt := &Bluetooth{
		family: unix.AF_BLUETOOTH,
		typ:    unix.SOCK_SEQPACKET,  
		proto:  unix.BTPROTO_L2CAP,
		block:  block,
	}
	fd, err := unix.Socket(bt.family, bt.typ, bt.proto)
	if err != nil {
		btlog.Debug("Socket could not be created", err)
		return nil, err
	}
	btlog.Debug("Socket is created")
	bt.fd = fd
	unix.CloseOnExec(bt.fd)
	if err := bt.SetBlocking(block); err != nil {
		_err := bt.Close()
		btlog.Debug("SetBlocking", _err, err)
		return nil, err
	}
	btlog.Debug("Socket is set blocking mode")
	addr := SockaddrL2{
		PSM:    uint16(psm),
		Bdaddr: [6]uint8{0},
	}
	bt.saddr = addr
	saddr, saddrlen, err := addr.sockaddr()
	if _, _, err := unix.Syscall(unix.SYS_BIND, uintptr(bt.fd), uintptr(saddr), uintptr(saddrlen)); int(err) != 0 {
		switch int(err) {
		case 0:
		default:
			_err := bt.Close()
			btlog.Debug("Failure on Binding Socket", _err, err)
			return nil, err
		}
	}
	btlog.Debug("Socket is binded")
	if err := unix.Listen(bt.fd, bklen); err != nil {
		_err := bt.Close()
		btlog.Debug(_err)
		return nil, err
	}
	btlog.Debug("Socket is listening")
	return bt, nil
}