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

View File

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