本文整理匯總了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)
}