Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible to do a reuse port option? #64

Open
kolinfluence opened this issue May 26, 2023 · 3 comments
Open

possible to do a reuse port option? #64

kolinfluence opened this issue May 26, 2023 · 3 comments

Comments

@kolinfluence
Copy link

kolinfluence commented May 26, 2023

possible to do a reuse port option?

how do i modify the code for reuse port to work?

@kolinfluence
Copy link
Author

@tidwall i've modified the code for reuse port to work BUT it's not elegant.

  1. can u pls standardize it into the package?
  2. also can u also add context to it?
  3. can i buy u a coffee for doing those 2 above?

been using this package and i can only say it's great! thx!

@tidwall
Copy link
Owner

tidwall commented May 27, 2023

Sorry, but unfortunately I don't have the available time necessary to dedicate to new features for this project.

@kolinfluence
Copy link
Author

kolinfluence commented May 27, 2023

@tidwall i have done the below coding.
would like your guidance on how u would like call the reuse port and "add context" in.
to add the feature is 15-20 mins of ur time.
if u find the time in any coffee breaks, do hope to see it implemented.

only needing to add these two codes BUT not sure how u would let users define it.

	config = &net.ListenConfig{Control: func (network, address string, conn syscall.RawConn) error {
		return conn.Control(func(descriptor uintptr) {
			unix.SetsockoptInt(int(descriptor), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
		})
	}}
	
// ListenServeAndSignal serves incoming connections and passes nil or error
// when listening. signal can be nil.
func (s *Server) ListenServeAndSignal(signal chan error) error {
        //if port reuse option selected, use the config.Listen addition above. else normal net stuff
        //the context.Background() can also be a user-defined option
	ln, err := config.Listen(context.Background(), s.net, s.laddr)
	if err != nil {
		if signal != nil {
			signal <- err
		}
		return err
	}
	s.mu.Lock()
	s.ln = ln
	s.mu.Unlock()
	if signal != nil {
		signal <- nil
	}
	return serve(s)
}

	

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants