Exemplo n.º 1
0
func setLinger(fd int, sec int) error {
	var l syscall.Linger
	if sec >= 0 {
		l.Onoff = 1
		l.Linger = int32(sec)
	} else {
		l.Onoff = 0
		l.Linger = 0
	}
	return os.NewSyscallError("setsockopt", syscall.SetsockoptLinger(fd, syscall.SOL_SOCKET, syscall.SO_LINGER, &l))
}
Exemplo n.º 2
0
Arquivo: sock.go Projeto: 8l/go-learn
func setLinger(fd *netFD, sec int) os.Error {
	var l syscall.Linger
	if sec >= 0 {
		l.Onoff = 1
		l.Linger = int32(sec)
	} else {
		l.Onoff = 0
		l.Linger = 0
	}
	e := syscall.SetsockoptLinger(fd.fd, syscall.SOL_SOCKET, syscall.SO_LINGER, &l)
	return os.NewSyscallError("setsockopt", e)
}
Exemplo n.º 3
0
func setLinger(fd *netFD, sec int) error {
	var l syscall.Linger
	if sec >= 0 {
		l.Onoff = 1
		l.Linger = int32(sec)
	} else {
		l.Onoff = 0
		l.Linger = 0
	}
	fd.incref()
	defer fd.decref()
	return os.NewSyscallError("setsockopt", syscall.SetsockoptLinger(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_LINGER, &l))
}
Exemplo n.º 4
0
func setLinger(fd *netFD, sec int) error { // 设置Linger
	var l syscall.Linger // 声明Linger结构
	if sec >= 0 {        // sec大于等于0,开启Linger
		l.Onoff = 1
		l.Linger = int32(sec)
	} else { // sec小于0,关闭Linger
		l.Onoff = 0
		l.Linger = 0
	}
	if err := fd.incref(); err != nil { // 先增加fd的引用计数
		return err
	}
	defer fd.decref() // 设置完成后减小fd的引用计数
	return os.NewSyscallError("setsockopt", syscall.SetsockoptLinger(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_LINGER, &l))
}