static void *timeWaitFunction(void *arg) { Connection *conn = (Connection *) arg; Segment rcvsgm; int rcvd; struct timespec start; start = getTimestamp(); while (getElapsedNow(start) < RUSP_TIMEWTTM) { rcvd = receiveSegment(conn, &rcvsgm); if (rcvd == -1) break; if (rcvd == 0) continue; if ((matchWindow(&(conn->rcvwnd), rcvsgm.hdr.seqn) == 0) && (rcvsgm.hdr.ctrl & RUSP_FIN)) sendSACK(conn, RUSP_NXTSEQN(rcvsgm.hdr.seqn, 1)); } setConnectionState(conn, RUSP_CLOSED); destroyConnection(conn); return NULL; }
void CTeleInfo::onUpdateConfiguration(boost::shared_ptr<yApi::IYPluginApi> api, const shared::CDataContainer& newConfigurationData) { // Stop running timers, if any m_waitForAnswerTimer->stop(); // Stop running reception, if any m_receiveBufferHandler->suspend(); // Configuration was updated std::cout << "Update configuration..." << std::endl; BOOST_ASSERT(!newConfigurationData.empty()); // newConfigurationData shouldn't be empty, or kEventUpdateConfiguration shouldn't be generated // If plugin instance is not running, just update configuration if (!m_port) { // Update configuration m_configuration.initializeWith(newConfigurationData); return; } // Port has changed, destroy and recreate connection destroyConnection(); // Update configuration m_configuration.initializeWith(newConfigurationData); // Create new connection createConnection(api); }
void CTeleInfo::processTeleInfoUnConnectionEvent(boost::shared_ptr<yApi::IYPluginApi> api) { std::cout << "TeleInfo connection was lost" << std::endl; api->setPluginState(yApi::historization::EPluginState::kError, "connectionLost"); destroyConnection(); }
void destroyConnection(Connection * connect, IDnum nodeID) { Connection *previous, *next; //printf("Destroying connection from %li to %li\n", (long) nodeID, (long) getNodeID(connect->destination)); if (connect == NULL) return; previous = connect->previous; next = connect->next; if (previous != NULL) previous->next = next; if (next != NULL) next->previous = previous; if (scaffold[nodeID + nodeCount(graph)] == connect) scaffold[nodeID + nodeCount(graph)] = next; if (connect->twin != NULL) { connect->twin->twin = NULL; destroyConnection(connect->twin, getNodeID(connect->destination)); } deallocateConnection(connect); }
KviIrcContext::~KviIrcContext() { killTimer(m_iHeartbeatTimerId); for(auto & m : m_pMonitorList) { if(m) m->die(); } delete m_pReconnectTimer; if(m_pLinksWindow) m_pLinksWindow->die(); if(m_pListWindow) m_pListWindow->die(); closeAllDeadChannels(); closeAllDeadQueries(); closeAllContextWindows(); destroyConnection(); delete m_pAsynchronousConnectionData; delete m_pSavedAsynchronousConnectionData; }
ChatNetworkingIRC::~ChatNetworkingIRC() { if ( _p_session ) destroyConnection(); if ( _p_config ) delete _p_config; }
inline void remove(int k) { T* p = &(particles[k]); int grdindex = p->gridindex; int cellidx = grdindex/csize; int idx = grdindex%csize; // remove pending connections if (p->mID != -1) destroyConnection(p,-1); if (p->pID != -1) destroyConnection(p,+1); // remove from grid if (idx < occnt[cellidx]-1) { grid[grdindex] = grid[cellidx*csize + occnt[cellidx]-1]; grid[grdindex]->gridindex = grdindex; } occnt[cellidx]--; // remove from container if (k<pcnt-1) { int todel_ID = p->ID; int move_ID = particles[pcnt-1].ID; *p = particles[pcnt-1]; // move very last particle to empty slot particles[pcnt-1].ID = todel_ID; // keep IDs unique grid[p->gridindex] = p; // keep gridindex consistent // permute address table ID_2_address[todel_ID] = &(particles[pcnt-1]); ID_2_address[move_ID] = p; } pcnt--; }
void KviIrcContext::setState(State eState) { if(m_eState == eState) return; m_eState = eState; g_pMainWindow->childContextStateChange(this); emit stateChanged(); if(eState == KviIrcContext::Idle || eState == KviIrcContext::PendingReconnection) destroyConnection(); m_pConsole->updateCaption(); }
static void recenterNode(Node * node, Coordinate oldLength) { IDnum nodeID = getNodeID(node); Connection *connect, *next; Coordinate distance_shift = (getNodeLength(node) - oldLength) / 2; Coordinate min_distance = getNodeLength(node) / 2 - BACKTRACK_CUTOFF; MiniConnection *localConnect; //velvetLog("Recentering node\n"); for (connect = getConnection(node); connect != NULL; connect = next) { next = getNextConnection(connect); incrementConnectionDistance(connect, -distance_shift); if (getConnectionDistance(connect) < min_distance) { //velvetLog("Unrecording %li\n", // -getNodeID(getConnectionDestination(connect))); localConnect = &localScaffold[-getNodeID(getConnectionDestination(connect)) + nodeCount(graph)]; localConnect->frontReference = NULL; unmarkNode(getTwinNode(getConnectionDestination(connect)), localConnect); destroyConnection(connect, nodeID); } else if (getTwinConnection(connect) != NULL) incrementConnectionDistance(getTwinConnection(connect), -distance_shift); } for (connect = getConnection(getTwinNode(node)); connect != NULL; connect = next) { next = getNextConnection(connect); incrementConnectionDistance(connect, distance_shift); if (getTwinConnection(connect) != NULL) incrementConnectionDistance(getTwinConnection(connect), distance_shift); } }
void passiveClose(Connection *conn) { Segment fin; cancelThread(conn->sender); joinThread(conn->sender); fin = createSegment(RUSP_FIN, 0, getWindowNext(&(conn->sndwnd)), 0, NULL); addSgmBuff(&(conn->sndsgmbuff), fin, RUSP_NACK); setConnectionState(conn, RUSP_LSTACK); sendSegment(conn, fin); slideWindowNext(&(conn->sndwnd), 1); DBGPRINT(RUSP_DEBUG, "SND (NXT): base:%u nxt:%u end:%u SNDUSRBUFF:%zu SNDSGMBUFF:%ld", getWindowBase(&(conn->sndwnd)), getWindowNext(&(conn->sndwnd)), getWindowEnd(&(conn->sndwnd)), getStrBuffSize(&(conn->sndusrbuff)), getSgmBuffSize(&(conn->sndsgmbuff))); joinThread(conn->receiver); destroyConnection(conn); }
void CTeleInfo::errorProcess(boost::shared_ptr<yApi::IYPluginApi> api) { api->setPluginState(yApi::historization::EPluginState::kError, "connectionLost"); destroyConnection(); api->getEventHandler().createTimer(kErrorRetryTimer, shared::event::CEventTimer::kOneShot, boost::posix_time::seconds(30)); }
static boolean pushNeighbours(Node * node, Node * oppositeNode, Coordinate distance, boolean force_jumps) { Node *candidate; Coordinate oldLength = getNodeLength(node); MiniConnection *localConnect; NodeList *path, *tmp; if ((path = pathIsClear(node, oppositeNode, distance))) { while (path) { candidate = path->node; tmp = path->next; deallocateNodeList(path); path = tmp; /////////////////////////////////////// // Stepping forward to destination // /////////////////////////////////////// if (getUniqueness(candidate)) { concatenateReadStarts(node, candidate, graph); concatenateLongReads(node, candidate, graph); absorbExtension(node, candidate); // Scaffold changes recenterNode(node, oldLength); recenterLocalScaffold(node, oldLength); absorbExtensionInScaffold(node, candidate); // Read coverage #ifndef SINGLE_COV_CAT Category cat; for (cat = 0; cat < CATEGORIES; cat++) { incrementVirtualCoverage(node, cat, getVirtualCoverage(candidate, cat)); incrementOriginalVirtualCoverage(node, cat, getOriginalVirtualCoverage(candidate, cat)); } #else incrementVirtualCoverage(node, getVirtualCoverage(candidate)); #endif if (getNodeStatus(candidate)) { localConnect = &localScaffold[getNodeID (candidate) + nodeCount (graph)]; if (localConnect->frontReference) { destroyConnection (localConnect-> frontReference, getNodeID(node)); localConnect-> frontReference = NULL; } if (localConnect->backReference) { destroyConnection (localConnect-> backReference, -getNodeID(node)); localConnect-> backReference = NULL; } unmarkNode(candidate, localConnect); } if (getNodeStatus(getTwinNode(candidate))) { localConnect = &localScaffold[-getNodeID (candidate) + nodeCount (graph)]; if (localConnect->frontReference) { destroyConnection (localConnect-> frontReference, getNodeID(node)); localConnect-> frontReference = NULL; } if (localConnect->backReference) { destroyConnection (localConnect-> backReference, -getNodeID(node)); localConnect-> backReference = NULL; } unmarkNode(getTwinNode(candidate), localConnect); } destroyNode(candidate, graph); return true; } else { adjustShortReads(node, candidate); adjustLongReads(node, getNodeLength(candidate)); absorbExtension(node, candidate); } } } if (force_jumps && oppositeNode && abs_ID(getNodeID(oppositeNode)) < abs_ID(getNodeID(node))) { distance -= getNodeLength(node) / 2; distance -= getNodeLength(oppositeNode) / 2; if (distance > 10) { adjustShortReadsByLength(node, distance); adjustLongReads(node, distance); appendGap(node, distance, graph); } else { adjustShortReadsByLength(node, 10); adjustLongReads(node, 10); appendGap(node, 10, graph); } concatenateReadStarts(node, oppositeNode, graph); concatenateLongReads(node, oppositeNode, graph); absorbExtension(node, oppositeNode); // Scaffold changes recenterNode(node, oldLength); recenterLocalScaffold(node, oldLength); absorbExtensionInScaffold(node, oppositeNode); // Read coverage #ifndef SINGLE_COV_CAT Category cat; for (cat = 0; cat < CATEGORIES; cat++) incrementVirtualCoverage(node, cat, getVirtualCoverage(oppositeNode, cat)); #else incrementVirtualCoverage(node, getVirtualCoverage(oppositeNode)); #endif if (getNodeStatus(oppositeNode)) { localConnect = &localScaffold[getNodeID(oppositeNode) + nodeCount(graph)]; if (localConnect->frontReference) { destroyConnection(localConnect-> frontReference, getNodeID(node)); localConnect->frontReference = NULL; } if (localConnect->backReference) { destroyConnection(localConnect-> backReference, -getNodeID(node)); localConnect->backReference = NULL; } unmarkNode(oppositeNode, localConnect); } if (getNodeStatus(getTwinNode(oppositeNode))) { localConnect = &localScaffold[-getNodeID(oppositeNode) + nodeCount(graph)]; if (localConnect->frontReference) { destroyConnection(localConnect-> frontReference, getNodeID(node)); localConnect->frontReference = NULL; } if (localConnect->backReference) { destroyConnection(localConnect-> backReference, -getNodeID(node)); localConnect->backReference = NULL; } unmarkNode(getTwinNode(oppositeNode), localConnect); } destroyNode(oppositeNode, graph); } return false; }
static void absorbExtensionInScaffold(Node * node, Node * source) { IDnum nodeID = getNodeID(node); IDnum sourceID = getNodeID(source); IDnum sourceIndex = sourceID + nodeCount(graph); Node *twinSource = getTwinNode(source); IDnum twinSourceIndex = getNodeID(twinSource) + nodeCount(graph); Connection *connect, *original; Node *destination; IDnum destinationID; Coordinate distance_shift = (getNodeLength(node) - getNodeLength(source)) / 2; Coordinate min_distance = getNodeLength(node) / 2 - BACKTRACK_CUTOFF; MiniConnection *localConnect; Coordinate distance; double variance; IDnum direct_count; IDnum paired_count; while ((connect = getConnection(source))) { destination = getTwinNode(getConnectionDestination(connect)); if (destination == getTwinNode(node)) { localConnect = &localScaffold[twinSourceIndex]; localConnect->frontReference = NULL; unmarkNode(twinSource, localConnect); destroyConnection(connect, sourceID); continue; } if (destination == node) { localConnect = &localScaffold[sourceIndex]; localConnect->backReference = NULL; unmarkNode(source, localConnect); destroyConnection(connect, sourceID); continue; } destinationID = getNodeID(destination); localConnect = &localScaffold[destinationID + nodeCount(graph)]; incrementConnectionDistance(connect, distance_shift); distance = getConnectionDistance(connect); variance = getConnectionVariance(connect); direct_count = getConnectionDirectCount(connect); paired_count = getConnectionPairedCount(connect); if (getNodeStatus(destination)) { readjustMiniConnection(destination, localConnect, distance, min_distance, variance, NULL, NULL); if ((original = localConnect->frontReference)) readjustConnection(original, distance, variance, direct_count, paired_count); else localConnect->frontReference = createNewConnection(nodeID, -destinationID, direct_count, paired_count, distance, variance); } else resetMiniConnection(destination, localConnect, distance, variance, createNewConnection(nodeID, -destinationID, direct_count, paired_count, distance, variance), NULL, true); integrateDerivativeDistances(connect, min_distance, true); destroyConnection(connect, sourceID); } // Loop thru twin's primary scaffold while ((connect = getConnection(getTwinNode(source)))) { destination = getConnectionDestination(connect); if (destination == node) { localConnect = &localScaffold[sourceIndex]; localConnect->frontReference = NULL; unmarkNode(source, localConnect); destroyConnection(connect, -sourceID); continue; } if (destination == getTwinNode(node)) { localConnect = &localScaffold[twinSourceIndex]; localConnect->backReference = NULL; unmarkNode(twinSource, localConnect); destroyConnection(connect, -sourceID); continue; } destinationID = getNodeID(destination); localConnect = &localScaffold[destinationID + nodeCount(graph)]; incrementConnectionDistance(connect, -distance_shift); distance = getConnectionDistance(connect); variance = getConnectionVariance(connect); direct_count = getConnectionDirectCount(connect); paired_count = getConnectionPairedCount(connect); if (distance > min_distance && getNodeStatus(destination) < 0) { readjustMiniConnection(destination, localConnect, -distance, min_distance, variance, NULL, NULL); if ((original = localConnect->backReference)) readjustConnection(original, distance, variance, direct_count, paired_count); } else if (getNodeStatus(destination) < 0) { if ((original = localConnect->backReference)) { destroyConnection(original, -nodeID); localConnect->backReference = NULL; } unmarkNode(destination, localConnect); } else if (getNodeStatus(destination) > 0) { if ((original = localConnect->frontReference)) { destroyConnection(original, nodeID); localConnect->frontReference = NULL; } unmarkNode(destination, localConnect); } else if (distance > min_distance) { resetMiniConnection(destination, localConnect, -distance, variance, NULL, createNewConnection(-nodeID, destinationID, direct_count, paired_count, distance, variance), -1); integrateDerivativeDistances(connect, min_distance, true); } destroyConnection(connect, -sourceID); } }
void handleUpdates() { for (conn* c : connections_to_handle) { c->need_be_handled = false; try { if (c->errorOccurred) { destroyConnection(*c); continue; } if (c->socketRemoteClosed) { // Send all read data to pty if (c->pipeClosed) { destroyConnection(*c); continue; } if (!c->socketCloseHandled) { c->socketCloseHandled = true; // Ignore pty IN group.modifyRegistration(c->pty.getMasterFd(), EPOLLOUT, const_cast<epoll_tag*>(&c->tagPipe)); } if (transferLeft(c->receiveBuffer, c->socket, c->pty)) { destroyConnection(*c); } } else if (c->pipeClosed) { // Send all unsent data if (!c->pipeCloseHandled) { c->pipeCloseHandled = true; // Don't receive HUP again group.removeRegistration(c->pty.getMasterFd()); // Ignore socket IN group.modifyRegistration(c->socket.getFd(), EPOLLOUT | EPOLLRDHUP, const_cast<epoll_tag*>(&c->tagSocket)); } if(transferLeft(c->sendBuffer, c->pty, c->socket)) { destroyConnection(*c); } continue; } else { if (c->socketReadReady) { // Network -> Receive buffer c->socketReadReady = false; transfer(c->socket, c->receiveBuffer); } if (c->pipeReadReady) { // Pipe -> Send buffer c->pipeReadReady = false; transfer(c->pty, c->sendBuffer); } if (c->pipeWriteReady) { // Receive buffer -> Pipe c->pipeWriteReady = false; transfer(c->receiveBuffer, c->pty); } if (c->socketWriteReady) { // Send buffer -> Network c->socketWriteReady = false; transfer(c->sendBuffer, c->socket); } uint32_t ptyEvents = (!c->sendBuffer.isFull() ? EPOLLIN : 0u) | (!c->receiveBuffer.isEmpty() ? EPOLLOUT : 0u); uint32_t socketEvents = (!c->sendBuffer.isEmpty() ? EPOLLOUT : 0u) | (!c->receiveBuffer.isFull() ? EPOLLIN : 0u) | EPOLLRDHUP; group.modifyRegistration(c->socket.getFd(), socketEvents, const_cast<epoll_tag *>(&c->tagSocket)); group.modifyRegistration(c->pty.getMasterFd(), ptyEvents, const_cast<epoll_tag *>(&c->tagPipe)); if (c->socketRemoteClosed || c->pipeClosed) { destroyConnection(*c); continue; } } } catch (const errno_exception& ex) { fprintf(stdout, "Error while handling updates, %s: %s\n", ex.description.data(), strerror(ex.err)); destroyConnection(*c); } } }