-/* 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"
#include <sys/types.h>
#include <unistd.h>
#include "fatal-signal.h"
+#include "poll-loop.h"
#include "util.h"
#include "vlog.h"
\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:
*
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;
}
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);
}
}
-/* 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,
}
/* 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;
fprintf(stderr, "vlog: reading configuration socket: %s",
strerror(errno));
}
- return;
+ break;
} else if (error < 0) {
continue;
}
(struct sockaddr*) &un, un_len);
free(reply);
}
+ server->waiter = poll_fd_callback(server->fd, POLLIN, poll_server, server);
}
\f
/* Client for Vlog control connection. */