Browse Source

Socket management types include given address -> real address mappers

for serialization.
multiapp-subsubapp
Benjamin Shelton 3 months ago
parent
commit
dbb57bff0f
1 changed files with 21 additions and 4 deletions
  1. +21
    -4
      network.go

+ 21
- 4
network.go View File

@@ -35,8 +35,9 @@ type fdencode struct {
}

type fdenv struct {
Sockets []*fdencode `json:"sockets"`
ParentPID int `json:"parent_pid"`
Sockets []*fdencode `json:"sockets"`
ParentPID int `json:"parent_pid"`
Addrs map[string]string `json:"addrs"`
}

type fdmap struct {
@@ -46,6 +47,14 @@ type fdmap struct {
sync.RWMutex
}

func newfdmap() *fdmap {
return &fdmap{
sockets: make(map[string]Listener),
descriptors: make(map[string]uintptr),
addrmap: make(map[string]string),
}
}

func (f *fdmap) Files() ([]*file, error) {
i := 0
files := make([]*file, len(f.sockets))
@@ -104,6 +113,14 @@ func AddPreLaunchFunc(fn PreLaunchFunc) {
prelaunchFunc = fn
}

func (f fdmap) addAddrMap(key, fdkey string) {
f.addrmap[key] = fdkey
}

func (f fdmap) addDescriptor(key string, fd uintptr) {
f.descriptors[key] = fd
}

func (f fdmap) addListener(listener Listener, network, addr string) error {
var fd uintptr
conn, ok := listener.(syscall.Conn)
@@ -122,7 +139,7 @@ func (f fdmap) addListener(listener Listener, network, addr string) error {
f.Lock()
f.sockets[listenerKey(listener)] = listener
f.descriptors[listenerKey(listener)] = fd
f.addrmap[netKey(network, addr)] = listenerKey(listener)
f.addrmap[addr] = listenerKey(listener)
f.Unlock()

return nil
@@ -133,7 +150,7 @@ func (f fdmap) getDescriptor(network, addr string) (uintptr, bool) {
if ok {
return fd, true
}
mapped, ok := f.addrmap[netKey(network, addr)]
mapped, ok := f.addrmap[addr]
if ok {
if fd, ok := f.descriptors[mapped]; ok {
return fd, true


Loading…
Cancel
Save