package sipc_conn import ( "net" ) type Server struct { isUnix bool serverPath string ctx ServerCtx listener net.Listener connErrorHandler ConnErrorHandler connHandler ConnHandler quitChan chan int } func (s *Server) GetPath() string { return s.serverPath } func (s *Server) IsUnix() bool { return s.isUnix } func (s *Server) IsWindows() bool { return !s.isUnix } func (s *Server) SetConnErrorHandler(handler ConnErrorHandler) { s.connErrorHandler = handler } func (s *Server) SetConnHandler(handler ConnHandler) { s.connHandler = handler } type ConnErrorHandler func(err error) type ConnHandler func(conn net.Conn) func defaultConnErrHandler(err error) {} func defaultConnHandler(conn net.Conn) { conn.Close() } func (s *Server) doAccept() { for { conn, err := s.listener.Accept() select { default: case <-s.quitChan: return } if err != nil { go s.connErrorHandler(err) } else { go s.connHandler(conn) } } } func (s *Server) Stop() error { close(s.quitChan) if s.listener != nil { return s.listener.Close() } return nil }