本文整理汇总了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")
}
示例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")
}
示例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)
}
}
示例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()
}
示例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)
}