本文整理汇总了Golang中syscall.Shutdown函数的典型用法代码示例。如果您正苦于以下问题:Golang Shutdown函数的具体用法?Golang Shutdown怎么用?Golang Shutdown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Shutdown函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: splice
func (s *Splicer) splice(direction string, inFD, outFD int, wg *sync.WaitGroup) {
// Signal to the caller that we're done
defer func() {
// If a reliable delivery socket has data associated with it when a close takes place, the system continues to attempt data transfer.
if err := syscall.Shutdown(inFD, SHUT_RDWR); err != nil {
log.Printf("Shutdown err %v", err)
}
if err := syscall.Shutdown(outFD, SHUT_RDWR); err != nil {
log.Printf("Shutdown err %v", err)
}
if wg != nil {
wg.Done()
}
}()
pipe := make([]int, 2)
if err := syscall.Pipe(pipe); err != nil {
log.Fatal(err)
}
defer func() {
syscall.Close(pipe[0])
syscall.Close(pipe[1])
}()
var netWrittenBytes, netReadBytes int64
log.Printf("[%v] Splicing pipe %+v, tcpfds %+v", direction, s.pipe, s.tcpFD)
for {
// SPLICE_F_NONBLOCK: don't block if TCP buffer is empty
// SPLICE_F_MOVE: directly move pages into splice buffer in kernel memory
// SPLICE_F_MORE: just makes mysql connections slow
log.Printf("[input (%v)] Entering input", direction)
inBytes, err := syscall.Splice(inFD, nil, pipe[1], nil, s.bufferSize, SPLICE_F_NONBLOCK)
if err := s.checkSpliceErr(inBytes, err, fmt.Sprintf("input (%v)", direction)); err != nil {
log.Printf("ERROR [input (%v)] error: %v", direction, err)
return
}
netReadBytes += inBytes
log.Printf("[input (%v)] %d bytes read", direction, inBytes)
log.Printf("[input (%v)] Entering output", direction)
outBytes, err := syscall.Splice(pipe[0], nil, outFD, nil, s.bufferSize, SPLICE_F_NONBLOCK)
if err := s.checkSpliceErr(inBytes, err, fmt.Sprintf("output (%v)", direction)); err != nil {
log.Printf("ERROR [output (%v)] error: %v", direction, err)
return
}
log.Printf("[output (%v)] %d bytes written, out of given input %d", direction, outBytes, inBytes)
netWrittenBytes += outBytes
}
log.Printf("[%v] Spliced %d bytes read %d bytes written", direction, netWrittenBytes, netReadBytes)
}
示例2: StartServer
func StartServer(vshost string, me string) *PBServer {
pb := new(PBServer)
pb.me = me
pb.vs = viewservice.MakeClerk(me, vshost)
// Your pb.* initializations here.
pb.view = viewservice.View{}
pb.content = make(map[string]string)
pb.client = make(map[string]string)
rpcs := rpc.NewServer()
rpcs.Register(pb)
os.Remove(pb.me)
l, e := net.Listen("unix", pb.me)
if e != nil {
log.Fatal("listen error: ", e)
}
pb.l = l
// please do not change any of the following code,
// or do anything to subvert it.
go func() {
for pb.isdead() == false {
conn, err := pb.l.Accept()
if err == nil && pb.isdead() == false {
if pb.isunreliable() && (rand.Int63()%1000) < 100 {
// discard the request.
conn.Close()
} else if pb.isunreliable() && (rand.Int63()%1000) < 200 {
// process the request but force discard of reply.
c1 := conn.(*net.UnixConn)
f, _ := c1.File()
err := syscall.Shutdown(int(f.Fd()), syscall.SHUT_WR)
if err != nil {
fmt.Printf("shutdown: %v\n", err)
}
go rpcs.ServeConn(conn)
} else {
go rpcs.ServeConn(conn)
}
} else if err == nil {
conn.Close()
}
if err != nil && pb.isdead() == false {
fmt.Printf("PBServer(%v) accept: %v\n", me, err.Error())
pb.kill()
}
}
}()
go func() {
for pb.isdead() == false {
pb.tick()
time.Sleep(viewservice.PingInterval)
}
}()
return pb
}
示例3: Make
//
// the application wants to create a paxos peer.
// the ports of all the paxos peers (including this one)
// are in peers[]. this servers port is peers[me].
//
func Make(peers []string, me int, rpcs *rpc.Server) *Paxos {
px := &Paxos{}
px.peers = peers
px.me = me
// Your initialization code here.
if rpcs != nil {
// caller will create socket &c
rpcs.Register(px)
} else {
rpcs = rpc.NewServer()
rpcs.Register(px)
// prepare to receive connections from clients.
// change "unix" to "tcp" to use over a network.
os.Remove(peers[me]) // only needed for "unix"
l, e := net.Listen("unix", peers[me])
if e != nil {
log.Fatal("listen error: ", e)
}
px.l = l
// please do not change any of the following code,
// or do anything to subvert it.
// create a thread to accept RPC connections
go func() {
for px.dead == false {
conn, err := px.l.Accept()
if err == nil && px.dead == false {
if px.unreliable && (rand.Int63()%1000) < 100 {
// discard the request.
conn.Close()
} else if px.unreliable && (rand.Int63()%1000) < 200 {
// process the request but force discard of reply.
c1 := conn.(*net.UnixConn)
f, _ := c1.File()
err := syscall.Shutdown(int(f.Fd()), syscall.SHUT_WR)
if err != nil {
fmt.Printf("shutdown: %v\n", err)
}
px.rpcCount++
go rpcs.ServeConn(conn)
} else {
px.rpcCount++
go rpcs.ServeConn(conn)
}
} else if err == nil {
conn.Close()
}
if err != nil && px.dead == false {
fmt.Printf("Paxos(%v) accept: %v\n", me, err.Error())
}
}
}()
}
return px
}
示例4: shutdown
func (fd *netFD) shutdown(how int) error {
if err := fd.incref(); err != nil {
return err
}
defer fd.decref()
return syscall.Shutdown(fd.sysfd, how)
}
示例5: StartServer
//
// servers[] contains the ports of the set of
// servers that will cooperate via Paxos to
// form the fault-tolerant key/value service.
// me is the index of the current server in servers[].
//
func StartServer(servers []string, me int) *KVPaxos {
// this call is all that's needed to persuade
// Go's RPC library to marshall/unmarshall
// struct Op.
gob.Register(Op{})
kv := new(KVPaxos)
kv.me = me
// Your initialization code here.
kv.mydb = map[string]string{}
kv.history = map[int64]string{}
kv.DoneInst = 0
rpcs := rpc.NewServer()
rpcs.Register(kv)
kv.px = paxos.Make(servers, me, rpcs)
os.Remove(servers[me])
l, e := net.Listen("unix", servers[me])
if e != nil {
log.Fatal("listen error: ", e)
}
kv.l = l
// please do not change any of the following code,
// or do anything to subvert it.
go func() {
for kv.dead == false {
conn, err := kv.l.Accept()
if err == nil && kv.dead == false {
if kv.unreliable && (rand.Int63()%1000) < 100 {
// discard the request.
conn.Close()
} else if kv.unreliable && (rand.Int63()%1000) < 200 {
// process the request but force discard of reply.
c1 := conn.(*net.UnixConn)
f, _ := c1.File()
err := syscall.Shutdown(int(f.Fd()), syscall.SHUT_WR)
if err != nil {
fmt.Printf("shutdown: %v\n", err)
}
go rpcs.ServeConn(conn)
} else {
go rpcs.ServeConn(conn)
}
} else if err == nil {
conn.Close()
}
if err != nil && kv.dead == false {
fmt.Printf("KVPaxos(%v) accept: %v\n", me, err.Error())
kv.kill()
}
}
}()
return kv
}
示例6: StartServer
//
// servers[] contains the ports of the set of
// servers that will cooperate via Paxos to
// form the fault-tolerant key/value service.
// me is the index of the current server in servers[].
//
func StartServer(servers []string, me int) *KVPaxos {
// call gob.Register on structures you want
// Go's RPC library to marshall/unmarshall.
gob.Register(Op{})
kv := new(KVPaxos)
kv.me = me
// initialization
kv.kvData = make(map[string]string)
kv.preReply = make(map[string]*Op)
kv.seqChan = make(map[int]chan *Op)
kv.maxInstanceID = -1
rpcs := rpc.NewServer()
rpcs.Register(kv)
kv.px = paxos.Make(servers, me, rpcs)
os.Remove(servers[me])
l, e := net.Listen("unix", servers[me])
if e != nil {
log.Fatal("listen error: ", e)
}
kv.l = l
// please do not change any of the following code,
// or do anything to subvert it.
go func() {
for kv.dead == false {
conn, err := kv.l.Accept()
if err == nil && kv.dead == false {
if kv.unreliable && (rand.Int63()%1000) < 100 {
// discard the request.
conn.Close()
} else if kv.unreliable && (rand.Int63()%1000) < 200 {
// process the request but force discard of reply.
c1 := conn.(*net.UnixConn)
f, _ := c1.File()
err := syscall.Shutdown(int(f.Fd()), syscall.SHUT_WR)
if err != nil {
fmt.Printf("shutdown: %v\n", err)
}
go rpcs.ServeConn(conn)
} else {
go rpcs.ServeConn(conn)
}
} else if err == nil {
conn.Close()
}
if err != nil && kv.dead == false {
fmt.Printf("KVPaxos(%v) accept: %v\n", me, err.Error())
kv.kill()
}
}
}()
go kv.updateStatus()
return kv
}
示例7: shutdown
func (fd *netFD) shutdown(how int) error {
if err := fd.incref(); err != nil {
return err
}
defer fd.decref()
return os.NewSyscallError("shutdown", syscall.Shutdown(fd.sysfd, how))
}
示例8: start
func (p *setnsProcess) start() (err error) {
defer p.parentPipe.Close()
if err = p.execSetns(); err != nil {
return newSystemError(err)
}
if len(p.cgroupPaths) > 0 {
if err := cgroups.EnterPid(p.cgroupPaths, p.pid()); err != nil {
return newSystemError(err)
}
}
if err := json.NewEncoder(p.parentPipe).Encode(p.config); err != nil {
return newSystemError(err)
}
if err := syscall.Shutdown(int(p.parentPipe.Fd()), syscall.SHUT_WR); err != nil {
return newSystemError(err)
}
// wait for the child process to fully complete and receive an error message
// if one was encoutered
var ierr *genericError
if err := json.NewDecoder(p.parentPipe).Decode(&ierr); err != nil && err != io.EOF {
return newSystemError(err)
}
if ierr != nil {
return newSystemError(ierr)
}
return nil
}
示例9: sendConfig
func (p *initProcess) sendConfig() error {
// send the state to the container's init process then shutdown writes for the parent
if err := json.NewEncoder(p.parentPipe).Encode(p.config); err != nil {
return err
}
// shutdown writes for the parent side of the pipe
return syscall.Shutdown(int(p.parentPipe.Fd()), syscall.SHUT_WR)
}
示例10: StartServer
//
// servers[] contains the ports of the set of
// servers that will cooperate via Paxos to
// form the fault-tolerant shardmaster service.
// me is the index of the current server in servers[].
//
func StartServer(servers []string, me int) *ShardMaster {
gob.Register(Op{})
sm := new(ShardMaster)
sm.me = me
sm.configs = make([]Config, 1)
sm.configs[0].Groups = map[int64][]string{}
//your initialization
sm.cfgnum = 0
rpcs := rpc.NewServer()
rpcs.Register(sm)
sm.px = paxos.Make(servers, me, rpcs)
os.Remove(servers[me])
l, e := net.Listen("unix", servers[me])
if e != nil {
log.Fatal("listen error: ", e)
}
sm.l = l
// please do not change any of the following code,
// or do anything to subvert it.
go func() {
for sm.dead == false {
conn, err := sm.l.Accept()
if err == nil && sm.dead == false {
if sm.unreliable && (rand.Int63()%1000) < 100 {
// discard the request.
conn.Close()
} else if sm.unreliable && (rand.Int63()%1000) < 200 {
// process the request but force discard of reply.
c1 := conn.(*net.UnixConn)
f, _ := c1.File()
err := syscall.Shutdown(int(f.Fd()), syscall.SHUT_WR)
if err != nil {
fmt.Printf("shutdown: %v\n", err)
}
go rpcs.ServeConn(conn)
} else {
go rpcs.ServeConn(conn)
}
} else if err == nil {
conn.Close()
}
if err != nil && sm.dead == false {
fmt.Printf("ShardMaster(%v) accept: %v\n", me, err.Error())
sm.Kill()
}
}
}()
return sm
}
示例11: shutdown
func (fd *netFD) shutdown(how int) os.Error {
if fd == nil || fd.sysfd == syscall.InvalidHandle {
return os.EINVAL
}
errno := syscall.Shutdown(fd.sysfd, how)
if errno != 0 {
return &OpError{"shutdown", fd.net, fd.laddr, os.Errno(errno)}
}
return nil
}
示例12: SendToChild
func (s *SyncPipe) SendToChild(v interface{}) error {
data, err := json.Marshal(v)
if err != nil {
return err
}
s.parent.Write(data)
return syscall.Shutdown(int(s.parent.Fd()), syscall.SHUT_WR)
}
示例13: SendToChild
func (s *SyncPipe) SendToChild(networkState *network.NetworkState) error {
data, err := json.Marshal(networkState)
if err != nil {
return err
}
s.parent.Write(data)
return syscall.Shutdown(int(s.parent.Fd()), syscall.SHUT_WR)
}
示例14: StartServer
//
// servers[] contains the ports of the set of
// servers that will cooperate via Paxos to
// form the fault-tolerant shardmaster service.
// me is the index of the current server in servers[].
//
func StartServer(me string) *ObliviousReplica {
or := new(ObliviousReplica)
or.me = me
rpcs := rpc.NewServer()
rpcs.Register(or)
or.UID = GetMD5Hash(me)
os.Mkdir("data", 0700)
or.dataPath = "data/replica-" + or.UID
os.Mkdir(or.dataPath, 0700)
os.Remove(me)
l, e := net.Listen(Network, me)
if e != nil {
log.Fatal("listen error: ", e)
}
or.l = l
// please do not change any of the following code,
// or do anything to subvert it.
go func() {
for or.dead == false {
conn, err := or.l.Accept()
if err == nil && or.dead == false {
if or.unreliable && (rand.Int63()%1000) < 100 {
// discard the request.
conn.Close()
} else if or.unreliable && (rand.Int63()%1000) < 200 {
// process the request but force discard of reply.
c1 := conn.(*net.UnixConn)
f, _ := c1.File()
err := syscall.Shutdown(int(f.Fd()), syscall.SHUT_WR)
if err != nil {
fmt.Printf("shutdown: %v\n", err)
}
go rpcs.ServeConn(conn)
} else {
go rpcs.ServeConn(conn)
}
} else if err == nil {
conn.Close()
}
if err != nil && or.dead == false {
fmt.Printf("ShardMaster(%v) accept: %v\n", me, err.Error())
or.Kill()
}
}
}()
return or
}
示例15: shutdown
func (fd *netFD) shutdown(how int) error {
if err := fd.incref(false); err != nil {
return err
}
defer fd.decref()
err := syscall.Shutdown(fd.sysfd, how)
if err != nil {
return &OpError{"shutdown", fd.net, fd.laddr, err}
}
return nil
}