etsn

package module
v0.0.0-...-ef9d1e6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2013 License: BSD-2-Clause Imports: 5 Imported by: 2

README

A Go implementation of the ETSN protocol: https://raw.github.com/250bpm/nanomsg/master/rfc/etsn-01.txt

Install:

go get github.com/JImmyFrasche/etsn

Documentation: http://godoc.org/github.com/JImmyFrasche/etsn

Example server:

package main

import (
	"github.com/JImmyFrasche/etsn"
	"io"
	"log"
	"net"
)

func main() {
	s := etsn.New(func(e error) {
		if e != nil {
			log.Println(e)
		}
	})
	s.Register("echo", func(c *net.TCPConn) {
		log.Println(io.Copy(c, c))
		log.Println(c.Close())
	})
	log.Fatalln(s.Listen("tcp", "127.0.0.1:"))
}

Example Client:

package main

import (
	"bufio"
	"github.com/JImmyFrasche/etsn"
	"io"
	"log"
	"os"
)

func main() {
	c, err := etsn.Dial("tcp", "127.0.0.1:", "echo")
	if err != nil {
		log.Fatalln(err)
	}

	w := bufio.NewWriter(c)
	w.WriteString("Hello\n")
	w.Flush()
	c.CloseWrite()
	io.Copy(os.Stdout, c)
}

Documentation

Overview

A simple implementation of ETSN: https://raw.github.com/250bpm/nanomsg/master/rfc/etsn-01.txt

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProtocolIdentifierTooLong  = errors.New("ETSN protocol identifier exceeds 255 bytes")
	ErrUnsupportedProtocolVersion = errors.New("Unsupported ETSN protocol version")
	ErrInvalidHeader              = errors.New("Invalid ETSN header")
)

Functions

func Dial

func Dial(nett, laddr, proto string) (*net.TCPConn, error)

Dial connects to the specified ETSN server and requests protocol proto.

nett must be one of "tcp", "tcp4", "tcp6".

laddr is standard Go networking address as used in the net package. If the laddr string ends in ":", the default port, 5908, is appended.

If the server server does not speak the protocol proto, an error will be returned; otherwise a TCP connection is returned ready to use.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server encapsulates the state of an ETSN server.

func New

func New(logger func(error)) *Server

New returns a new Server.

logger is called whenever there's an error establishing a connection within Listen. Note that the error may be nil. If logger is nil, a no op logger is used. The logger may be called by multiple goroutines. Errors returned from handlers are passed to logger.

func (*Server) Help

func (s *Server) Help() (protos []string)

Help is a local version of the TCPMUX HELP protocol. It returns a list of all the protocols the server implements. It is not exposed by the server, but can be made to do so trivially, if desired: (error handling elided for brevity)

server.Register("HELP", func(c *net.TCPConn) {
	w := bufio.NewWriter(c)
	for _, p := range server.Help() {
		w.WriteString(p)
		w.WriteByte('\n')
	}
	w.Flush()
	c.Close()
})

func (*Server) Listen

func (s *Server) Listen(nett, laddr string) error

Listen starts an ETSN server on port 5908.

When connections are made they are dispatched, based on the client's requested protocol identifier, to any handler registered via Register, otherwise the request is dropped.

If a logger was set with SetListenLogger, all errors during the ETSN handshake will be passed to it, there will be at most one error per goroutine.

nett must be one of "tcp", "tcp4", "tcp6".

laddr is standard Go networking address as used in the net package. If the laddr string ends in ":", the default port, 5908, is appended.

func (*Server) ProtocolMissing

func (s *Server) ProtocolMissing(pm func(string, *net.TCPConn) error)

ProtocolMissing is called when no protocol is found. The first argument is the name of the unknown protocol, otherwise it behaves exactly like a regular handler. If no ProtocolMissing handler is set, or this is called with nil, requests will be closed and ignored.

func (*Server) Register

func (s *Server) Register(proto string, handler func(*net.TCPConn) error) error

Register registers a handler function for the protocol named proto.

If there was already a protocol registered with identifier proto, handler will be used for any future connections. All existing connections of proto will remain with the previous handler until the connections are closed.

func (*Server) Unregister

func (s *Server) Unregister(proto string)

Unregister removes any handler associated with the identifier proto, if present.

No existing connection will be effected.

Directories

Path Synopsis
Create an ETSN server that sends its connections to other procs over unix domain sockets.
Create an ETSN server that sends its connections to other procs over unix domain sockets.
etsnunix implements an interface similar to etsn, but for listening for connections on a unix socket provided by the etsnsrv command.
etsnunix implements an interface similar to etsn, but for listening for connections on a unix socket provided by the etsnsrv command.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL