From 2e2d67c967a4a03936ede9c474a8d42739215271 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Fri, 20 May 2016 03:42:57 +0000 Subject: server: make active md5ed socket nonblocking Signed-off-by: ISHIDA Wataru --- server/sockopt_linux.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/sockopt_linux.go b/server/sockopt_linux.go index 4a68a18d..c764eb04 100644 --- a/server/sockopt_linux.go +++ b/server/sockopt_linux.go @@ -69,7 +69,7 @@ func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec } la = j } - sotype := syscall.SOCK_STREAM | syscall.SOCK_CLOEXEC + sotype := syscall.SOCK_STREAM | syscall.SOCK_CLOEXEC | syscall.SOCK_NONBLOCK proto := 0 fd, err := syscall.Socket(family, sotype, proto) if err != nil { @@ -87,6 +87,7 @@ func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec uintptr(unsafe.Pointer(&t)), unsafe.Sizeof(t), 0); e > 0 { return nil, os.NewSyscallError("setsockopt", e) } + if err = syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1); err != nil { return nil, os.NewSyscallError("setsockopt", err) } @@ -121,7 +122,7 @@ func DialTCPTimeoutWithMD5Sig(host string, port int, localAddr, key string, msec var event syscall.EpollEvent events := make([]syscall.EpollEvent, 1) - event.Events = syscall.EPOLLIN + event.Events = syscall.EPOLLIN | syscall.EPOLLOUT | syscall.EPOLLPRI event.Fd = int32(fd) if e = syscall.EpollCtl(epfd, syscall.EPOLL_CTL_ADD, fd, &event); e != nil { return nil, e -- cgit v1.2.3