diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-04-18 18:04:45 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-04-18 18:04:45 -0400 |
| commit | bfaad07bab58207d802ea1d94539a29ff6c97fce (patch) | |
| tree | fddb7f99910b8d3a55c06d535e16e81368f21e7c /net | |
| parent | 67b550d22eb8cd312d282898d0d22bbe368d6d7a (diff) | |
| download | hose-bfaad07bab58207d802ea1d94539a29ff6c97fce.zip | |
acceptConnection()
Diffstat (limited to 'net')
| -rw-r--r-- | net/net.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/net/net.go b/net/net.go new file mode 100644 index 0000000..13a1891 --- /dev/null +++ b/net/net.go @@ -0,0 +1,19 @@ +package net + +import ( + "fmt" + std_net "net" + + "git.samanthony.xyz/hose/util" +) + +func AcceptConnection(network string, port uint16) (std_net.Conn, error) { + laddr := std_net.JoinHostPort("", fmt.Sprintf("%d", port)) + ln, err := std_net.Listen(network, laddr) + if err != nil { + return nil, err + } + defer ln.Close() + util.Logf("listening on %s", laddr) + return ln.Accept() +} |