mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-27 06:10:26 +08:00
fix
This commit is contained in:
@@ -105,8 +105,23 @@ func (m *Me) listen() (conn *net.UDPConn, err error) {
|
|||||||
|
|
||||||
// Read 接收所有发送给本机的报文
|
// Read 接收所有发送给本机的报文
|
||||||
// 需要开启 nopipe
|
// 需要开启 nopipe
|
||||||
func (m *Me) Read() *head.Packet {
|
func (m *Me) Read(p []byte) (n int, err error) {
|
||||||
return <-m.pipe
|
if len(m.readptr) > 0 {
|
||||||
|
n = copy(p, m.readptr)
|
||||||
|
m.readptr = m.readptr[n:]
|
||||||
|
if n == len(p) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p = p[n:]
|
||||||
|
}
|
||||||
|
data := (<-m.pipe).Data
|
||||||
|
c := copy(p, data)
|
||||||
|
n += c
|
||||||
|
if c == len(data) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.readptr = data[c:]
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从 conn 读取 sz 字节数据
|
// 从 conn 读取 sz 字节数据
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ type Me struct {
|
|||||||
clock map[*head.Packet]uint8
|
clock map[*head.Packet]uint8
|
||||||
// 本机上层配置
|
// 本机上层配置
|
||||||
srcport, dstport, mtu uint16
|
srcport, dstport, mtu uint16
|
||||||
|
readptr []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMe 设置本机参数
|
// NewMe 设置本机参数
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package lower
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -49,8 +50,7 @@ func (nc *NIC) Start(m *link.Me) {
|
|||||||
nc.hasstart = true
|
nc.hasstart = true
|
||||||
go func() { // 接收到 NIC
|
go func() { // 接收到 NIC
|
||||||
for nc.hasstart {
|
for nc.hasstart {
|
||||||
packet := m.Read()
|
n, err := io.Copy(nc.ifce, m)
|
||||||
n, err := nc.ifce.Write(packet.Data)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorln("[lower] recv write to nic err:", err)
|
logrus.Errorln("[lower] recv write to nic err:", err)
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -32,11 +32,9 @@ type LogFormat struct{}
|
|||||||
// Format implements logrus.Formatter
|
// Format implements logrus.Formatter
|
||||||
func (f LogFormat) Format(entry *logrus.Entry) ([]byte, error) {
|
func (f LogFormat) Format(entry *logrus.Entry) ([]byte, error) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
buf.WriteByte('[')
|
|
||||||
buf.WriteString(getLogLevelColorCode(entry.Level))
|
buf.WriteString(getLogLevelColorCode(entry.Level))
|
||||||
buf.WriteString(strings.ToUpper(entry.Level.String()))
|
buf.WriteString(strings.ToUpper(entry.Level.String()))
|
||||||
buf.WriteString(colorReset)
|
buf.WriteString(colorReset)
|
||||||
buf.WriteString("] ")
|
|
||||||
buf.WriteString(entry.Message)
|
buf.WriteString(entry.Message)
|
||||||
buf.WriteString(" \n")
|
buf.WriteString(" \n")
|
||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
|
|||||||
Reference in New Issue
Block a user