代码拉取完成,页面将自动刷新
package main
import (
"context"
)
type deviceProtoctlType uint8
const (
tcpDeviceProtocol deviceProtoctlType = iota
rtuDeviceProtocol
)
var (
connectionRequestQueueSize uint32 = 100
)
type DevicePool struct {
deqChan chan *DeviceRequest
openerCh chan *DeviceRequest
ctx context.Context
}
func OpenDevicePool(parentCtx context.Context) *DevicePool {
devicePool := &DevicePool{
deqChan: make(chan *DeviceRequest, 1),
openerCh: make(chan *DeviceRequest, connectionRequestQueueSize),
ctx: parentCtx,
}
//生产 conn
go devicePool.connectionOpener()
//消费 conn
go devicePool.runConnDevice()
return devicePool
}
func (devicePool *DevicePool) connectionOpener() {
for {
select {
case <-devicePool.ctx.Done():
return
case d := <-devicePool.openerCh:
devicePool.deqChan <- &DeviceRequest{
ModpollParams: d.ModpollParams,
}
}
}
}
func (devicePool *DevicePool) runConnDevice() error {
for {
select {
default:
case device, ok := <-devicePool.deqChan:
if ok && device != nil {
deviceQ := &DeviceRequest{
ModpollParams: device.ModpollParams,
}
go deviceQ.Exec(devicePool.ctx)
}
case <-devicePool.ctx.Done():
return devicePool.ctx.Err()
}
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。