Documentation ¶
Index ¶
- Constants
- Variables
- func CreatePath(path string, dirPerm, filePerm os.FileMode) (*os.File, error)
- func FindExecutable(name string, dirs []string) string
- func GoBinPath() []string
- func IsDir(path string) bool
- func IsExecutable(file string) bool
- func LiberalSearchPath() []string
- func LocalPath() []string
- func Logged(err error) error
- func NewFile(fd int) *os.File
- func NewUnixSingleReadWriteCloser(path string) io.ReadWriteCloser
- func SystemPath() []string
- func UseEnvFlags(prefix ...string)
- func WritePath(path string, data []byte, dirPerm, filePerm os.FileMode) error
- type ChanReadWriteCloser
- type MessageReader
- type MessageStream
- type MessageWriter
- type OOBUnixConn
- type PairReadWriteCloser
- type StringReader
- type StringWriter
- type UnixSingleReadWriteCloser
Constants ¶
const DefaultMaxMessageSize = 20 * 1024 * 1024
DefaultMaxMessageSize gives the default max for messages sent on a MessageStream.
const OOBMaxLength = 100 // usually under 64 in practice
Maximum amount of out-of-band data supported. This is enough to send at least a set of credentials and 3 file descriptors.
Variables ¶
var ( ErrOOBSendFailed = errors.New("error sending out-of-band unix socket data") ErrOOBParseFailed = errors.New("error parsing out-of-band unix socket data") )
Error types for the protorpc package.
var ErrMessageTooLarge = errors.New("messagestream: message is too large")
ErrMessageTooLarge is the error message returned when a message larger than DefaultMaxMessageSize is sent on a MessageStream.
Functions ¶
func CreatePath ¶
CreatePath creates a file after creating any necessary directories.
func FindExecutable ¶
FindExecutable searches for an executable in a path. If the name is already an absolute slash, the search path is ignored. If the search fails, emptystring is returned.
func IsExecutable ¶
IsExecutable checks whether the file has an executable bits set.
func LiberalSearchPath ¶
func LiberalSearchPath() []string
LiberalSearchPath returns LocalPath, GoBinPath, and SystemPath together, in that order.
func LocalPath ¶
func LocalPath() []string
LocalPath returns the directory of the current executable
func Logged ¶
Logged prints an error and some context to glog.Error, then returns the same error. The intended usage is like so:
foo, err := somefunc() if err != nil { return 0, Logged(err) } ...
The context consists of a stack trace, but omitting parts of the trace that were already shown by the most recently printed error.
func NewUnixSingleReadWriteCloser ¶
func NewUnixSingleReadWriteCloser(path string) io.ReadWriteCloser
NewUnixSingleReadWriteCloser listens on a given Unix socket path and returns a UnixSingleReadWriteCloser that will accept a single connection on this socket and communicate only with it.
func UseEnvFlags ¶
func UseEnvFlags(prefix ...string)
UseEnvFlags pulls variables from the environment to use as values for flags. For each prefix X, an environment variable X_f will be used as the value for flag f. If flag.Parse() has not been called, then flags on the command line will override those from the environment. Otherwise environment flags will override those on the command line.
Types ¶
type ChanReadWriteCloser ¶
A ChanReadWriteCloser implements io.ReadWriteCloser over chan []byte.
func (ChanReadWriteCloser) Close ¶
func (crw ChanReadWriteCloser) Close() error
Close implements io.Closer for ChanReadWriteCloser.
type MessageReader ¶
A MessageReader is a stream from which protobuf messages can be read.
type MessageStream ¶
type MessageStream struct { MaxMessageSize int // Negative means unlimited io.ReadWriteCloser }
A MessageStream is an io.ReadWriteCloser that can also read and write strings and protobuf messages. Boundaries are preserved for strings and protobuf messages using a 32-bit (network byte order) length prefix before the contents of the string or marshalled protobuf message. MessageStream can also enforce an upper-limit on the size of received messages.
func DeserializeFDMessageStream ¶
func DeserializeFDMessageStream(s string) (*MessageStream, error)
DeserializeFDMessageStream takes a string description of the form "tao::FDMessageStream(X, Y)" and returns a MessageStream that uses file descriptor X as the reader and file descriptor Y as the writer.
func DeserializeFileMessageStream ¶
func DeserializeFileMessageStream(s string) (*MessageStream, error)
DeserializeFileMessageStream takes a string description of the form "tao::FileMessageChannel(X)" and returns a MessageStream that uses file X to communicate.
func DeserializeUnixSocketMessageStream ¶
func DeserializeUnixSocketMessageStream(f string) (*MessageStream, error)
DeserializeUnixSocketMessageStream takes a string filename and returns a MessageStream that is based on the Unix socket for this file.
func NewMessageStream ¶
func NewMessageStream(pipe io.ReadWriteCloser) *MessageStream
NewMessageStream creates a MessageStream for the given pipe with a reception limit of DefaultMaxMessageSize.
func (*MessageStream) ReadMessage ¶
func (ms *MessageStream) ReadMessage(m proto.Message) error
ReadMessage reads a 32-bit length followed by a protobuf message. If m is nil, the incoming message is discarded.
func (*MessageStream) ReadString ¶
func (ms *MessageStream) ReadString() (string, error)
ReadString reads a 32-bit length followed by a string.
func (*MessageStream) WriteMessage ¶
func (ms *MessageStream) WriteMessage(m proto.Message) (int, error)
WriteMessage writes 32-bit length followed by a protobuf message. If m is nil, a blank message is written instead.
func (*MessageStream) WriteString ¶
func (ms *MessageStream) WriteString(s string) (int, error)
WriteString writes a 32-bit length followed by the string.
type MessageWriter ¶
A MessageWriter is a stream to which protobuf messages can be written.
type OOBUnixConn ¶
OOBUnixConn provides the same operations as net.UnixConn, plus the ability to asynchronously make use of the out-of-band mechanism to share file descriptors and credentials.
func NewOOBUnixConn ¶
func NewOOBUnixConn(conn *net.UnixConn) *OOBUnixConn
NewOOBUnixConn returns a new util.OOBUnixConn, which provides the same operations as net.UnixConn but also allows sharing of file descriptors and credentials.
func (*OOBUnixConn) PeerCred ¶
func (s *OOBUnixConn) PeerCred() *syscall.Ucred
PeerCred retreives the most recently passed peer credential, or nil if no credentials have been received yet.
func (*OOBUnixConn) ShareFDs ¶
func (s *OOBUnixConn) ShareFDs(fd ...int)
ShareFDs adds some file descriptors to the list of filescriptors to be shared during the next Write.
func (*OOBUnixConn) SharedFiles ¶
func (s *OOBUnixConn) SharedFiles() []*os.File
SharedFiles retreives the open files shared during recent Read calls.
type PairReadWriteCloser ¶
type PairReadWriteCloser struct { io.ReadCloser io.WriteCloser }
A PairReadWriteCloser groups an io.ReadCloser and an io.WriteCloser into a single structure that implements the io.ReadWriteCloser interface. This can be used to turn a pair of uni-directional streams into a single bi-directional stream.
func NewPairReadWriteCloser ¶
func NewPairReadWriteCloser(r io.ReadCloser, w io.WriteCloser) *PairReadWriteCloser
NewPairReadWriteCloser creates a new io.ReadWriteCloser given separate streams for reading and writing. If both streams refer to the same object, then the read stream will be wrapped in an ioutil.NopCloser() so that Close() on the resulting io.ReadWriteCloser() will only close that underlying stream object once.
func (PairReadWriteCloser) Close ¶
func (pair PairReadWriteCloser) Close() error
Close closes the underying streams, both the io.ReadCloser and the io.WriteCloser.
type StringReader ¶
A StringReader is a stream from which strings can be read.
type StringWriter ¶
A StringWriter is a stream to which strings can be written.
type UnixSingleReadWriteCloser ¶
type UnixSingleReadWriteCloser struct {
// contains filtered or unexported fields
}
A UnixSingleReadWriteCloser accepts a single connection and reads and writes to this connection
func (*UnixSingleReadWriteCloser) Close ¶
func (usrwc *UnixSingleReadWriteCloser) Close() error
Close closes the connection if there is one and closes the listener.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package options works in concert with flag, adding prettier printing of options.
|
Package options works in concert with flag, adding prettier printing of options. |
Package protorpc implements a protobuf-based ClientCodec and ServerCodec for the rpc package.
|
Package protorpc implements a protobuf-based ClientCodec and ServerCodec for the rpc package. |