rconn_run(struct rconn *rc)
{
int old_state;
+ size_t i;
+
+ if (rc->vconn) {
+ vconn_run(rc->vconn);
+ }
+ for (i = 0; i < rc->n_monitors; i++) {
+ vconn_run(rc->monitors[i]);
+ }
+
do {
old_state = rc->state;
switch (rc->state) {
void
rconn_run_wait(struct rconn *rc)
{
- unsigned int timeo = timeout(rc);
+ unsigned int timeo;
+ size_t i;
+
+ if (rc->vconn) {
+ vconn_run_wait(rc->vconn);
+ }
+ for (i = 0; i < rc->n_monitors; i++) {
+ vconn_run_wait(rc->monitors[i]);
+ }
+
+ timeo = timeout(rc);
if (timeo != UINT_MAX) {
unsigned int expires = sat_add(rc->state_entered, timeo);
unsigned int remaining = sat_sub(expires, time_now());
* accepted for transmission, it should return EAGAIN. */
int (*send)(struct vconn *vconn, struct ofpbuf *msg);
+ /* Allows 'vconn' to perform maintenance activities, such as flushing
+ * output buffers.
+ *
+ * May be null if 'vconn' doesn't have anything to do here. */
+ void (*run)(struct vconn *vconn);
+
+ /* Arranges for the poll loop to wake up when 'vconn' needs to perform
+ * maintenance activities.
+ *
+ * May be null if 'vconn' doesn't have anything to do here. */
+ void (*run_wait)(struct vconn *vconn);
+
/* Arranges for the poll loop to wake up when 'vconn' is ready to take an
* action of the given 'type'. */
void (*wait)(struct vconn *vconn, enum vconn_wait_type type);
SSL *ssl;
struct ofpbuf *rxbuf;
struct ofpbuf *txbuf;
- struct poll_waiter *tx_waiter;
/* rx_want and tx_want record the result of the last call to SSL_read()
* and SSL_write(), respectively:
static void ssl_clear_txbuf(struct ssl_vconn *);
static int interpret_ssl_error(const char *function, int ret, int error,
int *want);
-static void ssl_tx_poll_callback(int fd, short int revents, void *vconn_);
static DH *tmp_dh_callback(SSL *ssl, int is_export UNUSED, int keylength);
static void log_ca_cert(const char *file_name, X509 *cert);
sslv->ssl = ssl;
sslv->rxbuf = NULL;
sslv->txbuf = NULL;
- sslv->tx_waiter = NULL;
sslv->rx_want = sslv->tx_want = SSL_NOTHING;
*vconnp = &sslv->vconn;
return 0;
ssl_close(struct vconn *vconn)
{
struct ssl_vconn *sslv = ssl_vconn_cast(vconn);
- poll_cancel(sslv->tx_waiter);
ssl_clear_txbuf(sslv);
ofpbuf_delete(sslv->rxbuf);
SSL_free(sslv->ssl);
ret = SSL_read(sslv->ssl, ofpbuf_tail(rx), want_bytes);
if (old_state != SSL_get_state(sslv->ssl)) {
sslv->tx_want = SSL_NOTHING;
- if (sslv->tx_waiter) {
- poll_cancel(sslv->tx_waiter);
- ssl_tx_poll_callback(sslv->fd, POLLIN, vconn);
- }
}
sslv->rx_want = SSL_NOTHING;
{
ofpbuf_delete(sslv->txbuf);
sslv->txbuf = NULL;
- sslv->tx_waiter = NULL;
-}
-
-static void
-ssl_register_tx_waiter(struct vconn *vconn)
-{
- struct ssl_vconn *sslv = ssl_vconn_cast(vconn);
- sslv->tx_waiter = poll_fd_callback(sslv->fd,
- want_to_poll_events(sslv->tx_want),
- ssl_tx_poll_callback, vconn);
}
static int
}
}
-static void
-ssl_tx_poll_callback(int fd UNUSED, short int revents UNUSED, void *vconn_)
-{
- struct vconn *vconn = vconn_;
- struct ssl_vconn *sslv = ssl_vconn_cast(vconn);
- int error = ssl_do_tx(vconn);
- if (error != EAGAIN) {
- ssl_clear_txbuf(sslv);
- } else {
- ssl_register_tx_waiter(vconn);
- }
-}
-
static int
ssl_send(struct vconn *vconn, struct ofpbuf *buffer)
{
return 0;
case EAGAIN:
leak_checker_claim(buffer);
- ssl_register_tx_waiter(vconn);
return 0;
default:
sslv->txbuf = NULL;
}
}
+static void
+ssl_run(struct vconn *vconn)
+{
+ struct ssl_vconn *sslv = ssl_vconn_cast(vconn);
+
+ if (sslv->txbuf && ssl_do_tx(vconn) != EAGAIN) {
+ ssl_clear_txbuf(sslv);
+ }
+}
+
+static void
+ssl_run_wait(struct vconn *vconn)
+{
+ struct ssl_vconn *sslv = ssl_vconn_cast(vconn);
+
+ if (sslv->tx_want != SSL_NOTHING) {
+ poll_fd_wait(sslv->fd, want_to_poll_events(sslv->tx_want));
+ }
+}
+
static void
ssl_wait(struct vconn *vconn, enum vconn_wait_type wait)
{
/* We have room in our tx queue. */
poll_immediate_wake();
} else {
- /* The call to ssl_tx_poll_callback() will wake us up. */
+ /* vconn_run_wait() will do the right thing; don't bother with
+ * redundancy. */
}
break;
ssl_connect, /* connect */
ssl_recv, /* recv */
ssl_send, /* send */
+ ssl_run, /* run */
+ ssl_run_wait, /* run_wait */
ssl_wait, /* wait */
};
\f
int fd;
struct ofpbuf *rxbuf;
struct ofpbuf *txbuf;
- struct poll_waiter *tx_waiter;
char *unlink_path;
};
vconn_init(&s->vconn, &stream_vconn_class, connect_status, name);
s->fd = fd;
s->txbuf = NULL;
- s->tx_waiter = NULL;
s->rxbuf = NULL;
s->unlink_path = unlink_path;
*vconnp = &s->vconn;
stream_close(struct vconn *vconn)
{
struct stream_vconn *s = stream_vconn_cast(vconn);
- poll_cancel(s->tx_waiter);
stream_clear_txbuf(s);
ofpbuf_delete(s->rxbuf);
close(s->fd);
{
ofpbuf_delete(s->txbuf);
s->txbuf = NULL;
- s->tx_waiter = NULL;
-}
-
-static void
-stream_do_tx(int fd UNUSED, short int revents UNUSED, void *vconn_)
-{
- struct vconn *vconn = vconn_;
- struct stream_vconn *s = stream_vconn_cast(vconn);
- ssize_t n = write(s->fd, s->txbuf->data, s->txbuf->size);
- if (n < 0) {
- if (errno != EAGAIN) {
- VLOG_ERR_RL(&rl, "send: %s", strerror(errno));
- stream_clear_txbuf(s);
- return;
- }
- } else if (n > 0) {
- ofpbuf_pull(s->txbuf, n);
- if (!s->txbuf->size) {
- stream_clear_txbuf(s);
- return;
- }
- }
- s->tx_waiter = poll_fd_callback(s->fd, POLLOUT, stream_do_tx, vconn);
}
static int
if (retval > 0) {
ofpbuf_pull(buffer, retval);
}
- s->tx_waiter = poll_fd_callback(s->fd, POLLOUT, stream_do_tx, vconn);
return 0;
} else {
return errno;
}
}
+static void
+stream_run(struct vconn *vconn)
+{
+ struct stream_vconn *s = stream_vconn_cast(vconn);
+ ssize_t n;
+
+ if (!s->txbuf) {
+ return;
+ }
+
+ n = write(s->fd, s->txbuf->data, s->txbuf->size);
+ if (n < 0) {
+ if (errno != EAGAIN) {
+ VLOG_ERR_RL(&rl, "send: %s", strerror(errno));
+ stream_clear_txbuf(s);
+ return;
+ }
+ } else if (n > 0) {
+ ofpbuf_pull(s->txbuf, n);
+ if (!s->txbuf->size) {
+ stream_clear_txbuf(s);
+ return;
+ }
+ }
+}
+
+static void
+stream_run_wait(struct vconn *vconn)
+{
+ struct stream_vconn *s = stream_vconn_cast(vconn);
+
+ if (s->txbuf) {
+ poll_fd_wait(s->fd, POLLOUT);
+ }
+}
+
static void
stream_wait(struct vconn *vconn, enum vconn_wait_type wait)
{
if (!s->txbuf) {
poll_fd_wait(s->fd, POLLOUT);
} else {
- /* Nothing to do: need to drain txbuf first. */
+ /* Nothing to do: need to drain txbuf first. stream_run_wait()
+ * will arrange to wake up when there room to send data, so there's
+ * no point in calling poll_fd_wait() redundantly here. */
}
break;
stream_connect, /* connect */
stream_recv, /* recv */
stream_send, /* send */
+ stream_run, /* run */
+ stream_run_wait, /* run_wait */
stream_wait, /* wait */
};
\f
NULL, /* connect */
NULL, /* recv */
NULL, /* send */
+ NULL, /* run */
+ NULL, /* run_wait */
NULL, /* wait */
};
\f
NULL, /* connect */
NULL, /* recv */
NULL, /* send */
+ NULL, /* run */
+ NULL, /* run_wait */
NULL, /* wait */
};
\f
/*
- * Copyright (c) 2008, 2009 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
struct vconn_class *class = vconn_classes[i];
assert(class->name != NULL);
assert(class->open != NULL);
- if (class->close || class->recv || class->send || class->wait) {
+ if (class->close || class->recv || class->send
+ || class->run || class->run_wait || class->wait) {
assert(class->close != NULL);
assert(class->recv != NULL);
assert(class->send != NULL);
return EAFNOSUPPORT;
}
+/* Allows 'vconn' to perform maintenance activities, such as flushing output
+ * buffers. */
+void
+vconn_run(struct vconn *vconn)
+{
+ if (vconn->class->run) {
+ (vconn->class->run)(vconn);
+ }
+}
+
+/* Arranges for the poll loop to wake up when 'vconn' needs to perform
+ * maintenance activities. */
+void
+vconn_run_wait(struct vconn *vconn)
+{
+ if (vconn->class->run_wait) {
+ (vconn->class->run_wait)(vconn);
+ }
+}
+
int
vconn_open_block(const char *name, int min_version, struct vconn **vconnp)
{
error = vconn_open(name, min_version, &vconn);
while (error == EAGAIN) {
+ vconn_run(vconn);
+ vconn_run_wait(vconn);
vconn_connect_wait(vconn);
poll_block();
error = vconn_connect(vconn);
{
int retval;
while ((retval = vconn_send(vconn, msg)) == EAGAIN) {
+ vconn_run(vconn);
+ vconn_run_wait(vconn);
vconn_send_wait(vconn);
poll_block();
}
{
int retval;
while ((retval = vconn_recv(vconn, msgp)) == EAGAIN) {
+ vconn_run(vconn);
+ vconn_run_wait(vconn);
vconn_recv_wait(vconn);
poll_block();
}
int vconn_recv_xid(struct vconn *, uint32_t xid, struct ofpbuf **);
int vconn_transact(struct vconn *, struct ofpbuf *, struct ofpbuf **);
+void vconn_run(struct vconn *);
+void vconn_run_wait(struct vconn *);
+
int vconn_open_block(const char *name, int min_version, struct vconn **);
int vconn_send_block(struct vconn *, struct ofpbuf *);
int vconn_recv_block(struct vconn *, struct ofpbuf **);
fpv_create(type, &fpv);
assert(!vconn_open(fpv.vconn_name, OFP_VERSION, &vconn));
fpv_close(&fpv);
+ vconn_run(vconn);
assert(vconn_connect(vconn) == expected_error);
vconn_close(vconn);
fpv_destroy(&fpv);
fpv_create(type, &fpv);
assert(!vconn_open(fpv.vconn_name, OFP_VERSION, &vconn));
+ vconn_run(vconn);
close(fpv_accept(&fpv));
fpv_close(&fpv);
assert(vconn_connect(vconn) == expected_error);
fpv_create(type, &fpv);
assert(!vconn_open(fpv.vconn_name, OFP_VERSION, &vconn));
+ vconn_run(vconn);
fd = fpv_accept(&fpv);
fpv_destroy(&fpv);
assert(!set_nonblocking(fd));
assert(errno == EAGAIN);
}
+ vconn_run(vconn);
assert(vconn_connect(vconn) == EAGAIN);
+ vconn_run_wait(vconn);
vconn_connect_wait(vconn);
poll_fd_wait(fd, POLLIN);
poll_block();
fpv_create(type, &fpv);
assert(!vconn_open(fpv.vconn_name, OFP_VERSION, &vconn));
+ vconn_run(vconn);
fd = fpv_accept(&fpv);
fpv_destroy(&fpv);
}
}
+ vconn_run(vconn);
if (!connected) {
int error = vconn_connect(vconn);
if (error == expect_connect_error) {
break;
}
+ vconn_run_wait(vconn);
if (!connected) {
vconn_connect_wait(vconn);
}