/* Connects to a fake_pvconn with vconn_open(), accepts that connection and * closes it immediately, and verifies that vconn_connect() reports * 'expected_error'. */ static void test_accept_then_close(struct ovs_cmdl_context *ctx) { const char *type = ctx->argv[1]; struct fake_pvconn fpv; struct vconn *vconn; int error; fpv_create(type, &fpv); CHECK_ERRNO(vconn_open(fpv.vconn_name, 0, DSCP_DEFAULT, &vconn), 0); vconn_run(vconn); stream_close(fpv_accept(&fpv)); fpv_close(&fpv); error = vconn_connect_block(vconn); if (!strcmp(type, "tcp") || !strcmp(type, "unix")) { if (error != ECONNRESET && error != EPIPE #ifdef _WIN32 && error != WSAECONNRESET #endif ) { ovs_fatal(0, "unexpected vconn_connect() return value %d (%s)", error, ovs_strerror(error)); } } else { CHECK_ERRNO(error, EPROTO); } vconn_close(vconn); fpv_destroy(&fpv); }
static void fpv_destroy(struct fake_pvconn *fpv) { fpv_close(fpv); free(fpv->pvconn_name); free(fpv->vconn_name); }
/* Connects to a fake_pvconn with vconn_open(), then closes the listener and * verifies that vconn_connect() reports 'expected_error'. */ static void test_refuse_connection(int argc OVS_UNUSED, char *argv[]) { const char *type = argv[1]; int expected_error; 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, OFP_VERSION, &vconn), 0); fpv_close(&fpv); vconn_run(vconn); CHECK_ERRNO(vconn_connect(vconn), expected_error); vconn_close(vconn); fpv_destroy(&fpv); }
/* Connects to a fake_pvconn with vconn_open(), then closes the listener and * verifies that vconn_connect() reports 'expected_error'. */ static void test_refuse_connection(struct ovs_cmdl_context *ctx) { const char *type = ctx->argv[1]; struct fake_pvconn fpv; struct vconn *vconn; int error; fpv_create(type, &fpv); CHECK_ERRNO(vconn_open(fpv.vconn_name, 0, DSCP_DEFAULT, &vconn), 0); fpv_close(&fpv); vconn_run(vconn); error = vconn_connect_block(vconn); if (!strcmp(type, "tcp")) { if (error != ECONNRESET && error != EPIPE #ifdef _WIN32 && error != WSAECONNRESET #endif ) { ovs_fatal(0, "unexpected vconn_connect() return value %d (%s)", error, ovs_strerror(error)); } } else if (!strcmp(type, "unix")) { #ifndef _WIN32 CHECK_ERRNO(error, EPIPE); #else CHECK_ERRNO(error, WSAECONNRESET); #endif } else if (!strcmp(type, "ssl")) { if (error != EPROTO && error != ECONNRESET) { ovs_fatal(0, "unexpected vconn_connect() return value %d (%s)", error, ovs_strerror(error)); } } else { ovs_fatal(0, "invalid connection type %s", type); } vconn_close(vconn); fpv_destroy(&fpv); }