• Stars
    star
    282
  • Rank 141,697 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created about 11 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Windows named pipe implementation written in pure Go.

npipe Build status GoDoc

Package npipe provides a pure Go wrapper around Windows named pipes.

Windows named pipe documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365780

Note that the code lives at https://github.com/natefinch/npipe (v2 branch) but should be imported as gopkg.in/natefinch/npipe.v2 (the package name is still npipe).

npipe provides an interface based on stdlib's net package, with Dial, Listen, and Accept functions, as well as associated implementations of net.Conn and net.Listener. It supports rpc over the connection.

Notes

  • Deadlines for reading/writing to the connection are only functional in Windows Vista/Server 2008 and above, due to limitations with the Windows API.

  • The pipes support byte mode only (no support for message mode)

Examples

The Dial function connects a client to a named pipe:

conn, err := npipe.Dial(`\\.\pipe\mypipename`)
if err != nil {
	<handle error>
}
fmt.Fprintf(conn, "Hi server!\n")
msg, err := bufio.NewReader(conn).ReadString('\n')
...

The Listen function creates servers:

ln, err := npipe.Listen(`\\.\pipe\mypipename`)
if err != nil {
	// handle error
}
for {
	conn, err := ln.Accept()
	if err != nil {
		// handle error
		continue
	}
	go handleConnection(conn)
}

Variables

var ErrClosed = PipeError{"Pipe has been closed.", false}

ErrClosed is the error returned by PipeListener.Accept when Close is called on the PipeListener.

type PipeAddr

type PipeAddr string

PipeAddr represents the address of a named pipe.

func (PipeAddr) Network

func (a PipeAddr) Network() string

Network returns the address's network name, "pipe".

func (PipeAddr) String

func (a PipeAddr) String() string

String returns the address of the pipe

type PipeConn

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

PipeConn is the implementation of the net.Conn interface for named pipe connections.

func Dial

func Dial(address string) (*PipeConn, error)

Dial connects to a named pipe with the given address. If the specified pipe is not available, it will wait indefinitely for the pipe to become available.

The address must be of the form \.\pipe<name> for local pipes and \\pipe<name> for remote pipes.

Dial will return a PipeError if you pass in a badly formatted pipe name.

Examples:

// local pipe
conn, err := Dial(`\\.\pipe\mypipename`)

// remote pipe
conn, err := Dial(`\\othercomp\pipe\mypipename`)

func DialTimeout

func DialTimeout(address string, timeout time.Duration) (*PipeConn, error)

DialTimeout acts like Dial, but will time out after the duration of timeout

func (*PipeConn) Close

func (c *PipeConn) Close() error

Close closes the connection.

func (*PipeConn) LocalAddr

func (c *PipeConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*PipeConn) Read

func (c *PipeConn) Read(b []byte) (int, error)

Read implements the net.Conn Read method.

func (*PipeConn) RemoteAddr

func (c *PipeConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*PipeConn) SetDeadline

func (c *PipeConn) SetDeadline(t time.Time) error

SetDeadline implements the net.Conn SetDeadline method. Note that timeouts are only supported on Windows Vista/Server 2008 and above

func (*PipeConn) SetReadDeadline

func (c *PipeConn) SetReadDeadline(t time.Time) error

SetReadDeadline implements the net.Conn SetReadDeadline method. Note that timeouts are only supported on Windows Vista/Server 2008 and above

func (*PipeConn) SetWriteDeadline

