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

Support for Unix Domain Sockets #23

Closed
cooldarkdryplace opened this issue Sep 19, 2022 · 3 comments
Closed

Support for Unix Domain Sockets #23

cooldarkdryplace opened this issue Sep 19, 2022 · 3 comments

Comments

@cooldarkdryplace
Copy link
Contributor

Hi!

Beanstalkd 1.12 supports Unix Domain Sockets (commit).

Unfortunately, the current client implementation only supports TCP sockets. Even though adding UDS support is trivial and beneficial for people who do not want to have TCP overhead.

Do you want to support UDS?
If not, please close the issue.

If yes, would you prefer just another URL prefix, like unix://,

beanstalk.Dial("unix:///var/run/beanstalkd/beanstalkd.sock", cfg)

Or is your preference to give a way to construct beanstalk.Conn by passing net.Conn as a parameter?

conn, err := net.Dial("unix", "/var/run/beanstalkd/beanstalkd.sock")
if err != nil {
    log.Fatalf("Failed to connect: %s", err)
}
bc := beanstalk.NewConn(conn, cfg)

I can prepare a PR if this looks interesting.

Cheers.

@prep
Copy link
Owner

prep commented Sep 19, 2022

Hey buddy! Good to hear from you 🤗

I was not aware beanstalk 1.12 supported UDS and it definitely would be nice to add it. It looks like a change is needed in ParseURI(). Perhaps the function return types need to change to something like this:

type uriType string

const (
  uriTCPType uriType = "tcp"
  uriTLSType uriType = "tls"
  uriUDSType uriType = "unix"
)

// XXX: Might as well unexported this function.
func parseURI(v string) (string, uriType, error) {
  // ...
}

So that in Dial() we can do something like this:

func Dial(uri string, config Config) (*Conn, error) {
  addr, ut, err := ParseURI(uri)
  if err != nil {
    return nil, err
  }

  config = config.normalize()

  vat netConn net.Conn
  switch ut {
  case uriTCPType:
    // ...
  }

Does that make sense?

@cooldarkdryplace
Copy link
Contributor Author

Thanks for the suggestions. I have submitted a PR.

@prep
Copy link
Owner

prep commented Sep 22, 2022

Thanks for the PR, bud! сливаться 👍

@prep prep closed this as completed Sep 22, 2022
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