How to discard response when using net/rpc?

Viewed 29

I am tring to Simulate a Disconnected scenario for testing my paxos algorithm.

Have tried the following:

import net/rpc
...
    rpcx := rpc.NewServer()
    rpcx.Register(a)
    l, e := net.Listen("tcp", a.localAddr)
    a.listener = l
    if e != nil {
        log.Fatal("listen error:", e)
    }
    go func() {
        for {
            conn, err := l.Accept()
            if err != nil {
                continue
            }
            c1 := conn.(*net.TCPConn)
            f, _ := c1.File()
            err := syscall.Shutdown(syscall.Handle(f.Fd()), syscall.SHUT_WR)
            if err != nil {
                fmt.Printf("%v\n", err)
            }
        }
    }()

the error message :An operation was attempted on something that is not a socket

I am using Go1.18 on Windows, so Any ideas to make it work?

0 Answers
Related