Until now, it seems that all vconn users have immediately started reading
messages from the connection. Today, however, I added a new user that
only wants to read packets after the OpenFlow version is negotiated, so
it never called vconn_recv() before that happened. It turns out that if
you do this, the version never gets negotiated at all.
This commit fixes the problem by ensuring that vconn_run() will continue
version negotiation if it isn't done yet.
This changes the error return that I get for Unix sockets in the
test-vconn "accept-then-close" test from EPIPE to ECONNRESET, so this
commit also adjusts that test to accept either error code; both of them
seem reasonable enough to me.
Signed-off-by: Ben Pfaff <blp@nicira.com>
void
vconn_run(struct vconn *vconn)
{
void
vconn_run(struct vconn *vconn)
{
+ if (vconn->state == VCS_CONNECTING ||
+ vconn->state == VCS_SEND_HELLO ||
+ vconn->state == VCS_RECV_HELLO) {
+ vconn_connect(vconn);
+ }
+
if (vconn->class->run) {
(vconn->class->run)(vconn);
}
if (vconn->class->run) {
(vconn->class->run)(vconn);
}
void
vconn_run_wait(struct vconn *vconn)
{
void
vconn_run_wait(struct vconn *vconn)
{
+ if (vconn->state == VCS_CONNECTING ||
+ vconn->state == VCS_SEND_HELLO ||
+ vconn->state == VCS_RECV_HELLO) {
+ vconn_connect_wait(vconn);
+ }
+
if (vconn->class->run_wait) {
(vconn->class->run_wait)(vconn);
}
if (vconn->class->run_wait) {
(vconn->class->run_wait)(vconn);
}
test_accept_then_close(int argc OVS_UNUSED, char *argv[])
{
const char *type = argv[1];
test_accept_then_close(int argc OVS_UNUSED, char *argv[])
{
const char *type = argv[1];
struct fake_pvconn fpv;
struct vconn *vconn;
struct fake_pvconn fpv;
struct vconn *vconn;
-
- expected_error = (!strcmp(type, "unix") ? EPIPE
- : !strcmp(type, "tcp") ? ECONNRESET
- : EPROTO);
fpv_create(type, &fpv);
CHECK_ERRNO(vconn_open(fpv.vconn_name, OFP10_VERSION, &vconn,
fpv_create(type, &fpv);
CHECK_ERRNO(vconn_open(fpv.vconn_name, OFP10_VERSION, &vconn,
vconn_run(vconn);
stream_close(fpv_accept(&fpv));
fpv_close(&fpv);
vconn_run(vconn);
stream_close(fpv_accept(&fpv));
fpv_close(&fpv);
- CHECK_ERRNO(vconn_connect(vconn), expected_error);
+
+ error = vconn_connect_block(vconn);
+ if (!strcmp(type, "tcp") || !strcmp(type, "unix")) {
+ if (error != ECONNRESET && error != EPIPE) {
+ ovs_fatal(0, "unexpected vconn_connect() return value %d (%s)",
+ error, strerror(error));
+ }
+ } else {
+ CHECK_ERRNO(error, EPROTO);
+ }
+
vconn_close(vconn);
fpv_destroy(&fpv);
}
vconn_close(vconn);
fpv_destroy(&fpv);
}