Update copyright on all non-GPL files
[openvswitch] / lib / vlog-socket.c
index b3c2a285226154b41655162615e5da92d8ad03a5..05b91864ccbc182c07e8632baf9c98f0b40d0ca9 100644 (file)
@@ -1,22 +1,34 @@
-/* Copyright (C) 2008 Board of Trustees, Leland Stanford Jr. University.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
+/* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
+ * Junior University
+ * 
+ * We are making the OpenFlow specification and associated documentation
+ * (Software) available for public use and benefit with the expectation
+ * that others will use, modify and enhance the Software and contribute
+ * those enhancements back to the community. However, since we would
+ * like to make the Software available for broadest use, with as few
+ * restrictions as possible permission is hereby granted, free of
+ * charge, to any person obtaining a copy of this Software to deal in
+ * the Software under the copyrights without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ * 
+ * The name and trademarks of copyright holder(s) may NOT be used in
+ * advertising or publicity pertaining to the Software or any
+ * derivatives without specific, written prior permission.
  */
 
 #include "vlog-socket.h"
@@ -31,6 +43,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include "fatal-signal.h"
+#include "poll-loop.h"
 #include "util.h"
 #include "vlog.h"
 
@@ -43,10 +56,13 @@ static int make_unix_socket(bool nonblock, bool passcred,
 \f
 /* Server for Vlog control connection. */
 struct vlog_server {
+    struct poll_waiter *waiter;
     char *path;
     int fd;
 };
 
+static void poll_server(int fd, short int events, void *server_);
+
 /* Start listening for connections from clients and processing their
  * requests.  'path' may be:
  *
@@ -80,10 +96,17 @@ vlog_server_listen(const char *path, struct vlog_server **serverp)
         free(server);
         fprintf(stderr, "Could not initialize vlog configuration socket: %s\n",
                 strerror(-server->fd));
-        *serverp = NULL;
+        if (serverp) {
+            *serverp = NULL; 
+        }
         return fd;
     }
-    *serverp = server;
+
+    server->waiter = poll_fd_callback(server->fd, POLLIN, poll_server, server);
+
+    if (serverp) {
+        *serverp = server; 
+    }
     return 0;
 }
 
@@ -92,6 +115,7 @@ void
 vlog_server_close(struct vlog_server *server)
 {
     if (server) {
+        poll_cancel(server->waiter);
         close(server->fd);
         unlink(server->path);
         fatal_signal_remove_file_to_unlink(server->path);
@@ -100,14 +124,6 @@ vlog_server_close(struct vlog_server *server)
     }
 }
 
-/* Returns the fd used by 'server'.  The caller can poll this fd (POLLIN) to
- * determine when to call vlog_server_poll(). */
-int
-vlog_server_get_fd(const struct vlog_server *server)
-{
-    return server->fd;
-}
-
 static int
 recv_with_creds(const struct vlog_server *server,
                 char *cmd_buf, size_t cmd_buf_size,
@@ -212,9 +228,10 @@ recv_with_creds(const struct vlog_server *server,
 }
 
 /* Processes incoming requests for 'server'. */
-void
-vlog_server_poll(struct vlog_server *server)
+static void
+poll_server(int fd UNUSED, short int events, void *server_)
 {
+    struct vlog_server *server = server_;
     for (;;) {
         char cmd_buf[512];
         struct sockaddr_un un;
@@ -228,7 +245,7 @@ vlog_server_poll(struct vlog_server *server)
                 fprintf(stderr, "vlog: reading configuration socket: %s",
                         strerror(errno));
             }
-            return;
+            break;
         } else if (error < 0) {
             continue;
         }
@@ -246,6 +263,7 @@ vlog_server_poll(struct vlog_server *server)
                (struct sockaddr*) &un, un_len);
         free(reply);
     }
+    server->waiter = poll_fd_callback(server->fd, POLLIN, poll_server, server);
 }
 \f
 /* Client for Vlog control connection. */