Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Vladimir
noc
Commits
ac4ee78f
Commit
ac4ee78f
authored
Sep 01, 2009
by
Dmitry Volodin
Browse files
PopenSocket
parent
8a8de78f
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/nbsocket.py
View file @
ac4ee78f
...
...
@@ -5,7 +5,7 @@
## Copyright (C) 2007-2009 The NOC Project
## See LICENSE for details
##----------------------------------------------------------------------
import
socket
,
select
,
errno
,
time
,
logging
,
pty
,
os
,
signal
import
socket
,
select
,
errno
,
time
,
logging
,
pty
,
os
,
signal
,
subprocess
from
errno
import
EALREADY
,
EINPROGRESS
,
EWOULDBLOCK
,
ECONNRESET
,
\
ENOTCONN
,
ESHUTDOWN
,
EINTR
,
EISCONN
,
ECONNREFUSED
,
EPIPE
,
errorcode
from
noc.lib.debug
import
error_report
...
...
@@ -441,7 +441,31 @@ class PTYSocket(Socket):
def
on_read
(
self
,
data
):
pass
##
## PopenSocket
## Events: on_read, on_close
##
class
PopenSocket
(
Socket
):
def
__init__
(
self
,
factory
,
argv
):
self
.
debug
(
"Launching %s"
%
argv
)
self
.
p
=
subprocess
.
Popen
(
argv
,
stdout
=
subprocess
.
PIPE
)
super
(
PopenSocket
,
self
).
__init__
(
factory
,
FileWrapper
(
self
.
p
.
stdout
.
fileno
()))
self
.
update_status
()
def
handle_read
(
self
):
try
:
data
=
self
.
socket
.
read
(
8192
)
except
OSError
:
self
.
close
()
return
self
.
update_status
()
if
data
:
self
.
on_read
(
data
)
else
:
self
.
close
()
def
close
(
self
):
Socket
.
close
(
self
)
##
## Socket Factory.
## Methods:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment