Skip to content

Commit

Permalink
gosip.Server: add network argument to the Listen method
Browse files Browse the repository at this point in the history
  • Loading branch information
ghettovoice committed Jun 16, 2018
1 parent e750d1e commit 95c11c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
9 changes: 7 additions & 2 deletions gosip.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ var (
defaultServer *Server
)

// DefaultServer returns auto created default SIP server
func DefaultServer() *Server {
return defaultServer
}

// Listen starts SIP stack
func Listen(listenAddr string) error {
func Listen(network string, listenAddr string) error {
if defaultServer == nil {
defaultServer = NewServer(ServerConfig{})
}

return defaultServer.Listen(listenAddr)
return defaultServer.Listen(network, listenAddr)
}
18 changes: 4 additions & 14 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ const (
defaultHostAddr = "127.0.0.1"
)

var (
protocols = []string{"udp", "tcp"}
)

// RequestHandler is a callback that will be called on the incoming request
// of the certain method
type RequestHandler func(req sip.Request)
Expand Down Expand Up @@ -75,16 +71,10 @@ func NewServer(config ServerConfig) *Server {
}

// ListenAndServe starts serving listeners on the provided address
func (srv *Server) Listen(listenAddr string) error {
if listenAddr == "" {
listenAddr = defaultListenAddr
}

for _, protocol := range protocols {
if err := srv.tp.Listen(protocol, listenAddr); err != nil {
// return immediately
return err
}
func (srv *Server) Listen(network string, listenAddr string) error {
if err := srv.tp.Listen(network, listenAddr); err != nil {
// return immediately
return err
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = Describe("Server", func() {
wg := new(sync.WaitGroup)
called := false

Expect(srv.Listen("127.0.0.1:5060")).To(Succeed())
Expect(srv.Listen("udp", "127.0.0.1:5060")).To(Succeed())

srv.OnRequest(sip.INVITE, func(req sip.Request) {
Expect(req.Method).To(Equal(sip.INVITE))
Expand Down

0 comments on commit 95c11c0

Please sign in to comment.