blob: 59ed979d1e7e93b71a05c3b38365189ef64d8e9f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package main
import (
"log/slog"
"net"
)
type Server struct {
conn *net.Conn
SID uint32
Name string
}
func (server *Server) Send(msg SMsg) error {
return server.SendRaw(msg.ServerSerialize())
}
func (server *Server) SendRaw(s string) error {
if server == self {
return ErrSendToSelf
}
if server.conn == nil {
// TODO: Propagate across mesh
return ErrNotConnectedServer
}
slog.Debug("send", "line", s, "conn", server.conn)
_, err := (*server.conn).Write([]byte(s))
if err != nil {
// TODO: Should shut down the netFd instead but the stdlib
// doesn't expose a way to do this.
(*server.conn).Close()
return err
}
return nil
}
func (server *Server) ClientSource() string {
return server.Name
}
func (server *Server) ServerSource() uint64 {
return uint64(server.SID) << 32
}
var self *Server
|