当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Shutdown函数代码示例

本文整理汇总了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)
}
开发者ID:bprashanth,项目名称:tmp,代码行数:50,代码来源:splice_proxy.go

示例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
}
开发者ID:EdisonCodeKeeper,项目名称:course-6.824-distributed-systems,代码行数:60,代码来源:server.go

示例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
}
开发者ID:kedebug,项目名称:golang-programming,代码行数:65,代码来源:paxos.go

示例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)
}
开发者ID:gmwu,项目名称:go,代码行数:7,代码来源:fd_windows.go

示例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
}
开发者ID:bigaditya,项目名称:mit-ds-course,代码行数:66,代码来源:server.go

示例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
}
开发者ID:parvathythilak,项目名称:MIT-6.824,代码行数:66,代码来源:server.go

示例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))
}
开发者ID:duhaibo0404,项目名称:go-1,代码行数:7,代码来源:fd_unix.go

示例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
}
开发者ID:nixuw,项目名称:docker,代码行数:28,代码来源:process_linux.go

示例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)
}
开发者ID:nixuw,项目名称:docker,代码行数:8,代码来源:process_linux.go

示例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
}
开发者ID:pokerG,项目名称:6.824,代码行数:64,代码来源:server.go

示例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
}
开发者ID:Sunmonds,项目名称:gcc,代码行数:10,代码来源:fd_windows.go

示例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)
}
开发者ID:BreezeWu,项目名称:docker,代码行数:10,代码来源:sync_pipe.go

示例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)
}
开发者ID:GloriaH,项目名称:docker,代码行数:10,代码来源:sync_pipe.go

示例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
}
开发者ID:kevinychen,项目名称:6824-project,代码行数:61,代码来源:server.go

示例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
}
开发者ID:serge-hulne,项目名称:golang,代码行数:11,代码来源:fd_windows.go


注:本文中的syscall.Shutdown函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。