Line | |
---|
1 | """ |
---|
2 | Writing to non-blocking pipe can result in ENOSPC when using Unix APIs on |
---|
3 | Windows. So, this program passes through data from stdin to stdout, using |
---|
4 | Windows APIs instead of Unix-y APIs. |
---|
5 | """ |
---|
6 | |
---|
7 | from twisted.internet.stdio import StandardIO |
---|
8 | from twisted.internet import reactor |
---|
9 | from twisted.internet.protocol import Protocol |
---|
10 | from twisted.internet.interfaces import IHalfCloseableProtocol |
---|
11 | from twisted.internet.error import ReactorNotRunning |
---|
12 | from zope.interface import implementer |
---|
13 | |
---|
14 | @implementer(IHalfCloseableProtocol) |
---|
15 | class Passthrough(Protocol): |
---|
16 | def readConnectionLost(self): |
---|
17 | self.transport.loseConnection() |
---|
18 | |
---|
19 | def writeConnectionLost(self): |
---|
20 | try: |
---|
21 | reactor.stop() |
---|
22 | except ReactorNotRunning: |
---|
23 | pass |
---|
24 | |
---|
25 | def dataReceived(self, data): |
---|
26 | self.transport.write(data) |
---|
27 | |
---|
28 | def connectionLost(self, reason): |
---|
29 | try: |
---|
30 | reactor.stop() |
---|
31 | except ReactorNotRunning: |
---|
32 | pass |
---|
33 | |
---|
34 | |
---|
35 | std = StandardIO(Passthrough()) |
---|
36 | reactor.run() |
---|
Note: See
TracBrowser
for help on using the repository browser.