-# Copyright (c) 2010 Nicira Networks
+# Copyright (c) 2010, 2011 Nicira Networks
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
return errno.EAFNOSUPPORT, None
Stream.n_unix_sockets += 1
- bind_path = "/tmp/stream-unix.%ld.%d" % (os.getpid(),
- Stream.n_unix_sockets)
+ bind_path = "/tmp/stream-unix.%d.%d" % (os.getpid(),
+ Stream.n_unix_sockets)
connect_path = name[5:]
error, sock = ovs.socket_util.make_unix_socket(socket.SOCK_STREAM,
True, bind_path,
return 0, Stream(sock, name, bind_path, status)
@staticmethod
- def open_block(tuple):
+ def open_block((error, stream)):
"""Blocks until a Stream completes its connection attempt, either
- succeeding or failing. 'tuple' should be the tuple returned by
+ succeeding or failing. (error, stream) should be the tuple returned by
Stream.open(). Returns a tuple of the same form.
Typical usage:
- error, stream = Stream.open_block(Stream.open("tcp:1.2.3.4:5"))"""
+ error, stream = Stream.open_block(Stream.open("unix:/tmp/socket"))"""
- error, stream = tuple
if not error:
while True:
error = stream.connect()
returns errno.EAGAIN."""
last_state = -1 # Always differs from initial self.state
while self.state != last_state:
+ last_state = self.state
if self.state == Stream.__S_CONNECTING:
self.__scs_connecting()
elif self.state == Stream.__S_CONNECTED:
if self.state == Stream.__S_CONNECTING:
wait = Stream.W_CONNECT
- if wait in (Stream.W_CONNECT, Stream.W_SEND):
- poller.fd_wait(self.socket, select.POLLOUT)
- else:
+ if wait == Stream.W_RECV:
poller.fd_wait(self.socket, select.POLLIN)
+ else:
+ poller.fd_wait(self.socket, select.POLLOUT)
def connect_wait(self, poller):
self.wait(poller, Stream.W_CONNECT)
def send_wait(self, poller):
self.wait(poller, Stream.W_SEND)
- def get_name(self):
- return self.name
-
def __del__(self):
# Don't delete the file: we might have forked.
self.socket.close()