split listenAndServe into 2 functions
This commit is contained in:
parent
2a26215f2a
commit
b345eb3899
1 changed files with 12 additions and 8 deletions
|
@ -84,8 +84,13 @@ func NewFrontend(logic frontend.TrackerLogic, cfg Config) (*Frontend, error) {
|
|||
},
|
||||
}
|
||||
|
||||
err := f.listen()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go func() {
|
||||
if err := f.listenAndServe(); err != nil {
|
||||
if err := f.serve(); err != nil {
|
||||
log.Fatal("failed while serving udp", log.Err(err))
|
||||
}
|
||||
}()
|
||||
|
@ -112,19 +117,18 @@ func (t *Frontend) Stop() stop.Result {
|
|||
return c.Result()
|
||||
}
|
||||
|
||||
// listenAndServe blocks while listening and serving UDP BitTorrent requests
|
||||
// until Stop() is called or an error is returned.
|
||||
func (t *Frontend) listenAndServe() error {
|
||||
func (t *Frontend) listen() error {
|
||||
udpAddr, err := net.ResolveUDPAddr("udp", t.Addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t.socket, err = net.ListenUDP("udp", udpAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// listenAndServe blocks while listening and serving UDP BitTorrent requests
|
||||
// until Stop() is called or an error is returned.
|
||||
func (t *Frontend) serve() error {
|
||||
pool := bytepool.New(2048)
|
||||
|
||||
t.wg.Add(1)
|
||||
|
|
Loading…
Add table
Reference in a new issue