goplumb

package module
v0.4.1-0...-74c2db1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: BSD-3-Clause Imports: 10 Imported by: 1

README

goplumb

goplumb provides interface to plumber - interprocess messaging from Plan 9

Documentation

Overview

This file is part of ahist

Copyright (c) 2013, 2020 Alexander Sychev. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright

notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above

copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • The name of author may not be used to endorse or promote products derived from

this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Package goplumb provides interface to plumber - interprocess messaging from Plan 9.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pack

func Pack(message *Message) []byte

Pack packs a message to []byte.

func PackAttr

func PackAttr(attr Attrs) string

PackAttr packs attr to string. If an attribute value contains a white space, a quote or an equal sign the value will be quoted.

Types

type Attrs

type Attrs map[string]string

Attrs is a map of an attribute of a plumber message.

func UnpackAttr

func UnpackAttr(s string) Attrs

UnpackAttr unpack the attributes from s to Attrs

type Message

type Message struct {
	Src  string
	Dst  string
	Wdir string
	Type string
	Attr Attrs
	Data []byte
}

Message desribes a plumber message.

func Unpack

func Unpack(b []byte) *Message

Unpack return a pointer to an unpacked message *Message.

func UnpackPartial

func UnpackPartial(b []byte) (m *Message, r int)

UnpackPartial helps to unpack messages splited in peaces. The first call to UnpackPartial for a given message must be sufficient to unpack the header; subsequent calls permit unpacking messages with long data sections. For each call, b contans the complete message received so far. If the message is complete, a pointer to the resulting message m will be returned, and a number of remainings bytes r will be set to 0. Otherwise m will be nil and r will be set to the number of bytes remaining to be read for this message to be complete (recall that the byte count is in the header). Those bytes should be read by the caller, placed at location b[r:], and the message unpacked again. If an error is encountered, m will be nil and r will be zero.

type Plumb

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

func Open

func Open(port string, omode uint8) (*Plumb, error)

Open opens a specified port with a specified omode and returns *Plumb or error

func (*Plumb) Close

func (this *Plumb) Close()

Close closes the plumbing connection.

func (*Plumb) MessageChannel

func (this *Plumb) MessageChannel(size int) (<-chan *Message, error)

MessageChannel returns a channel of *Message with a buffer size from which messages can be read or error. First call of MessageChannel starts a goroutine to read messages put them to the channel. Subsequent calls of EventChannel will return the same channel.

func (*Plumb) Recv

func (this *Plumb) Recv() (*Message, error)

Recv returns a pointer to a received message *Message or error.

func (*Plumb) Send

func (this *Plumb) Send(message *Message) error

Send sends a message and returns error if any.

func (*Plumb) SendText

func (this *Plumb) SendText(src string, dst string, wdir string, data string) error

SendText sends a text-only message; it assumes Type is text and Attr is empty. SendText returns error if any.

Jump to

Keyboard shortcuts

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