func (c *PipeConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the net.Conn SetWriteDeadline method. Note that timeouts are only supported on Windows Vista/Server 2008 and above

func (*PipeConn) Write

func (c *PipeConn) Write(b []byte) (int, error)

Write implements the net.Conn Write method.

type PipeError

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

PipeError is an error related to a call to a pipe

func (PipeError) Error

func (e PipeError) Error() string

Error implements the error interface

func (PipeError) Temporary

func (e PipeError) Temporary() bool

Temporary implements net.AddrError.Temporary()

func (PipeError) Timeout

func (e PipeError) Timeout() bool

Timeout implements net.AddrError.Timeout()

type PipeListener

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

PipeListener is a named pipe listener. Clients should typically use variables of type net.Listener instead of assuming named pipe.

func Listen

func Listen(address string) (*PipeListener, error)

Listen returns a new PipeListener that will listen on a pipe with the given address. The address must be of the form \.\pipe<name>

Listen will return a PipeError for an incorrectly formatted pipe name.

func (*PipeListener) Accept

func (l *PipeListener) Accept() (net.Conn, error)

Accept implements the Accept method in the net.Listener interface; it waits for the next call and returns a generic net.Conn.

func (*PipeListener) AcceptPipe

func (l *PipeListener) AcceptPipe() (*PipeConn, error)

AcceptPipe accepts the next incoming call and returns the new connection.

func (*PipeListener) Addr

func (l *PipeListener) Addr() net.Addr

Addr returns the listener's network address, a PipeAddr.

func (*PipeListener) Close

func (l *PipeListener) Close() error

Close stops listening on the address. Already Accepted connections are not closed.

More Repositories

1

lumberjack

lumberjack is a log rolling package for Go
Go
4,272
star
2

gorram

It's like go run for any go function
Go
1,038
star
3

pie

a toolkit for creating plugins for Go applications
Go
747
star
4

deputy

deputy is a go package that adds smarts on top of os/exec
Go
230
star
5

atomic

atomic is a go package for atomic file writing
Go
190
star
6

godocgo

An example of good godoc documentation.
Go
154
star
7

gocog

Generate code for any language, with any language.
Go
68
star
8

sh

Package sh makes working with shell commands more shell-like. Inspired by https://github.com/amoffat/sh
Go
52
star
9

npf

code to host a professional site
CSS
52
star
10

graffiti

graffiti is a tool to automatically add struct tags to fields in your go code
Go
38
star
11

claymud

Highly configurable and performant MUD written in Go
Go
28
star
12

keep

Go bindings wrapping the Google Keep API
Go
22
star
13

diceware

an implementation of the diceware passphrase generation algorithm
Go
21
star
14

blogimport

A tool to import from Blogger to Hugo
Go
20
star
15

tree

A statically typed binary tree in Go without casts or reflection
Go
19
star
16

pcgrep

Go
15
star
17

covergen

autogenerate a coverage badge for your README with with one dumb trick
Go
10
star
18

convert

An application to convert and resize images written in Go.
Go
10
star
19

plugman

a plugin manifest manager for go
9
star
20

q

Q is a CLI tool for developers that can do anything.
Go
8
star
21

avl

Go
6
star
22

natefinch.github.io

nate's sweet website
HTML
5
star
23

tod

A Hugo site for my D&D campaign
CSS
4
star
24

wrap

Wrap contains a method for wrapping one Go error with another.
Go
4
star
25

filterr

go package that helps filter returned errors to a specific list
Go
4
star
26

Ashes2Ashes

A modified CircleMUD that ran in the late 90's.
C
3
star
27

cavalier

a command line interface generator for Go
Go
3
star
28

emojis-and-dragons

2
star
29

nolog

just a dumb little tool to run juju tests and filter out all the logging
Go
2
star
30

sheet.monster

Public Issue Tracking for https://sheet.monster
1
star
31

natefinch

1
star
32

harvard-4-h

CSS
1
star
33

circle2json

converts CircleMUD room definitions to json equivalents
Go
1
star
34

rpg

a personal website about RPGs
CSS
1
star
35

go-quickstart

Go
1
star
36

burningchrome

A website for the in-development Burning Chrome RPG.
CSS
1
star
37

eg

An enhanced error package for Go
Go
1
star
38

tabletop.design

HTML
1
star
39

treesample

Sample project using natefinch/tree
Go
1
star