Skip to content

Commit

Permalink
Adding custom listener function StartWithListener
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivanshVij committed Aug 26, 2023
1 parent 5c40c96 commit b32165f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
OnClosedNil = errors.New("OnClosed cannot be nil")
PreWriteNil = errors.New("PreWrite cannot be nil")
StreamHandlerNil = errors.New("StreamHandler cannot be nil")
ListenerNil = errors.New("Listener cannot be nil")
)

var (
Expand Down Expand Up @@ -183,18 +184,30 @@ func (s *Server) SetConcurrency(concurrency uint64) {
// onClosed, OnShutdown, or preWrite functions have not been defined, it will
// use the default functions for these.
func (s *Server) Start(addr string) error {
var listener net.Listener
var err error
if s.options.TLSConfig != nil {
s.listener, err = tls.Listen("tcp", addr, s.options.TLSConfig)
listener, err = tls.Listen("tcp", addr, s.options.TLSConfig)
} else {
s.listener, err = net.Listen("tcp", addr)
listener, err = net.Listen("tcp", addr)
}
if err != nil {
return err
}
return s.StartWithListener(listener)
}

// StartWithListener will start the frisbee server and its reactor goroutines
// to receive and handle incoming connections with a given net.Listener. If the baseContext, ConnContext,
// onClosed, OnShutdown, or preWrite functions have not been defined, it will
// use the default functions for these.
func (s *Server) StartWithListener(listener net.Listener) error {
if listener == nil {
return ListenerNil
}
s.listener = listener
s.wg.Add(1)
close(s.startedCh)

return s.handleListener()
}

Expand Down

0 comments on commit b32165f

Please sign in to comment.