Mutex should be pointer, comments added.

This commit is contained in:
Jim Colderwood 2024-05-02 10:11:16 +01:00
parent 210141b8d5
commit 19487be773
2 changed files with 12 additions and 7 deletions

View File

@ -14,11 +14,14 @@ import (
)
func New() Message {
var message Message
message.RIP = make([]RIP, 25)
return message
return Message{
RIP: make([]RIP, 25),
}
}
/* Parse the raw data packet
* Store the serialised data in the Message slice
*/
func (m *Message) MParse(b *[]byte, n int) error {
if n == 0 {
return errors.New("can't parse empty data")
@ -59,6 +62,7 @@ func (m *Message) MParse(b *[]byte, n int) error {
return nil
}
/* Listen for network packets */
func (m *Message) Run(c *config.Config, callback func(*Routes)) error {
iface := net.Interface{
Name: c.MulticastInterface,

View File

@ -10,7 +10,7 @@ import (
type Routes struct {
Routes map[string]Route
sync.Mutex
*sync.Mutex
}
type Route struct {
@ -23,9 +23,10 @@ type Route struct {
}
func Init() *Routes {
var routes Routes
routes.Routes = make(map[string]Route, 25)
return &routes
return &Routes{
Routes: make(map[string]Route, 25),
Mutex: new(sync.Mutex),
}
}
func (r *Routes) append(route Route) {