/*
- * Copyright (c) 2009 Nicira Networks.
+ * Copyright (c) 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.
return;
}
+ stream_run(rpc->stream);
while (!queue_is_empty(&rpc->output)) {
struct ofpbuf *buf = rpc->output.head;
int retval;
void
jsonrpc_wait(struct jsonrpc *rpc)
{
- if (!rpc->status && !queue_is_empty(&rpc->output)) {
- stream_send_wait(rpc->stream);
+ if (!rpc->status) {
+ stream_run_wait(rpc->stream);
+ if (!queue_is_empty(&rpc->output)) {
+ stream_send_wait(rpc->stream);
+ }
}
}
jsonrpc_session_disconnect(s);
}
} else if (s->stream) {
- int error = stream_connect(s->stream);
+ int error;
+
+ stream_run(s->stream);
+ error = stream_connect(s->stream);
if (!error) {
reconnect_connected(s->reconnect, time_msec());
s->rpc = jsonrpc_open(s->stream);
if (s->rpc) {
jsonrpc_wait(s->rpc);
} else if (s->stream) {
+ stream_run_wait(s->stream);
stream_connect_wait(s->stream);
}
reconnect_wait(s->reconnect, time_msec());
fd_connect, /* connect */
fd_recv, /* recv */
fd_send, /* send */
+ NULL, /* run */
+ NULL, /* run_wait */
fd_wait, /* wait */
};
\f
* accepted for transmission, it should return -EAGAIN immediately. */
ssize_t (*send)(struct stream *stream, const void *buffer, size_t n);
+ /* Allows 'stream' to perform maintenance activities, such as flushing
+ * output buffers.
+ *
+ * May be null if 'stream' doesn't have anything to do here. */
+ void (*run)(struct stream *stream);
+
+ /* Arranges for the poll loop to wake up when 'stream' needs to perform
+ * maintenance activities.
+ *
+ * May be null if 'stream' doesn't have anything to do here. */
+ void (*run_wait)(struct stream *stream);
+
/* Arranges for the poll loop to wake up when 'stream' is ready to take an
* action of the given 'type'. */
void (*wait)(struct stream *stream, enum stream_wait_type type);
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 stream_class *class = stream_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);
error = stream_open(name, &stream);
while (error == EAGAIN) {
+ stream_run(stream);
+ stream_run_wait(stream);
stream_connect_wait(stream);
poll_block();
error = stream_connect(stream);
: (stream->class->send)(stream, buffer, n));
}
+/* Allows 'stream' to perform maintenance activities, such as flushing
+ * output buffers. */
+void
+stream_run(struct stream *stream)
+{
+ if (stream->class->run) {
+ (stream->class->run)(stream);
+ }
+}
+
+/* Arranges for the poll loop to wake up when 'stream' needs to perform
+ * maintenance activities. */
+void
+stream_run_wait(struct stream *stream)
+{
+ if (stream->class->run_wait) {
+ (stream->class->run_wait)(stream);
+ }
+}
+
+/* Arranges for the poll loop to wake up when 'stream' is ready to take an
+ * action of the given 'type'. */
void
stream_wait(struct stream *stream, enum stream_wait_type wait)
{
int stream_recv(struct stream *, void *buffer, size_t n);
int stream_send(struct stream *, const void *buffer, size_t n);
+void stream_run(struct stream *);
+void stream_run_wait(struct stream *);
+
enum stream_wait_type {
STREAM_CONNECT,
STREAM_RECV,