python/ovs: socket_util uses select.poll
[sliver-openvswitch.git] / python / ovs / socket_util.py
index 65fe94d..a978707 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2010 Nicira Networks
+# Copyright (c) 2010, 2012 Nicira, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # limitations under the License.
 
 import errno
-import logging
 import os
 import select
 import socket
 import sys
 
 import ovs.fatal_signal
+import ovs.poller
+import ovs.vlog
+
+vlog = ovs.vlog.Vlog("socket_util")
 
 
 def make_unix_socket(style, nonblock, bind_path, connect_path):
@@ -67,17 +70,13 @@ def make_unix_socket(style, nonblock, bind_path, connect_path):
         return 0, sock
     except socket.error, e:
         sock.close()
-        try:
-            os.unlink(bind_path)
-        except OSError, e:
-            pass
         if bind_path is not None:
-            ovs.fatal_signal.add_file_to_unlink(bind_path)
+            ovs.fatal_signal.unlink_file_now(bind_path)
         return get_exception_errno(e), None
 
 
 def check_connection_completion(sock):
-    p = select.poll()
+    p = ovs.poller.SelectPoll()
     p.register(sock, select.POLLOUT)
     if len(p.poll(0)) == 1:
         return get_socket_error(sock)
@@ -114,8 +113,7 @@ def get_null_fd():
         try:
             null_fd = os.open("/dev/null", os.O_RDWR)
         except OSError, e:
-            logging.error("could not open /dev/null: %s"
-                          % os.strerror(e.errno))
+            vlog.err("could not open /dev/null: %s" % os.strerror(e.errno))
             return -e.errno
     return null_fd
 
@@ -135,7 +133,7 @@ def write_fully(fd, buf):
             if retval == len(buf):
                 return 0, bytes_written + len(buf)
             elif retval == 0:
-                logging.warning("write returned 0")
+                vlog.warn("write returned 0")
                 return errno.EPROTO, bytes_written
             else:
                 bytes_written += retval
@@ -148,5 +146,5 @@ def set_nonblocking(sock):
     try:
         sock.setblocking(0)
     except socket.error, e:
-        logging.error("could not set nonblocking mode on socket: %s"
-                      % os.strerror(get_socket_error(e)))
+        vlog.err("could not set nonblocking mode on socket: %s"
+                 % os.strerror(get_socket_error(e)))