# limitations under the License.
import errno
-import logging
import os
import select
import socket
-import sys
import ovs.poller
import ovs.socket_util
+import ovs.vlog
+
+vlog = ovs.vlog.Vlog("stream")
+
class Stream(object):
"""Bidirectional byte stream. Currently only Unix domain sockets
stream.connect_wait(poller)
poller.block()
assert error != errno.EINPROGRESS
-
+
if error and stream:
stream.close()
stream = None
def recv(self, n):
"""Tries to receive up to 'n' bytes from this stream. Returns a
(error, string) tuple:
-
+
- If successful, 'error' is zero and 'string' contains between 1
and 'n' bytes of data.
- If the connection has been closed in the normal fashion or if 'n'
is 0, the tuple is (0, "").
-
+
The recv function will not block waiting for data to arrive. If no
data have been received, it returns (errno.EAGAIN, "") immediately."""
def connect_wait(self, poller):
self.wait(poller, Stream.W_CONNECT)
-
+
def recv_wait(self, poller):
self.wait(poller, Stream.W_RECV)
-
+
def send_wait(self, poller):
self.wait(poller, Stream.W_SEND)
-
+
def __del__(self):
# Don't delete the file: we might have forked.
self.socket.close()
+
class PassiveStream(object):
@staticmethod
def is_valid_name(name):
try:
sock.listen(10)
except socket.error, e:
- logging.error("%s: listen: %s" % (name, os.strerror(e.error)))
+ vlog.err("%s: listen: %s" % (name, os.strerror(e.error)))
sock.close()
return e.error, None
error = ovs.socket_util.get_exception_errno(e)
if error != errno.EAGAIN:
# XXX rate-limit
- logging.debug("accept: %s" % os.strerror(error))
+ vlog.dbg("accept: %s" % os.strerror(error))
return error, None
def wait(self, poller):
# Don't delete the file: we might have forked.
self.socket.close()
-def usage(name, active, passive, bootstrap):
- print
- if active:
- print("Active %s connection methods:" % name)
- print(" unix:FILE "
- "Unix domain socket named FILE");
-
- if passive:
- print("Passive %s connection methods:" % name)
- print(" punix:FILE "
- "listen on Unix domain socket FILE")
+
+def usage(name):
+ return """
+Active %s connection methods:
+ unix:FILE Unix domain socket named FILE
+
+Passive %s connection methods:
+ punix:FILE Listen on Unix domain socket FILE""" % (name, name)