/// Sends an acknowledgement as defined in XEP-0198. void QXmppStream::sendAcknowledgement() { if (!d->streamManagementEnabled) return; // prepare packet QByteArray data; QXmlStreamWriter xmlStream(&data); QXmppStreamManagementAck ack(d->lastIncomingSequenceNumber); ack.toXml(&xmlStream); // send packet sendData(data); }
void ICQTransfer::process() { unsigned int /*i, */startTime; hTimer = NULL; if (current >= count) return; startTime = GetTickCount(); while (fileProgress < fileSize && GetTickCount() < startTime+100) sendPacket0x06(); ack(ACKRESULT_DATA); if (fileProgress < fileSize) hTimer = SetTimer(NULL, 0, 1, (TIMERPROC)transferTimerProc); else if (current < count-1) sendPacket0x02(); }
void cwd(const char *path) { if (chdir(path) < 0) perror_reply(550, path); else { show_chdir_messages(250); ack("CWD"); if (getcwd(cached_path, MAXPATHLEN) == NULL) { discover_path(cached_path, path); } } }
void QSocketSession::handshake(bool opposite) { if (MESSAGES) qDebug("Handshaking... (isOpen()=%d)", isOpen()); ack(); if (!waitForAck(1000) || !isOpen()) { qWarning("*** ERROR: Handshake failed: Didn't receive ack. Closing link."); close(); return; } if (MESSAGES) qDebug("Got ack!"); theIsMaster = opposite; findByteOrder(); }
long ack(long n) { if (acks[n].next != 0) return acks[n].next; if (n % 2 == 0) { acks[n].next = n / 2; } else { acks[n].next = 3 * n + 1; } ack(acks[n].next); acks[n].length = acks[acks[n].next].length + 1; return acks[n].next; }
void ICQTransfer::resume(int action, const char *newName) { switch (action) { case FILERESUME_OVERWRITE: T("[ ] overwrite existing file\n"); fileProgress = 0; break; case FILERESUME_RESUME: T("[ ] file resume\n"); break; case FILERESUME_RENAME: T("[ ] rename file\n"); delete [] fileName; fileName = new char[mir_strlen(newName) + 1]; mir_strcpy(fileName, newName); files[current] = fileName; openFile(); fileProgress = 0; break; case FILERESUME_SKIP: T("[ ] skip file\n"); fileProgress = fileSize; break; } totalProgress += fileProgress; sendPacket0x03(); ack(ACKRESULT_NEXTFILE); if (fileProgress) ack(ACKRESULT_DATA); }
void Vehicle::SendFarsightPacket(Player * player, bool enabled) { if (enabled) { player->SetFarsightTarget(GetGUID()); WorldPacket ack(0x49D, 0); if (player->GetSession() != NULL) player->GetSession()->SendPacket(&ack); } else { player->SetFarsightTarget(0); player->SetCharmedUnitGUID( 0 ); } }
int fping_monitor(int sfd) { int err = 0; if (sfd < 0) return sfd; /* try to ping existing socket */ if (ack(sfd, 20) != 0) err = -1; /* check the reply */ if (!err && wait_reply(sfd, 20) != 0) err = -1; return err; }
int main(int argc, char *argv[]) { if(argc!=3){ printf("%s%s",argv[0],": m n\n\twhere n and m are integers\n"); return 0; } int m = atoi(argv[1]); int n = atoi(argv[2]); printf("ack(%d,%d): ",m,n); clock_t start=clock(); int back=ack(m,n); clock_t end=clock(); double passed = end - start; passed /= ((double)CLOCKS_PER_SEC); printf("%d (%e seconds)\n", back, passed); return(0); }
/** * In phase2 it advances the internal counter to move to the next tick, * and when all ticks for this TickManager are done, to move to the next * TickManager. */ void Clock::reinitPhase2( ProcInfo* info ) { info->currTime = 0.0; if ( Shell::isSingleThreaded() || info->threadIndexInGroup == 1 ) { if ( tickPtr_.size() == 0 || tickPtr_[ currTickPtr_ ].mgr()->reinitPhase2( info ) ) { ++currTickPtr_; if ( currTickPtr_ >= tickPtr_.size() ) { Id clockId( 1 ); ack()->send( clockId.eref(), info->threadIndexInGroup, info->nodeIndexInGroup, OkStatus ); procState_ = TurnOffReinit; ++countReinit2_; } } } }
// In phase 2 we need to do the updates to the Clock object, especially // sorting the TickPtrs. This also is when we find out if the simulation // is finished. // Note that this function happens when lots of other threads are doing // things. So it cannot touch any fields which might affect other threads. void Clock::advancePhase2( ProcInfo *p ) { if ( Shell::isSingleThreaded() || p->threadIndexInGroup == 1 ) { tickPtr_[0].mgr()->advancePhase2( p ); if ( tickPtr_.size() > 1 ) sort( tickPtr_.begin(), tickPtr_.end() ); currentTime_ = tickPtr_[0].mgr()->getNextTime() - tickPtr_[0].mgr()->getDt(); if ( currentTime_ > endTime_ ) { Id clockId( 1 ); procState_ = StopOnly; finished()->send( clockId.eref(), p->threadIndexInGroup ); ack()->send( clockId.eref(), p->threadIndexInGroup, p->nodeIndexInGroup, OkStatus ); } ++countAdvance2_; } }
bool Vantage::Connect() { int connectrc=0; char errorMsg[MAXRBUF]; DEBUGF(INDI::Logger::DBG_DEBUG, "Vantage connecting to %s", PortT[0].text); if ( (connectrc = tty_connect(PortT[0].text, atoi(IUFindOnSwitch(&BaudRateSP)->name), 8, 0, 1, &PortFD)) != TTY_OK) { tty_error_msg(connectrc, errorMsg, MAXRBUF); DEBUGF(INDI::Logger::DBG_ERROR,"Failed to connect to port %s @ baud %d. Error: %s", PortT[0].text,atoi(IUFindOnSwitch(&BaudRateSP)->name), errorMsg); return false; } DEBUGF(INDI::Logger::DBG_DEBUG, "Port FD %d",PortFD); return ack(); }
/* For the following functions it should not be nessecary to reimplement them as the contain the basic * message handling, timeouts and state transitions. */ void do_on_ack() { if ( _state != WAIT_FOR_ACK ) { _state = ERROR; std::stringstream ss; ss << "Unexpected ACK received while in state " << stateNames[_state]; error(ss.str()); return; } _timer.cancel(); _state = WAIT_FOR_START; ack(); _timer.expires_from_now(boost::posix_time::seconds(1500)); _timer.async_wait(boost::bind(&fullcircle::Client::do_on_timeout, this, _1)); }
uchar read_data(uchar add) { uchar b; init(); start(); write(0xa0); ack; write(add); ack(); start(); write(0xa1); ack; read(); b=read(); noack; stop; return b; }
void rel_recvpkt (rel_t *r, packet_t *pkt, size_t n) { if (ntohs(pkt->len) < 12 || ntohs(pkt->len) > 1016) { fprintf(stderr, "Wrong length pkt\n"); return; } if ( (((int) n) > ntohs(pkt->len)) || (((int) n) < ntohs(pkt->len)) ) { fprintf(stderr, "size mismatch\n"); return; } if (ntohl(pkt->ackno) < 1 || ntohl(pkt->ackno) > r->seqOut) { fprintf(stderr, "Wrong ackno\n"); return; } if ((int) n < 12 || (int) n > 1016) { fprintf(stderr, "Wrong length input\n"); return; } uint16_t oldCheck = pkt->cksum; int len = ntohs(pkt->len); numBitsReceivedBetweenTimers = numBitsReceivedBetweenTimers + len; pkt->cksum = 0; pkt->cksum = 0; pkt->cksum = 0; pkt->cksum = 0; uint16_t realCheck = cksum(pkt, len); if (realCheck != oldCheck) { fprintf(stderr, "wrong checksum for packet: length %d, ackno %d, seqno %d\n", len, ntohl(pkt->ackno), ntohl(pkt->seqno)); return; } if(len == 12){ processAck2 (r, pkt); } else if(len >= 16 && len <= 1016 && ntohl(pkt->seqno) >= r->seqIn && sizeOfQueue(r->receiverBuff) < r->recvWindows){ processData(r, pkt, len); } else{ ack(r, r->seqIn); } return; }
void reader() { while(1){ ManagedString incoming = uBit.serial.readUntil(";") + ";"; ManagedString id = incoming.substring(0,3); if(id == "set"){ uBit.serial.send("ack;"); set(incoming); } else if(id == "ack"){ uBit.serial.send("ack;"); ack(incoming); } else if(id == "stp"){ uBit.serial.send("ack;"); stp(); } } }
/** * The client is requesting an offer. * * @returns true. * * @param pDhcpMsg The message. * @param cb The message size. */ bool NetworkManager::handleDhcpReqRequest(PCRTNETBOOTP pDhcpMsg, size_t cb) { ConfigurationManager *confManager = ConfigurationManager::getConfigurationManager(); /* 1. find client */ Client client = confManager->getClientByDhcpPacket(pDhcpMsg, cb); /* 2. find bound lease */ Lease l = client.lease(); if (l != Lease::NullLease) { if (l.isExpired()) { /* send client to INIT state */ Client c(client); nak(client, pDhcpMsg->bp_xid); confManager->expireLease4Client(c); return true; } else { /* XXX: Validate request */ RawOption opt; RT_ZERO(opt); Client c(client); int rc = confManager->commitLease4Client(c); AssertRCReturn(rc, false); rc = ConfigurationManager::extractRequestList(pDhcpMsg, cb, opt); AssertRCReturn(rc, false); ack(client, pDhcpMsg->bp_xid, opt.au8RawOpt, opt.cbRawOpt); } } else { nak(client, pDhcpMsg->bp_xid); } return true; }
static char *ping_monitor_version(char *devname) { int sfd = connect_monitor(devname); struct metadata_update msg; int err = 0; if (sfd < 0) return NULL; if (ack(sfd, 20) != 0) err = -1; if (!err && receive_message(sfd, &msg, 20) != 0) err = -1; close(sfd); if (err || !msg.len || !msg.buf) return NULL; return msg.buf; }
void Client::Disconnect() { std::cout << "===> Disconnecting the client from socket" << std::endl; if (!fIsConnected) return; try { SendMessage(SocketMessage(REMOVE_CLIENT, fClientId), -1); } catch (Exception& e) { e.Dump(); } try { SocketMessage ack(FetchMessage()); if (ack.GetKey()==THIS_CLIENT_DELETED or ack.GetKey()==OTHER_CLIENT_DELETED) { fIsConnected = false; } } catch (Exception& e) { if (e.ErrorNumber()!=11000) // client has been disconnected e.Dump(); else return; } }
void interpret_packet(void) { int size = rx(); // ignore. protocol is self-terminating. (void)size; int command = rx(); switch(command & 0x0F) { default: case 0: ack(); break; case 1: npush(); break; case 2: npop(); break; case 3: jsr(); break; case 4: lda(); break; case 5: ldf(); break; case 7: intr(); break; case 8: nafetch(); break; case 9: nffetch(); break; case 10: nastore(); break; case 11: nfstore(); break; } infof("\n"); }
void queue::ack(const entry_id id) { auto found = m_wait_ack.find(id.chunk); if (found == m_wait_ack.end()) { LOG_ERROR("ack for chunk %d (pos %d) which is not in waiting list", id.chunk, id.pos); return; } auto chunk = found->second; chunk->ack(id.pos); if (chunk->meta().acked() == chunk->meta().low_mark()) { // Real end of the chunk's lifespan, all popped entries are acked m_wait_ack.erase(found); chunk->add(&m_statistics.chunks_popped); // Chunk would be uncomplete here only if its the only chunk in the queue // (filled partially and serving both as a push and a pop/ack target) if (chunk->meta().complete()) { chunk->remove(); LOG_INFO("chunk %d complete", id.chunk); } // Set chunk_id_ack to the lowest active chunk //NOTE: its important to have m_chunks and m_wait_ack both sorted m_state.chunk_id_ack = m_state.chunk_id_push; if (!m_chunks.empty()) { m_state.chunk_id_ack = std::min(m_state.chunk_id_ack, m_chunks.begin()->first); } if (!m_wait_ack.empty()) { m_state.chunk_id_ack = std::min(m_state.chunk_id_ack, m_wait_ack.begin()->first); } write_state(); } ++m_statistics.ack_count; }
void TradeHandler::ValidateAndAcknowledgeTrade( AcceptCommit accept_commit) { uint160 accept_commit_hash = accept_commit.GetHash160(); uint160 commit_hash = accept_commit.order_commit_hash; OrderCommit commit = msgdata[commit_hash]["commit"]; AcceptOrder accept; accept = msgdata[commit.accept_order_hash]["accept_order"]; Order order = msgdata[accept.order_hash]["order"]; Currency currency = flexnode.currencies[order.currency]; vch_t payer_data, payee_data; if (order.side == ASK) { payer_data = order.auxiliary_data; payee_data = accept.auxiliary_data; } else { payee_data = order.auxiliary_data; payer_data = accept.auxiliary_data; } if (!currency.ValidateProposedFiatTransaction(accept_commit_hash, payer_data, payee_data, order.size)) { log_ << "Could not validate fiat transaction!\n"; return; } tradedata[accept_commit_hash]["ttp_validated"] = true; ThirdPartyTransactionAcknowledgement ack(accept_commit_hash); ack.Sign(); uint160 ack_hash = ack.GetHash160(); tradedata[accept_commit_hash]["acknowledgement"] = ack_hash; BroadcastMessage(ack); }
/* * 4.3.5 DHCPINFORM message * * The server responds to a DHCPINFORM message by sending a DHCPACK * message directly to the address given in the 'ciaddr' field of the * DHCPINFORM message. The server MUST NOT send a lease expiration time * to the client and SHOULD NOT fill in 'yiaddr'. The server includes * other parameters in the DHCPACK message as defined in section 4.3.1. */ DhcpServerMessage *DHCPD::doInform(DhcpClientMessage &req) { if (req.ciaddr().u == 0) return NULL; const OptParameterRequest params(req); if (!params.present()) return NULL; optmap_t info(m_pConfig->getOptions(params, req.clientId())); if (info.empty()) return NULL; std::unique_ptr<DhcpServerMessage> ack ( createMessage(RTNET_DHCP_MT_ACK, req) ); ack->addOptions(info); ack->maybeUnicast(req); return ack.release(); }
int main() { long i, g_number; unsigned long g_sequence; acks[1].next = 1; g_sequence = 0; for (i = 2; i < 1000000; i++) { ack(i); if (acks[i].length > g_sequence) { g_sequence = acks[i].length; g_number = i; } else if (acks[i].length == g_sequence) { if (i < g_number) g_number = i; } } std::cout << g_number << std::endl; return 0; }
DhcpServerMessage *DHCPD::doRequest(DhcpClientMessage &req) { OptRequestedAddress reqAddr(req); if (req.ciaddr().u != 0 && reqAddr.present() && reqAddr.value().u != req.ciaddr().u) { std::unique_ptr<DhcpServerMessage> nak ( createMessage(RTNET_DHCP_MT_NAC, req) ); nak->addOption(OptMessage("Requested address does not match ciaddr")); return nak.release(); } Binding *b = m_db.allocateBinding(req); if (b == NULL) { return createMessage(RTNET_DHCP_MT_NAC, req); } std::unique_ptr<DhcpServerMessage> ack ( createMessage(RTNET_DHCP_MT_ACK, req) ); b->setState(Binding::ACKED); saveLeases(); ack->setYiaddr(b->addr()); ack->addOption(OptLeaseTime(b->leaseTime())); OptParameterRequest optlist(req); ack->addOptions(m_pConfig->getOptions(optlist, req.clientId())); ack->addOption(OptMessage("Ok, ok, here it is")); ack->maybeUnicast(req); return ack.release(); }
int InputData(int net) { int resource = 0; if ( getrequestheader(net) < 0 ) /* Get HTTP request */ return -1; output(net); if ( (resource = review()) < 0 ) /* Check whether resource exists and updates the status code */ { output(net); return 1; } printf("Status is: %d\n",status); /*Outputs HTTP response headers */ /* Service the HTTP request */ if ( status == 200 ) { if ( ack(net, resource) ) /* returns the resource */ error("Error returning the resource"); } if ( resource > 0 ) if ( close(resource) < 0 ) { error("Resource could not be closed"); } return 0; }
Stanza JingleStanza::ack(IJingle::CommandRespond ARespond) const { Stanza ack("iq"); ack.setId(id()); ack.setFrom(to()); ack.setTo(from()); if (ARespond==IJingle::Acknowledge) ack.setType("result"); else { ack.setType("error"); QDomElement error=ack.addElement("error"); switch (ARespond) { case IJingle::ServiceUnavailable: error.setAttribute("type", "cancel"); error.appendChild(ack.createElement("service-unavailable", "urn:ietf:params:xml:ns:xmpp-stanzas")); break; case IJingle::Redirect: error.setAttribute("type", "modify"); error.appendChild(ack.createElement("redirect", "urn:ietf:params:xml:ns:xmpp-stanzas")); break; case IJingle::ResourceConstraint: error.setAttribute("type", "wait"); error.appendChild(ack.createElement("resource-constraint", "urn:ietf:params:xml:ns:xmpp-stanzas")); break; case IJingle::BadRequest: error.setAttribute("type", "cancel"); error.appendChild(ack.createElement("bad-request", "urn:ietf:params:xml:ns:xmpp-stanzas")); break; default: break; } } return ack; }
boolean Nextion::updateProgressBar(int x, int y, int maxWidth, int maxHeight, int value, int emptyPictureID, int fullPictureID, int orientation){ int w1 = 0; int h1 = 0; int w2 = 0; int h2 = 0; int offset1 = 0; int offset2 = 0; if(orientation == 0){ // horizontal value = map(value, 0, 100, 0, maxWidth); w1 = value; h1 = maxHeight; w2 = maxWidth - value; h2 = maxHeight; offset1 = x + value; offset2 = y; }else{ // vertical value = map(value, 0, 100, 0, maxHeight); offset2 = y; y = y + maxHeight - value; w1 = maxWidth; h1 = value; w2 = maxWidth; h2 = maxHeight - value; offset1 = x; }//end if String wipe = "picq " + String(x) + "," + String(y) + "," + String(w1) + "," + String(h1) + "," + String(fullPictureID); sendCommand(wipe.c_str()); wipe = "picq " + String(offset1) + "," + String(offset2) + "," + String(w2) + "," + String(h2) + "," + String(emptyPictureID); sendCommand(wipe.c_str()); return ack(); }//end updateProgressBar
void processData (rel_t *r, packet_t *pkt, int length){ if ( r->beginTime.tv_sec == 0 && r->beginTime.tv_usec == 0 ) { gettimeofday(&r->beginTime, NULL); } if (ntohl(pkt->seqno) >= 1) { packetQueue* newPkt = new_packet(); memcpy(newPkt->packet, pkt, length); if (ntohl(pkt->seqno) == r->seqIn) { r->seqIn = r->seqIn + 1; } ack(r, r->seqIn); processAck(r, (struct ack_packet*) pkt); orderlyInsert(&(r->receiverBuff), newPkt); if (length == 16) { fprintf(stderr, "GET EOF\n"); r->pairEOFed = 1; } rel_output(r); } else{ fprintf(stderr, " wrong seqno %d \n", ntohl(pkt->seqno)); return; } }
void Vehicle::EjectPassengerFromSeat( uint32 seatid ){ if( !seats[ seatid ]->Usable() ) return; if( !seats[ seatid ]->HasPassenger() ) return; Unit *passenger = owner->GetMapMgrUnit( seats[ seatid ]->GetPassengerGUID() ); if( passenger == NULL ) return; // set moveflags // set movement info // remove charmed by if passenger was controller if( seats[ seatid ]->Controller() ){ passenger->SetCharmedUnitGUID( 0 ); owner->SetCharmedByGUID( 0 ); if( passenger->IsPlayer() ){ owner->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED_CREATURE | UNIT_FLAG_PVP_ATTACKABLE ); WorldPacket ack( SMSG_CLIENT_CONTROL_UPDATE, 16 ); ack << owner->GetNewGUID(); ack << uint8( 0 ); passenger->SendPacket(&ack); // send null spells if needed static_cast< Player* >( passenger )->SendEmptyPetSpellList(); } } if( passenger->IsPlayer() ) static_cast< Player* >( passenger )->SetFarsightTarget( 0 ); // if we are on a flying vehicle, add a parachute! if( owner->HasAuraWithName( SPELL_AURA_ENABLE_FLIGHT ) || owner->HasAuraWithName( SPELL_AURA_ENABLE_FLIGHT2 ) ) passenger->CastSpell( passenger, 45472, false ); // re-add spellclick flag if needed // despawn vehicle if it was spawned by spell? LocationVector landposition( owner->GetPosition() ); passenger->SendHopOffVehicle( owner, landposition ); passenger->SetPosition( landposition ); passenger->Unroot(); seats[ seatid ]->RemovePassenger(); passenger->SetCurrentVehicle( NULL ); passenger->RemoveFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_NOT_ATTACKABLE_2 ); passengercount--; freeseats++; if( HasEmptySeat() ){ if( owner->IsPlayer() ) owner->SetFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_PLAYER_VEHICLE ); else owner->SetFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK ); } if( passenger->IsPlayer() ) static_cast< Player* >( passenger )->SpawnActivePet(); if( passenger->IsCreature() ){ Creature *c = static_cast< Creature* >( passenger ); if( c->GetScript() != NULL ){ c->GetScript()->OnExitVehicle(); } } if( owner->IsCreature() ){ Creature *c = static_cast< Creature* >( owner ); if( c->GetScript() != NULL ){ if( passengercount == 0 ) c->GetScript()->OnLastPassengerLeft( passenger ); }else{ // The passenger summoned the vehicle, and we have no script to remove it, so we remove it here if( ( passengercount == 0 ) && ( c->GetSummonedByGUID() == passenger->GetGUID() ) ) c->Despawn( 1 * 1000, 0 ); } } }