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


Golang UDPConn.SetWriteDeadline方法代码示例

本文整理汇总了Golang中net.UDPConn.SetWriteDeadline方法的典型用法代码示例。如果您正苦于以下问题:Golang UDPConn.SetWriteDeadline方法的具体用法?Golang UDPConn.SetWriteDeadline怎么用?Golang UDPConn.SetWriteDeadline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.UDPConn的用法示例。


在下文中一共展示了UDPConn.SetWriteDeadline方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: serveUDP

// serveUDP starts a UDP listener for the server.
// Each request is handled in a seperate goroutine.
func (srv *Server) serveUDP(l *net.UDPConn) error {
	defer l.Close()
	handler := srv.Handler
	if handler == nil {
		handler = DefaultServeMux
	}
	if srv.UDPSize == 0 {
		srv.UDPSize = udpMsgSize
	}
	for {
		if srv.ReadTimeout != 0 {
			l.SetReadDeadline(time.Now().Add(srv.ReadTimeout))
		}
		if srv.WriteTimeout != 0 {
			l.SetWriteDeadline(time.Now().Add(srv.WriteTimeout))
		}
		m := make([]byte, srv.UDPSize)
		n, a, e := l.ReadFromUDP(m)
		if e != nil || n == 0 {
			// don't bail out, but wait for a new request
			continue
		}
		m = m[:n]
		go serve(a, handler, m, l, nil, srv.TsigSecret)
	}
	panic("dns: not reached")
}
开发者ID:vonwenm,项目名称:golang-dns,代码行数:29,代码来源:server.go

示例2: ServeUDP

// ServeUDP starts a UDP listener for the server.
// Each request is handled in a seperate goroutine,
// with the Handler set in ....
func (srv *Server) ServeUDP(l *net.UDPConn) error {
	defer l.Close()
	handler := srv.Handler
	if handler == nil {
		handler = DefaultServeMux
	}
	if srv.UDPSize == 0 {
		srv.UDPSize = UDPMsgSize
	}
	for {
		m := make([]byte, srv.UDPSize)
		n, a, e := l.ReadFromUDP(m)
		if e != nil {
			return e
		}
		m = m[:n]

		if srv.ReadTimeout != 0 {
			l.SetReadDeadline(time.Now().Add(srv.ReadTimeout))
		}
		if srv.WriteTimeout != 0 {
			l.SetWriteDeadline(time.Now().Add(srv.WriteTimeout))
		}
		d, err := newConn(nil, l, a, m, handler, srv.TsigSecret)
		if err != nil {
			continue
		}
		go d.serve()
	}
	panic("not reached")
}
开发者ID:h2non,项目名称:dns,代码行数:34,代码来源:server.go

示例3: sendAck

func (c *TFTPServer) sendAck(conn *net.UDPConn, tid string) {
	pkt := &TFTPAckPkt{Opcode: OpcodeACK, Block: c.Connections[tid].block}
	conn.SetWriteDeadline(time.Now().Add(1 * time.Second))
	if _, err := conn.Write(pkt.Pack()); err != nil {
		log.Println(err)
	}
}
开发者ID:kwbales,项目名称:nitro-tftp,代码行数:7,代码来源:tftp_client_mgr.go

示例4: sendOptAck

func (c *TFTPServer) sendOptAck(conn *net.UDPConn, tid string, opts map[string]string) {
	pkt := &tftp.TFTPOptionAckPkt{Opcode: tftp.OpcodeOptAck, Options: opts}
	conn.SetWriteDeadline(time.Now().Add(1 * time.Second))
	if _, err := conn.Write(pkt.Pack()); err != nil {
		log.Errorln(err)
	}
	c.Connections[tid].OptACKSent()
}
开发者ID:RobWC,项目名称:nitro-tftp,代码行数:8,代码来源:tftp_client_mgr.go

示例5: broadcast

// Broadcaster egen ip
func broadcast(send_sock *net.UDPConn, my_ip string) {
	send_sock.SetWriteDeadline(Now().Add(100 * Millisecond)) // Setter deadline til broadcastSock
	err := UDPwriteToSocket(send_sock, my_ip)
	if err != nil {
		Println("Could not write network_status to UDPsocket")
	}
	Sleep(1000 * Millisecond)
}
开发者ID:KjartanCool,项目名称:w14,代码行数:9,代码来源:network_short.go


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