github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/experimental/libbox/command_reload.go (about) 1 package libbox 2 3 import ( 4 "encoding/binary" 5 "net" 6 7 E "github.com/sagernet/sing/common/exceptions" 8 "github.com/sagernet/sing/common/rw" 9 ) 10 11 func (c *CommandClient) ServiceReload() error { 12 conn, err := c.directConnect() 13 if err != nil { 14 return err 15 } 16 defer conn.Close() 17 err = binary.Write(conn, binary.BigEndian, uint8(CommandServiceReload)) 18 if err != nil { 19 return err 20 } 21 var hasError bool 22 err = binary.Read(conn, binary.BigEndian, &hasError) 23 if err != nil { 24 return err 25 } 26 if hasError { 27 errorMessage, err := rw.ReadVString(conn) 28 if err != nil { 29 return err 30 } 31 return E.New(errorMessage) 32 } 33 return nil 34 } 35 36 func (s *CommandServer) handleServiceReload(conn net.Conn) error { 37 rErr := s.handler.ServiceReload() 38 err := binary.Write(conn, binary.BigEndian, rErr != nil) 39 if err != nil { 40 return err 41 } 42 if rErr != nil { 43 return rw.WriteVString(conn, rErr.Error()) 44 } 45 return nil 46 }