Example #1
0
func (us *UnixSock) Accept(l *net.UnixListener) {
	// Why doesn't this get called on ctrl + c
	defer l.Close()

	for {
		fd, err := l.Accept()
		if err != nil {
			break
		}
		us.processBuffer(fd)
	}
}
Example #2
0
func listen(sock *net.UnixListener, logChan chan []byte) {
	defer sock.Close()
	defer wg.Done()
	// Timeout after 2 seconds
	sock.SetDeadline(time.Now().Add((2 * time.Second)))
	for run {
		client, err := sock.Accept()
		if err != nil {
			ne, ok := err.(net.Error)
			if !ok || !ne.Temporary() {
				// Non-temporary (fatal) error
				log.Printf("Error accepting client:\n%v", err)
				break
			}
		} else {
			wg.Add(1)
			go handle(client, logChan)
		}
	}
}
Example #3
0
// Run the server's accept loop, waiting for connections from l.
// Correct shutdown procedure is:
// set slots to a number such that no new processes will run
// wait for all running processes to finish
// set shittingDown to true
// close the listening socket
func Run(v *viper.Viper, l *net.UnixListener) {
	i := newInstance(v)
	i.listener = l
	for {
		c, err := l.AcceptUnix()
		i.m.Lock()
		sdc := i.shutdownComplete
		i.m.Unlock()
		if sdc {
			glog.Infoln("Shutdown complete. closing listener.")
			if c != nil {
				c.Close()
			}
			l.Close()
			return
		} else if err != nil {
			glog.Errorln("Accept() failed on unix socket:", err)
			return
		}
		go i.connectionHandler(c)
	}
}