本文整理匯總了Golang中net.PacketConn.closeWithError方法的典型用法代碼示例。如果您正苦於以下問題:Golang PacketConn.closeWithError方法的具體用法?Golang PacketConn.closeWithError怎麽用?Golang PacketConn.closeWithError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.PacketConn
的用法示例。
在下文中一共展示了PacketConn.closeWithError方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: processLoop
//.........這裏部分代碼省略.........
now := time.Now()
if time.Unix(int64(binary.LittleEndian.Uint32(buffer[8:12])), 0).Before(now) {
sendAbort(c, addr, buffer[1:4])
continue
}
// decode connection tag to uin32
tagId := binary.LittleEndian.Uint32(buffer[3:7]) >> 8
connections.RLock()
_, ok := connections.M[tagId]
connections.RUnlock()
// create new connection
if !ok {
// create connection
wg.Add(1)
connections.Lock()
conn := newConnection(c, addr, tq, buffer[1:4], func() {
connections.Lock()
delete(connections.M, tagId)
connections.Unlock()
wg.Done()
pld.L.Lock()
pld.remainingConnections--
remain := pld.remainingConnections
pld.L.Unlock()
if remain == 0 {
pld.Signal()
}
})
connections.M[tagId] = conn
connections.Unlock()
pld.L.Lock()
pld.remainingConnections++
pld.L.Unlock()
l.L.Lock()
l.pending = append(l.pending, conn)
l.L.Unlock()
l.Signal()
}
// send COOKIE-ACK
var outgoing [4]byte
outgoing[0] = byte(PacketCookieAck)
copy(outgoing[1:4], buffer[1:4])
c.WriteTo(outgoing[:], addr)
default:
// parse connection tag
tagId := binary.LittleEndian.Uint32(buffer[0:4]) >> 8
connections.RLock()
conn, ok := connections.M[tagId]
connections.RUnlock()
// discard packets addressed to unknown connections
if !ok {
sendAbort(c, addr, buffer[1:4])
continue
}
// copy the packet data so we can reuse the buffer
p := NewPacket(len(buffer))
copy(p.D, buffer)
// queue the packet onto the connection
conn.L.Lock()
conn.Incoming = append(conn.Incoming, p)
conn.L.Unlock()
conn.Signal()
}
}
// return the packet to the receive loop
rld.L.Lock()
for ii := range packets {
rld.buffers = append(rld.buffers, packets[ii].D)
}
rld.L.Unlock()
rld.Signal()
// if we were signaled to quit, terminate existing connections
if pldErr != nil {
connections.Lock()
m := connections.M
connections.M = make(map[uint32]*connection)
connections.Unlock()
for _, c := range m {
c.closeWithError(pldErr)
}
}
}
}