64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
package discovery
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"git.loafle.net/overflow_scanner/probe/discovery/types"
|
|
)
|
|
|
|
type ofDiscoveryRequest struct {
|
|
requesterID string
|
|
requestType types.DiscoveryRequestType
|
|
params []interface{}
|
|
|
|
dequeue chan bool
|
|
timeout bool
|
|
}
|
|
|
|
func (dr *ofDiscoveryRequest) RequesterID() string {
|
|
return dr.requesterID
|
|
}
|
|
|
|
func (dr *ofDiscoveryRequest) RequestType() types.DiscoveryRequestType {
|
|
return dr.requestType
|
|
}
|
|
|
|
func (dr *ofDiscoveryRequest) Params() []interface{} {
|
|
return dr.params
|
|
}
|
|
|
|
func (dr *ofDiscoveryRequest) release() {
|
|
releaseDiscoveryRequest(dr)
|
|
}
|
|
|
|
var discoveryRequestPool sync.Pool
|
|
|
|
func retainDiscoveryRequest(requesterID string, requestType types.DiscoveryRequestType, params ...interface{}) *ofDiscoveryRequest {
|
|
v := discoveryRequestPool.Get()
|
|
var dr *ofDiscoveryRequest
|
|
if v == nil {
|
|
dr = &ofDiscoveryRequest{}
|
|
} else {
|
|
dr = v.(*ofDiscoveryRequest)
|
|
}
|
|
|
|
dr.requesterID = requesterID
|
|
dr.requestType = requestType
|
|
dr.params = params
|
|
dr.dequeue = make(chan bool, 1)
|
|
dr.timeout = false
|
|
|
|
return dr
|
|
}
|
|
|
|
func releaseDiscoveryRequest(dr *ofDiscoveryRequest) {
|
|
dr.requesterID = ""
|
|
dr.requestType = types.DiscoveryRequestTypeNone
|
|
dr.params = nil
|
|
close(dr.dequeue)
|
|
dr.dequeue = nil
|
|
dr.timeout = false
|
|
|
|
discoveryRequestPool.Put(dr)
|
|
}
|