vendor/gopkg.in/natefinch/npipe.v2/README.md

308 lines · 6113 bytes

  1npipe  [![Build status](https://ci.appveyor.com/api/projects/status/00vuepirsot29qwi)](https://ci.appveyor.com/project/natefinch/npipe) [![GoDoc](https://godoc.org/gopkg.in/natefinch/npipe.v2?status.svg)](https://godoc.org/gopkg.in/natefinch/npipe.v2)
  2=====
  3Package npipe provides a pure Go wrapper around Windows named pipes.
  4
  5Windows named pipe documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365780
  6
  7Note that the code lives at https://github.com/natefinch/npipe (v2 branch)
  8but should be imported as gopkg.in/natefinch/npipe.v2 (the package name is
  9still npipe).
 10
 11npipe provides an interface based on stdlib's net package, with Dial, Listen,
 12and Accept functions, as well as associated implementations of net.Conn and
 13net.Listener.  It supports rpc over the connection.
 14
 15### Notes
 16* Deadlines for reading/writing to the connection are only functional in Windows Vista/Server 2008 and above, due to limitations with the Windows API.
 17
 18* The pipes support byte mode only (no support for message mode)
 19
 20### Examples
 21The Dial function connects a client to a named pipe:
 22
 23
 24	conn, err := npipe.Dial(`\\.\pipe\mypipename`)
 25	if err != nil {
 26		<handle error>
 27	}
 28	fmt.Fprintf(conn, "Hi server!\n")
 29	msg, err := bufio.NewReader(conn).ReadString('\n')
 30	...
 31
 32The Listen function creates servers:
 33
 34
 35	ln, err := npipe.Listen(`\\.\pipe\mypipename`)
 36	if err != nil {
 37		// handle error
 38	}
 39	for {
 40		conn, err := ln.Accept()
 41		if err != nil {
 42			// handle error
 43			continue
 44		}
 45		go handleConnection(conn)
 46	}
 47
 48
 49
 50
 51
 52## Variables
 53``` go
 54var ErrClosed = PipeError{"Pipe has been closed.", false}
 55```
 56ErrClosed is the error returned by PipeListener.Accept when Close is called
 57on the PipeListener.
 58
 59
 60
 61## type PipeAddr
 62``` go
 63type PipeAddr string
 64```
 65PipeAddr represents the address of a named pipe.
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77### func (PipeAddr) Network
 78``` go
 79func (a PipeAddr) Network() string
 80```
 81Network returns the address's network name, "pipe".
 82
 83
 84
 85### func (PipeAddr) String
 86``` go
 87func (a PipeAddr) String() string
 88```
 89String returns the address of the pipe
 90
 91
 92
 93## type PipeConn
 94``` go
 95type PipeConn struct {
 96    // contains filtered or unexported fields
 97}
 98```
 99PipeConn is the implementation of the net.Conn interface for named pipe connections.
100
101
102
103
104
105
106
107
108
109### func Dial
110``` go
111func Dial(address string) (*PipeConn, error)
112```
113Dial connects to a named pipe with the given address. If the specified pipe is not available,
114it will wait indefinitely for the pipe to become available.
115
116The address must be of the form \\.\\pipe\<name> for local pipes and \\<computer>\pipe\<name>
117for remote pipes.
118
119Dial will return a PipeError if you pass in a badly formatted pipe name.
120
121Examples:
122
123
124	// local pipe
125	conn, err := Dial(`\\.\pipe\mypipename`)
126	
127	// remote pipe
128	conn, err := Dial(`\\othercomp\pipe\mypipename`)
129
130
131### func DialTimeout
132``` go
133func DialTimeout(address string, timeout time.Duration) (*PipeConn, error)
134```
135DialTimeout acts like Dial, but will time out after the duration of timeout
136
137
138
139
140### func (\*PipeConn) Close
141``` go
142func (c *PipeConn) Close() error
143```
144Close closes the connection.
145
146
147
148### func (\*PipeConn) LocalAddr
149``` go
150func (c *PipeConn) LocalAddr() net.Addr
151```
152LocalAddr returns the local network address.
153
154
155
156### func (\*PipeConn) Read
157``` go
158func (c *PipeConn) Read(b []byte) (int, error)
159```
160Read implements the net.Conn Read method.
161
162
163
164### func (\*PipeConn) RemoteAddr
165``` go
166func (c *PipeConn) RemoteAddr() net.Addr
167```
168RemoteAddr returns the remote network address.
169
170
171
172### func (\*PipeConn) SetDeadline
173``` go
174func (c *PipeConn) SetDeadline(t time.Time) error
175```
176SetDeadline implements the net.Conn SetDeadline method.
177Note that timeouts are only supported on Windows Vista/Server 2008 and above
178
179
180
181### func (\*PipeConn) SetReadDeadline
182``` go
183func (c *PipeConn) SetReadDeadline(t time.Time) error
184```
185SetReadDeadline implements the net.Conn SetReadDeadline method.
186Note that timeouts are only supported on Windows Vista/Server 2008 and above
187
188
189
190### func (\*PipeConn) SetWriteDeadline
191``` go
192func (c *PipeConn) SetWriteDeadline(t time.Time) error
193```
194SetWriteDeadline implements the net.Conn SetWriteDeadline method.
195Note that timeouts are only supported on Windows Vista/Server 2008 and above
196
197
198
199### func (\*PipeConn) Write
200``` go
201func (c *PipeConn) Write(b []byte) (int, error)
202```
203Write implements the net.Conn Write method.
204
205
206
207## type PipeError
208``` go
209type PipeError struct {
210    // contains filtered or unexported fields
211}
212```
213PipeError is an error related to a call to a pipe
214
215
216
217
218
219
220
221
222
223
224
225### func (PipeError) Error
226``` go
227func (e PipeError) Error() string
228```
229Error implements the error interface
230
231
232
233### func (PipeError) Temporary
234``` go
235func (e PipeError) Temporary() bool
236```
237Temporary implements net.AddrError.Temporary()
238
239
240
241### func (PipeError) Timeout
242``` go
243func (e PipeError) Timeout() bool
244```
245Timeout implements net.AddrError.Timeout()
246
247
248
249## type PipeListener
250``` go
251type PipeListener struct {
252    // contains filtered or unexported fields
253}
254```
255PipeListener is a named pipe listener. Clients should typically
256use variables of type net.Listener instead of assuming named pipe.
257
258
259
260
261
262
263
264
265
266### func Listen
267``` go
268func Listen(address string) (*PipeListener, error)
269```
270Listen returns a new PipeListener that will listen on a pipe with the given
271address. The address must be of the form \\.\pipe\<name>
272
273Listen will return a PipeError for an incorrectly formatted pipe name.
274
275
276
277
278### func (\*PipeListener) Accept
279``` go
280func (l *PipeListener) Accept() (net.Conn, error)
281```
282Accept implements the Accept method in the net.Listener interface; it
283waits for the next call and returns a generic net.Conn.
284
285
286
287### func (\*PipeListener) AcceptPipe
288``` go
289func (l *PipeListener) AcceptPipe() (*PipeConn, error)
290```
291AcceptPipe accepts the next incoming call and returns the new connection.
292
293
294
295### func (\*PipeListener) Addr
296``` go
297func (l *PipeListener) Addr() net.Addr
298```
299Addr returns the listener's network address, a PipeAddr.
300
301
302
303### func (\*PipeListener) Close
304``` go
305func (l *PipeListener) Close() error
306```
307Close stops listening on the address.
308Already Accepted connections are not closed.