TEST(hub_connection_tests, connection_id_start_stop_start_reconnect) { auto hub_conn = std::make_shared<signalr::hub_connection>(url); auto weak_hub_conn = std::weak_ptr<signalr::hub_connection>(hub_conn); auto reconnecting_event = std::make_shared<signalr::event>(); auto reconnected_event = std::make_shared<signalr::event>(); utility::string_t connection_id; hub_conn->set_reconnecting([weak_hub_conn, reconnecting_event, &connection_id]() { auto conn = weak_hub_conn.lock(); if (conn) { ASSERT_EQ(conn->get_connection_id(), connection_id); } reconnecting_event->set(); }); hub_conn->set_reconnected([weak_hub_conn, reconnected_event, &connection_id]() { auto conn = weak_hub_conn.lock(); if (conn) { ASSERT_EQ(conn->get_connection_id(), connection_id); } reconnected_event->set(); }); ASSERT_EQ(U(""), hub_conn->get_connection_id()); hub_conn->start().get(); connection_id = hub_conn->get_connection_id(); ASSERT_NE(connection_id, U("")); hub_conn->stop().get(); ASSERT_EQ(hub_conn->get_connection_id(), connection_id); hub_conn->start().get(); ASSERT_NE(hub_conn->get_connection_id(), U("")); ASSERT_NE(hub_conn->get_connection_id(), connection_id); connection_id = hub_conn->get_connection_id(); try { hub_conn->send(U("forceReconnect")).get(); } catch (...) { } ASSERT_FALSE(reconnecting_event->wait(2000)); ASSERT_FALSE(reconnected_event->wait(2000)); }
static void device_state_changed (NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason, gpointer user_data) { NMPolicy *policy = (NMPolicy *) user_data; NMConnection *connection = get_device_connection (device); switch (new_state) { case NM_DEVICE_STATE_FAILED: /* Mark the connection invalid if it failed during activation so that * it doesn't get automatically chosen over and over and over again. */ if (connection && IS_ACTIVATING_STATE (old_state)) { g_object_set_data (G_OBJECT (connection), INVALID_TAG, GUINT_TO_POINTER (TRUE)); nm_log_info (LOGD_DEVICE, "Marking connection '%s' invalid.", get_connection_id (connection)); nm_connection_clear_secrets (connection); } schedule_activate_check (policy, device, 3); break; case NM_DEVICE_STATE_ACTIVATED: if (connection) { /* Clear the invalid tag on the connection */ g_object_set_data (G_OBJECT (connection), INVALID_TAG, NULL); /* And clear secrets so they will always be requested from the * settings service when the next connection is made. */ nm_connection_clear_secrets (connection); } update_routing_and_dns (policy, FALSE); break; case NM_DEVICE_STATE_UNMANAGED: case NM_DEVICE_STATE_UNAVAILABLE: case NM_DEVICE_STATE_DISCONNECTED: update_routing_and_dns (policy, FALSE); schedule_activate_check (policy, device, 0); break; default: break; } }
static bool psccclient_selector_callback_event(int fd, void *data_p) { psccclient_t *psccclient_p = (psccclient_t *)data_p; mpl_msg_event_t *event_p = NULL; exe_request_record_t *record_p = NULL; int conn_id = 0; bool in_iadb = false; exe_request_t request; bool event_processed = false; bool network_initiated = false; mpl_param_element_t *param_elem_p = NULL; int res; bool sterc_event = false; ATC_LOG_D("fd = %d, data_p = %p", fd, data_p); if (NULL == psccclient_p) { ATC_LOG_E("psccclient_p is NULL!"); goto exit; } if (psccclient_p->pscc_fd_event == fd) { event_p = mpl_req_msg_alloc(PSCC_PARAM_SET_ID); } else if (psccclient_p->sterc_fd_event == fd) { event_p = mpl_req_msg_alloc(STERC_PARAM_SET_ID); sterc_event = true; } else { ATC_LOG_E("invalid fd_request"); goto exit; } if (NULL == event_p) { ATC_LOG_E("mpl_event_msg_alloc failed!"); goto exit; } res = psccclient_receive_event(psccclient_p, event_p, sterc_event); if (res < 0) { ATC_LOG_E("receive_event failed!"); goto exit; } else if (res == 0) { /* Zero is returned if peer has closed the socket */ goto disconnect; } ATC_LOG_I("received event %d", event_p->id); if (PSCC_CT_PRESENT((pscc_msg_t *) event_p)) { /* The event included a client tag. * Concerns attach and detach. */ int client_tag = (int)PSCC_GET_CT((pscc_msg_t *) event_p); record_p = request_record_get_record_from_client_tag((int)PSCC_GET_CT((pscc_msg_t *) event_p)); ATC_LOG_I("Client Tag Present"); if (NULL == record_p) { ATC_LOG_E("could not find request record"); goto exit; } } else if (PSCC_CONNID_PRESENT((pscc_msg_t *) event_p)) { /* The event included a conn id. * Get the corresponding request from iadb. */ ATC_LOG_I("CONNID Present"); conn_id = get_connection_id(event_p); in_iadb = psccclient_iadb_get_at_ct_on_conn_id(conn_id, (int *)(&record_p)); if(in_iadb && (event_p->id == pscc_event_modified) && (NULL != record_p) && (EXE_CGCMOD != record_p->request_id)) { ATC_LOG_I("pscc_event_modified recvd and record_p->request_id = %d",record_p->request_id); network_initiated = true; } /* Even if there is a pscc call waiting for a return for a particular connid, there is a chance * that the event might be unsolicited. Currently only occurs for (network initiated) * disconnected events. In that case, handle it as unsolicited. */ if (in_iadb && event_p->id == pscc_event_disconnected) { param_elem_p = mpl_param_list_find(pscc_paramid_reason, event_p->param_list_p); if (param_elem_p != NULL && (pscc_reason_pdp_context_nw_deactivated == *(int *)(param_elem_p->value_p))) { ATC_LOG_I("nw initiated pscc_event_disconnected. Treat as unsolicited."); network_initiated = true; } else if (param_elem_p != NULL && (pscc_reason_pdp_context_nw_deactivated_reset == *(int *)(param_elem_p->value_p))) { ATC_LOG_I("nw initiated pscc_event_disconnected with reset indication. Treat as unsolicited."); network_initiated = true; } } if (NULL == record_p || !in_iadb || network_initiated) { #ifdef EXE_USE_ATC_CUSTOMER_EXTENSIONS /* Note: The extended event handler needs to return false if processing * is not complete and further processing is required by the generic * handler. Return true to prevent the generic handler from ever seeing * the event. */ event_processed = exe_extended_pscc_event_handler(psccclient_p, event_p, conn_id); #else event_processed = false; #endif ATC_LOG_I("Received unsolicited event not related to an outstanding request"); /* Unsolicited event not related to an outstanding request. */ if (!event_processed) { event_processed = exe_pscc_event_handler(psccclient_p, event_p, conn_id); if (!event_processed) { ATC_LOG_E("Unknown/Unhandled event! (%d)", event_p->id); } } goto exit; } } else if (STERC_HANDLE_PRESENT((pscc_msg_t *) event_p)) { int sterc_handle = (int)STERC_GET_HANDLE((pscc_msg_t *) event_p); in_iadb = psccclient_iadb_get_at_ct_on_sterc_handle(sterc_handle, (int *)(&record_p)); ATC_LOG_I("Sterc Handle Present"); if (in_iadb && event_p->id == sterc_event_disconnected) { param_elem_p = mpl_param_list_find(sterc_paramid_reason, event_p->param_list_p); if (param_elem_p != NULL) { ATC_LOG_I("Received sterc disconnect reason: (%d)", *(int *)(param_elem_p->value_p)); } } if (NULL == record_p || !in_iadb) { ATC_LOG_I("Received unsolicited event not related to an outstanding request with Sterc Handle Present"); /* Unsolicited event not related to an outstanding request. */ event_processed = exe_pscc_event_handler(psccclient_p, event_p, sterc_handle); if (!event_processed) { ATC_LOG_E("Received unknown sterc event! (%d)", event_p->id); } goto exit; } } else { /* No client tag and no connection id. */ ATC_LOG_E("No CT and no CONNID"); goto exit; } ATC_LOG_I("Setting event to record"); if (!psccclient_set_pscc_event_p(record_p, event_p)) { ATC_LOG_E("failed to set event_p to record!"); goto exit; } request = request_record_get_request(record_p); if (EXE_SUCCESS != request(record_p)) { ATC_LOG_E("request returned unsuccessfully, failed!"); } exit: mpl_msg_free((mpl_msg_t *)event_p); return true; /* Returning false will remove the fd from the selector. */ disconnect: ATC_LOG_E("********************************************************"); ATC_LOG_E("***** at_core lost contact with pscc daemon *****"); ATC_LOG_E("********************************************************"); mpl_msg_free((mpl_msg_t *)event_p); /* Do nothing. Let the receive socket callback clean-up. */ return false; /* Returning false will remove the fd from the selector. */ }
connection_range fc_rnn::get_connections( layer_filter const& src_lfilter, layer_filter const& dst_lfilter, neuron_filter const& src_nfilter, neuron_filter const& dst_nfilter ) const { connection_iterator::data_array_t data; auto const src_layers = std::array < LayerType, 2 > { { LayerType::Input, LayerType::Hidden } }; auto const dst_layers = std::map< LayerType, std::array < LayerType, 2 > >{ { LayerType::Input, { { LayerType::Hidden, LayerType::Output } } }, { LayerType::Hidden, { { LayerType::Hidden, LayerType::Output } } } }; // Iterate over possible source layers for(auto ly_src : src_layers) { layer_data ld_src{ ly_src }; // Skip if don't pass layer filters if(!src_lfilter.test(ld_src)) { continue; } for(auto ly_dst : dst_layers.at(ly_src)) { layer_data ld_dst{ ly_dst }; // Skip if don't pass layer filters if(!dst_lfilter.test(ld_dst)) { continue; } // Now iterate over neurons in src layer auto const src_start = layer_offset(ly_src); auto const src_end = src_start + layer_count(ly_src); for(auto src_id = src_start; src_id < src_end; ++src_id) { // And test against src neuron filter auto src_nd = as_neuron_data(src_id); if(!src_nfilter.test(src_nd)) { continue; } // Neuron passed source filter, so iterate over dst neurons // TODO: should just test each neuron against src/dest filters once at most!! auto const dst_start = layer_offset(ly_dst); auto const dst_end = dst_start + layer_count(ly_dst); for(auto dst_id = dst_start; dst_id < dst_end; ++dst_id) { auto dst_nd = as_neuron_data(dst_id); if(dst_nfilter.test(dst_nd)) { auto const id = get_connection_id(src_id, dst_id); data.emplace_back(as_connection_data(id)); } } } } } return connection_range( connection_iterator(std::move(data)), connection_iterator(), data.size() ); }