iorpc

package module
v0.0.0-...-92a5ec2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2013 License: MIT Imports: 2 Imported by: 0

README

iorpc

iorpc is a Go library for serving and accessing io interfaces across net/rpc connections. It currently allows serving and accessing both io.Reader and io.Writer implementations.

This library is useful if you're serving a single io.Reader or io.Writer to multiple clients. If you're serving a single reader/writer to only a single client, you should instead just create a TCP listener and a TCP client and stream the data through using io.Copy which will adhere to buffers properly.

Installation

Standard go get:

$ go get github.com/mitchellh/iorpc

Usage & Example

For the most up-to-date examples and usage information, you should always access the documentation. However, for a quick look at what using this library looks like, this basic example is shown below:

// On the server side, you just register your reader onto an RPC
// server, and serve it as usual.
server := rpc.NewServer()
reader := new(bytes.Buffer) // This can be any io.Reader
iorpc.RegisterReader(server, reader)

// On the client side, you connect to an RPC server like usual,
// the use the iorpc client to read it.
client, _ := rpc.Dial("tcp", "127.0.0.1:1234")
reader := iorpc.NewReader(client)

// "reader" is now a valid io.Reader to use that will read data from
// the remote io.Reader

Documentation

Overview

Package iorpc provides a way to serve and access io package interface implementations such as io.Reader over a net/rpc connection. The implementation strives for correctness over performance. For example, with the io.Reader implementation, if you request to Read one byte, it will perform a full RPC request/response to read only a single byte.

Accessing io implementations across the network can be extremely useful in certain environments. And, if used properly, can be performant as well.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterReader

func RegisterReader(server *rpc.Server, r io.Reader) error

RegisterReader registers the io.Reader on the RPC server.

func RegisterReaderName

func RegisterReaderName(s *rpc.Server, name string, r io.Reader) error

RegisterReaderName registers the io.Reader on the RPC server with the given type name instead of the default inferred type name.

func RegisterWriter

func RegisterWriter(server *rpc.Server, r io.Writer) error

RegisterWriter registers the io.Writer on the RPC server.

func RegisterWriterName

func RegisterWriterName(s *rpc.Server, name string, r io.Writer) error

RegisterWriterName registers the io.Writer on the RPC server with the given type name instead of the default inferred type name.

Types

type Reader

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

Reader is an implementation of io.Reader that performs its operations across an RPC connection.

func NewReader

func NewReader(client *rpc.Client) *Reader

NewReader returns a new Reader that communicates with the given RPC client.

func NewReaderName

func NewReaderName(client *rpc.Client, name string) *Reader

NewReaderName returns a new Reader that communicates with the given RPC client using name as the type name for the remote ReaderServer in RPC calls.

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

type ReaderServer

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

ReaderServer wraps an io.Reader and serves it across an RPC connection. The ReaderServer can be accessed by a Reader.

func (*ReaderServer) Read

func (r *ReaderServer) Read(n int, data *[]byte) error

type Writer

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

Writer is an implementation of io.Writer that performs its operations across an RPC connection.

func NewWriter

func NewWriter(client *rpc.Client) *Writer

NewWriter returns a new Writer that communicates with the given RPC client.

func NewWriterName

func NewWriterName(client *rpc.Client, name string) *Writer

NewWriterName returns a new Writer that communicates with the given RPC client using name as the type name for the remote WriterServer in RPC calls.

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

type WriterServer

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

WriterServer wraps a io.Writer and serves it across an RPC connection. The WriterServer can be accessed using an RPC client and Writer. Use RegisterWriter and RegisterWriterName to serve a writer from your RPC server.

func (*WriterServer) Write

func (w *WriterServer) Write(p []byte, n *int) (err error)

Jump to

Keyboard shortcuts

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