8000 Listeners with same name will cause panic. · Issue #8 · akutz/memconn · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Listeners with same name will cause panic. #8
Open
@sbilly

Description

@sbilly

Listener with same name will cause panic.

Hello, world.panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x10e8f62]

goroutine 1 [running]:
github.com/akutz/memconn.(*Listener).Close(0x0, 0x0, 0x7)
        /.go/src/github.com/akutz/memconn/memconn_listener.go:95 +0x22
main.main()
        /temp/memconn.go:48 +0x2c7
exit status 2

Source Code:

package main

import (
	"io"
	"os"

	"github.com/akutz/memconn"
)

// ExampleBuffered illustrates a server and client that
// communicate over a buffered, in-memory connection.
func main() {
	// Announce a new listener named "localhost" on MemConn's
	// buffered network, "memb".
	lis, _ := memconn.Listen("memb", "localhost")
	lis2, _ := memconn.Listen("memb", "localhost")

	// Ensure the listener is closed.
	defer lis.Close()
	defer lis2.Close()

	// Start a goroutine that will wait for a client to dial the
	// listener and then echo back any data sent to the remote
	// connection.
	go func() {
		conn, _ := lis.Accept()

		// If no errors occur then make sure the connection is closed.
		defer conn.Close()

		// Echo the data back to the client.
		io.CopyN(conn, conn, 13)
	}()

	// Dial the buffered, in-memory network named "localhost".
	conn, _ := memconn.Dial("memb", "localhost")

	// Ensure the connection is closed.
	defer conn.Close()

	// Write the data to the server.
	conn.Write([]byte("Hello, world."))

	// Read the data from the server.
	io.CopyN(os.Stdout, conn, 13)

	// Output: Hello, world.
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0