代码拉取完成,页面将自动刷新
package gproc
import (
"errors"
"fmt"
"gitee.com/micro-tools/wf/container/gmap"
"gitee.com/micro-tools/wf/net/gtcp"
"gitee.com/micro-tools/wf/os/gfile"
"gitee.com/micro-tools/wf/util/gconv"
)
// MsgRequest is the request structure for process communication.
type MsgRequest struct {
SendPid int // Sender PID.
RecvPid int // Receiver PID.
Group string // Message group name.
Data []byte // Request data.
}
// MsgResponse is the response structure for process communication.
type MsgResponse struct {
Code int // 1: OK; Other: Error.
Message string // Response message.
Data []byte // Response data.
}
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.
)
var (
// commReceiveQueues is the group name to queue map for storing received data.
// The value of the map is type of *gqueue.Queue.
commReceiveQueues = gmap.NewStrAnyMap(true)
// commPidFolderPath specifies the folder path storing pid to port mapping files.
commPidFolderPath = gfile.TempDir("gproc")
)
func init() {
// Automatically create the storage folder.
if !gfile.Exists(commPidFolderPath) {
err := gfile.Mkdir(commPidFolderPath)
if err != nil {
panic(fmt.Errorf(`create gproc folder failed: %v`, err))
}
}
}
// getConnByPid creates and returns a TCP connection for specified pid.
func getConnByPid(pid int) (*gtcp.PoolConn, error) {
port := getPortByPid(pid)
if port > 0 {
if conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", port)); err == nil {
return conn, nil
} else {
return nil, err
}
}
return nil, errors.New(fmt.Sprintf("could not find port for pid: %d", pid))
}
// getPortByPid returns the listening port for specified pid.
// It returns 0 if no port found for the specified pid.
func getPortByPid(pid int) int {
path := getCommFilePath(pid)
content := gfile.GetContentsWithCache(path)
return gconv.Int(content)
}
// getCommFilePath returns the pid to port mapping file path for given pid.
func getCommFilePath(pid int) string {
return gfile.Join(commPidFolderPath, gconv.String(pid))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。