mirror of
https://gitee.com/johng/gf
synced 2026-07-02 19:31:07 +08:00
update comment and standardize const naming for package gproc
This commit is contained in:
@ -31,9 +31,9 @@ type MsgResponse struct {
|
||||
}
|
||||
|
||||
const (
|
||||
gPROC_COMM_DEFAULT_GRUOP_NAME = "" // Default group name.
|
||||
gPROC_DEFAULT_TCP_PORT = 10000 // Starting port number for receiver listening.
|
||||
gPROC_MSG_QUEUE_MAX_LENGTH = 10000 // Max size for each message queue of the group.
|
||||
defaultGroupNameFoProcComm = "" // Default group name.
|
||||
defaultTcpPortForProcComm = 10000 // Starting port number for receiver listening.
|
||||
maxLengthForProcMsgQueue = 10000 // Max size for each message queue of the group.
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@ -35,10 +35,10 @@ func Receive(group ...string) *MsgRequest {
|
||||
if len(group) > 0 {
|
||||
groupName = group[0]
|
||||
} else {
|
||||
groupName = gPROC_COMM_DEFAULT_GRUOP_NAME
|
||||
groupName = defaultGroupNameFoProcComm
|
||||
}
|
||||
queue := commReceiveQueues.GetOrSetFuncLock(groupName, func() interface{} {
|
||||
return gqueue.New(gPROC_MSG_QUEUE_MAX_LENGTH)
|
||||
return gqueue.New(maxLengthForProcMsgQueue)
|
||||
}).(*gqueue.Queue)
|
||||
|
||||
// Blocking receiving.
|
||||
@ -52,7 +52,7 @@ func Receive(group ...string) *MsgRequest {
|
||||
func receiveTcpListening() {
|
||||
var listen *net.TCPListener
|
||||
// Scan the available port for listening.
|
||||
for i := gPROC_DEFAULT_TCP_PORT; ; i++ {
|
||||
for i := defaultTcpPortForProcComm; ; i++ {
|
||||
addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("127.0.0.1:%d", i))
|
||||
if err != nil {
|
||||
continue
|
||||
|
||||
@ -18,7 +18,7 @@ func Send(pid int, data []byte, group ...string) error {
|
||||
msg := MsgRequest{
|
||||
SendPid: Pid(),
|
||||
RecvPid: pid,
|
||||
Group: gPROC_COMM_DEFAULT_GRUOP_NAME,
|
||||
Group: defaultGroupNameFoProcComm,
|
||||
Data: data,
|
||||
}
|
||||
if len(group) > 0 {
|
||||
|
||||
@ -88,7 +88,7 @@ func (p *Process) Run() error {
|
||||
}
|
||||
}
|
||||
|
||||
// PID
|
||||
// Pid retrieves and returns the PID for the process.
|
||||
func (p *Process) Pid() int {
|
||||
if p.Process != nil {
|
||||
return p.Process.Pid
|
||||
@ -96,7 +96,7 @@ func (p *Process) Pid() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// Send send custom data to the process.
|
||||
// Send sends custom data to the process.
|
||||
func (p *Process) Send(data []byte) error {
|
||||
if p.Process != nil {
|
||||
return Send(p.Process.Pid, data)
|
||||
|
||||
Reference in New Issue
Block a user