Browse Source

Wrap direct access in function calls to gate internal API behavior for

sockets.

What we're mostly doing here is to ensure that there's some sanity when
adding or retrieving file descriptors.
multiapp-subsubapp
Benjamin Shelton 3 months ago
parent
commit
abdbec4fe5
1 changed files with 9 additions and 8 deletions
  1. +9
    -8
      netlisten_unix.go

+ 9
- 8
netlisten_unix.go View File

@@ -15,10 +15,7 @@ import (
func InitNetwork() (err error, errc chan error, close chan struct{}) {
var env *fdenv

fds = &fdmap{
sockets: make(map[string]Listener),
descriptors: make(map[string]uintptr),
}
fds = newfdmap()
errc = make(chan error, 1)
close = make(chan struct{}, 1)

@@ -31,7 +28,11 @@ func InitNetwork() (err error, errc chan error, close chan struct{}) {

parentPID = env.ParentPID
for _, socket := range env.Sockets {
fds.descriptors[socket.Name] = socket.FD
fds.addDescriptor(socket.Name, socket.FD)
}

for k, v := range env.Addrs {
fds.addAddrMap(k, v)
}

if parentPID != 0 {
@@ -99,13 +100,13 @@ func InitNetwork() (err error, errc chan error, close chan struct{}) {
}

func Listen(network, addr string) (net.Listener, error) {
if fd, ok := fds.descriptors[netKey(network, addr)]; ok {
if fd, ok := fds.getDescriptor(network, addr); ok {
listener, err := resumeListener(network, addr, fd)
if err != nil {
return nil, err
}
if _, ok := listener.(Listener); ok {
fds.addListener(listener.(Listener))
fds.addListener(listener.(Listener), network, addr)
return listener, nil
}
}
@@ -124,7 +125,7 @@ func Listen(network, addr string) (net.Listener, error) {
return nil, fmt.Errorf("listener does not implement the appropriate interface")
}

if err := fds.addListener(listener.(Listener)); err != nil {
if err := fds.addListener(listener.(Listener), network, addr); err != nil {
return nil, err
}
return listener, nil


Loading…
Cancel
Save