57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net"
|
|
gen "slimming/proto/gen"
|
|
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type RPCServer_OLD struct {
|
|
gen.UnimplementedFrameServiceServer
|
|
netCard *NetCard_OLD
|
|
}
|
|
|
|
var ()
|
|
|
|
func newRPCServer_OLD(netCard *NetCard_OLD) *RPCServer_OLD {
|
|
return &RPCServer_OLD{netCard: netCard}
|
|
}
|
|
|
|
func (rpc *RPCServer_OLD) run() {
|
|
|
|
lis, err := net.Listen("tcp", config.Network.Self.Real)
|
|
if err != nil {
|
|
log.Fatalf("failed to listen: %v", err)
|
|
}
|
|
s := grpc.NewServer()
|
|
gen.RegisterFrameServiceServer(s, rpc)
|
|
log.Printf("server listening at %v", lis.Addr())
|
|
|
|
if err := s.Serve(lis); err != nil {
|
|
log.Fatalf("failed to serve: %v", err)
|
|
}
|
|
}
|
|
|
|
// SayHello implements helloworld.GreeterServer
|
|
func (s *RPCServer_OLD) SendFrames(stream gen.FrameService_SendFramesServer) error {
|
|
log.Printf("Start: %v", stream)
|
|
|
|
for {
|
|
request, err := stream.Recv()
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
log.Printf("request: %v", len(request.Frames))
|
|
s.netCard.FrameChan <- request.GetFrames() // 接受数据 广播到网卡上
|
|
}
|
|
|
|
// err := stream.SendAndClose(&gen.Response{Code: 0})
|
|
// if err != nil {
|
|
// log.Panic(err)
|
|
// }
|
|
|
|
return nil
|
|
}
|