Exemple #1
0
/** Execute the algorithm.
 */
void SendUsage::exec() {
  // generate the default header - this uses a cache variable
  this->generateHeader();

  std::string json = this->generateJson();
  this->setPropertyValue("Json", json);

  // send the report
  if (doSend()) {
    sendReport(json);
  } else {
    g_log.debug("Sending usage reports is disabled\n");
  }
}
Exemple #2
0
void negotiator(void * ptr) {
	int *new = (int*) ptr;
	int newsockfd = *new;
	int panning = 1;
	char fileName[256];
	char buff[256];
	int noOfBytes = 0;
	bzero(fileName, 256);
	linkedList *panList = searchWorker(socketList, newsockfd);
	while ((noOfBytes = Receive(newsockfd, fileName, sizeof(fileName))) > 0) {
		if (strcmp(fileName, "EXIT") == 0) {
			break;
		}

		//fileName[noOfBytes] = 0;
		fprintf(stderr, "\n%s\n", fileName);
		//pthread_mutex_lock(&mutex);
		unsigned int size = getSize(fileName);
		//pthread_mutex_unlock(&mutex);
		sprintf(buff, "%d", size);
		fprintf(stderr, "%d", size);
		if (doSend(panning) == 1) {
			Send(newsockfd, buff, strlen(buff));
			char* s = (char*) malloc(size * sizeof(char) + 1);
			//pthread_mutex_lock(&mutex);
			readFile(s, fileName);
			//pthread_mutex_unlock(&mutex);
			fprintf(stderr, "\n %ld \n", strlen(s));
			int i, j, temp;
			i = 0;
			j = strlen(s) - 1;
			while (i < j) {
				temp = s[i];
				s[i++] = s[j];
				s[j--] = temp;
			}
			Send(newsockfd, s, size);
			free(s);
			panning = panList->data.priority;
		}
		//send the file length as 0
		else{
			sprintf(buff, "%d", 0);
			Send(newsockfd, buff, strlen(buff));
			panning = panList->data.priority;
		}
	}
	Close(newsockfd);
}
void DatagramTransceiver::handleSendTo(const boost::system::error_code &error, size_t)
{
    if (error)
    {
        stop();
        return;
    }

    /** Remove written message from queue */
    MessageToSend* struct_msg = m_write_msgs.front();
    m_write_msgs.pop_front();
    delete struct_msg;

    if (m_write_msgs.empty() == false) doSend();
}
NeoClient::NeoClient(const string addr, const unsigned short port,const SERVICE_TYPE svctype):
    clientSwitch(true)
{
    m_pNEOBaseLib = CNEOBaseLibrary::getInstance("neoclient",".","clientlog",NULL);

    m_pNEOBaseLib->m_pMemPool->Register(m_pNEOBaseLib,"NeoClient::m_pNEOBaseLib");

    setInetAddr(addr,port);

    if(init(svctype))
    {
        doConnection();
        doRecv();
        doSend();
    }
}
Exemple #5
0
int main(int argc, char** argv)
{

  if (argc < 2) {
    printf("Usage: %s <ipv6 addr>\n", argv[0]);
    exit(1);
  }

  onms_socket sock = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
  if (sock == INVALID_SOCKET) {
    perror("main: error creating socket");
    exit(1);
  }

  doSend(sock, argv[1]);
  doReceive(sock);
}
Exemple #6
0
void CANWrap::pollCallback(int status, int events)
{
    if (status == 0)
    {
        if (events & UV_WRITABLE)
        {
            const int err = doSend() < 0 ? errno : 0;

            m_pollEvents &= ~UV_WRITABLE;
            doPoll();
            if (!m_sentCallback.IsEmpty())
            {
                Nan::HandleScope scope;
                Local<Value> argv[1] = {Nan::New(err)};
                m_sentCallback.Call(1, argv);
            }
            else
            {
                callErrorCallback(err);
            }
        }
        else if (events & UV_READABLE)
        {
            const int err = doRecv();
            if (err < 0)
            {
                callErrorCallback(errno);
            }
            else if (!m_messageCallback.IsEmpty())
            {
                Nan::HandleScope scope;
                Local<Value> argv[] = {
                    Nan::New(m_recvBuffer.can_id),
                    Nan::CopyBuffer(reinterpret_cast<char*>(&m_recvBuffer.data),
                                    m_recvBuffer.can_dlc)
                        .ToLocalChecked()};
                m_messageCallback.Call(2, argv);
            }
        }
    }
    else
    {
        callErrorCallback(status);
    }
}
Exemple #7
0
void ChatDlg::initActions()
{
	act_send_ = new QAction(this);
	addAction(act_send_);
	connect(act_send_, SIGNAL(activated()), SLOT(doSend()));

	act_close_ = new QAction(this);
	addAction(act_close_);
	connect(act_close_, SIGNAL(activated()), SLOT(close()));

	act_scrollup_ = new QAction(this);
	addAction(act_scrollup_);
	connect(act_scrollup_, SIGNAL(activated()), SLOT(scrollUp()));

	act_scrolldown_ = new QAction(this);
	addAction(act_scrolldown_);
	connect(act_scrolldown_, SIGNAL(activated()), SLOT(scrollDown()));
}
void Client::doSend()
{
	boost::asio::async_write(
		socket_,
		boost::asio::buffer(sends_.front().getData(), sends_.front().getTotalLength()),
		[this](boost::system::error_code ec, std::size_t)
		{
			if ( ! ec)
			{
				sends_.pop_front();
				if ( ! sends_.empty())
					doSend();
			}
			else
				socket_.close();
		}
	);
}
Exemple #9
0
// raw form of send where full header gets passed-in
void Net::rawSend(uint8_t len, uint8_t hdr) {
#ifndef NET_NONE
  if (bufCnt >= NET_PKT) return; // error?
  buf[bufCnt].len = len;
  buf[bufCnt].hdr = hdr;
  bufCnt++;
  // if there was no packet queued just go ahead and send the new one
  trace('>');
  if (bufCnt == 1) {
    if (rf12_canSend()) {
      doSend();
    } else {
      trace('-');
      //Serial.println(F("Cannot send"));
    }
  }
#endif
}
Exemple #10
0
// Shift data into and out of JTAG chain.
//   In pointer may be ZEROS (shift in zeros) or ONES (shift in ones).
//   Out pointer may be NULL (not interested in data shifted out of the chain).
//
NeroStatus neroShift(
	struct NeroHandle *handle, uint32 numBits, const uint8 *inData, uint8 *outData, bool isLast,
	const char **error)
{
	NeroStatus returnCode, nStatus;
	uint32 numBytes;
	uint16 chunkSize;
	SendType sendType;
	bool isResponseNeeded;

	if ( inData == ZEROS ) {
		sendType = SEND_ZEROS;
	} else if ( inData == ONES ) {
		sendType = SEND_ONES;
	} else {
		sendType = SEND_DATA;
	}
	if ( outData ) {
		isResponseNeeded = true;
	} else {
		isResponseNeeded = false;
	}
	nStatus = beginShift(handle, numBits, sendType, isLast, isResponseNeeded, error);
	CHECK_STATUS(nStatus, "neroShift()", NERO_BEGIN_SHIFT);
	numBytes = bitsToBytes(numBits);
	while ( numBytes ) {
		chunkSize = (numBytes>=handle->endpointSize) ? handle->endpointSize : (uint16)numBytes;
		if ( sendType == SEND_DATA ) {
			nStatus = doSend(handle, inData, chunkSize, error);
			CHECK_STATUS(nStatus, "neroShift()", NERO_SEND);
			inData += chunkSize;
		}
		if ( isResponseNeeded ) {
			nStatus = doReceive(handle, outData, chunkSize, error);
			CHECK_STATUS(nStatus, "neroShift()", NERO_RECEIVE);
			outData += chunkSize;
		}
		numBytes -= chunkSize;
	}
	return NERO_SUCCESS;
cleanup:
	return returnCode;
}
Exemple #11
0
void CommandManager::update(float dt)
{
    if (m_commandQueue.size() > 0) {
        Command* command = m_commandQueue[0];
        switch (command->getCommandState()) {
            case CommandStateInited:
                doSend(command);
                command->setCommandState(CommandStateSending);
                break;
            case CommandStateResponded:
                break;
            case CommandStateResonsedProcessed:
                m_commandQueue.erase(m_commandQueue.begin());
                break;
            default:
                break;
        }
    }
}
void
SCI_Transporter::updateWritePtr(Uint32 lenBytes, Uint32 prio){
  
  Uint32 sz = m_sendBuffer.m_dataSize;
  Uint32 packet_size = m_PacketSize;
  sz += ((lenBytes + 3) >> 2);
  m_sendBuffer.m_dataSize = sz;
  
  if(sz > packet_size) { 
    /**------------------------------------------------- 
     * Buffer is full and we are ready to send. We will 
     * not wait since the signal is already in the buffer. 
     * Force flag set has the same indication that we 
     * should always send. If it is not possible to send 
     * we will not worry since we will soon be back for 
     * a renewed trial. 
     *------------------------------------------------- 
     */ 
    doSend();
  }
}
void XMLHttpRequestClass::send(const QScriptValue& data) {
    if (_readyState == OPENED && !_reply) {
        if (!data.isNull()) {
            _sendData = new QBuffer(this);
            if (data.isObject()) {
                QByteArray ba = qscriptvalue_cast<QByteArray>(data);
                _sendData->setData(ba);
            } else {
                _sendData->setData(data.toString().toUtf8());
            }
        }

        doSend();

        if (!_async) {
            QEventLoop loop;
            connect(this, SIGNAL(requestComplete()), &loop, SLOT(quit()));
            loop.exec();
        }
    }
}
void EwsSyncFolderItemsRequest::start()
{
    QString reqString;
    QXmlStreamWriter writer(&reqString);

    startSoapDocument(writer);

    writer.writeStartElement(ewsMsgNsUri, QStringLiteral("SyncFolderItems"));

    mShape.write(writer);

    writer.writeStartElement(ewsMsgNsUri, QStringLiteral("SyncFolderId"));
    mFolderId.writeFolderIds(writer);
    writer.writeEndElement();

    if (!mSyncState.isNull()) {
        writer.writeTextElement(ewsMsgNsUri, QStringLiteral("SyncState"), mSyncState);
    }

    writer.writeTextElement(ewsMsgNsUri, QStringLiteral("MaxChangesReturned"),
                            QString::number(mMaxChanges));

    writer.writeEndElement();

    endSoapDocument(writer);

    qCDebug(EWSRES_PROTO_LOG) << reqString;

    if (EWSRES_REQUEST_LOG().isDebugEnabled()) {
        QString st = mSyncState.isNull() ? QStringLiteral("none") : QString::number(qHash(mSyncState), 36);
        QString folder;
        qCDebugNC(EWSRES_REQUEST_LOG) << QStringLiteral("Starting SyncFolderItems request (folder: ")
                                      << mFolderId << QStringLiteral(", state: %1").arg(st);
    }

    prepare(reqString);

    doSend();
}
Exemple #15
0
void
TCP_Transporter::updateWritePtr(Uint32 lenBytes, Uint32 prio){
  m_sendBuffer.updateInsertPtr(lenBytes);
  
  const int bufsize = m_sendBuffer.bufferSize();
  if(bufsize > TCP_SEND_LIMIT) {
    //-------------------------------------------------
    // Buffer is full and we are ready to send. We will
    // not wait since the signal is already in the buffer.
    // Force flag set has the same indication that we
    // should always send. If it is not possible to send
    // we will not worry since we will soon be back for
    // a renewed trial.
    //-------------------------------------------------
    struct timeval no_timeout = {0,0};
    if(sendIsPossible(&no_timeout)) {
      //-------------------------------------------------
      // Send was possible, attempt at a send.
      //-------------------------------------------------
      doSend();
    }//if
  }
}
Exemple #16
0
void SendThread::run(){

    /* connect to server */
    try {
	skt = new zmq::socket_t(*context, ZMQ_REQ);
	skt->connect(serverAddress.toUtf8().data());
    } catch (zmq::error_t err){
	QString errorString = QString("unable to connect: %1").arg(err.what());
	qDebug() << "failed to connect skt: " << errorString;
	emit postedError(errorString);
	return;
    }

    if (hashArray && hashlen){
	doSendSample();
    } else {
	doSend();
    }

    delete skt;

    emit appendedText(tr("Done."));
    emit doneWithTask();
}
Exemple #17
0
/// Try to send data to this user. Disconnects if any problems occur.
void Buffer::user::Send(){
  if (!myRing){return;}//no ring!
  if (!S.connected()){return;}//cancel if not connected
  if (myRing->waiting){
    Stream::get()->waitForData();
    return;
  }//still waiting for next buffer?
  if (myRing->starved){
    //if corrupt data, warn and get new DTSC::Ring
    std::cout << "Warning: User " << MyNum << " was send corrupt video data and send to the next keyframe!" << std::endl;
    Stream::get()->dropRing(myRing);
    myRing = Stream::get()->getRing();
    return;
  }
  //try to complete a send
  Stream::get()->getReadLock();
  if (doSend(Stream::get()->getStream()->outPacket(myRing->b).c_str(), Stream::get()->getStream()->outPacket(myRing->b).length())){
    //switch to next buffer
    currsend = 0;
    if (myRing->b <= 0){myRing->waiting = true; return;}//no next buffer? go in waiting mode.
    myRing->b--;
  }//completed a send
  Stream::get()->dropReadLock();
}//send
Exemple #18
0
void SFEQuery::Send(QTcpSocket &socket)
{
    //set stream release
    _out.setVersion(QDataStream::Qt_4_7);
    //reserve place for total query size
    _out<< (quint32)0;
    //set command
    _out<< (quint32)_type;

    qDebug("cmd type %d",_type);

    doSend();

    _out.device()->seek(0);
    _out << (quint32) _outblock.size();

    qDebug("cmd size: %d",_outblock.size());

    dump(_outblock);
    socket.write(_outblock);
    socket.flush();


}
void process_input (void) {
	int bufferSize = 1024;

  	short buffer[BUFLEN];
	int l, i, level;
 
	//read a block of audio samples with proper error checking
  	if ((l = read (fd_in, buffer, sizeof (buffer))) == -1) {
      		perror ("Audio read");
      		exit (-1);		/* Or return an error code */
    	}

	//we are using mono 16bit. Stereo needs to be interleaved, more difficult
  	l = l / 2;

	//checking levels stuff
	level = 0;
  	for (i = 0; i < l; i++) {
       		int v = buffer[i];

      		if (v < 0)
			v = -v;		/* abs */

      		if (v > level)
			level = v;
    	}
	
  	level = (level + 1) / 1024;
	
	//save to file
	int index;
	int charBuffIndex = 0;
	char temp[BUFLEN * 2];
	for(index = 0; index < BUFLEN * 2; index += 2){
		//fprintf(fp, "%i\n", buffer[charBuffIndex]);
		short tempshort = buffer[charBuffIndex++];
		//short tempshort = 7192;
		//add the last 8 bits
		temp[index] = tempshort & 0xFF;
		//move the first 8 bits into the last 8 bits spot
		tempshort = tempshort >> 8;
		//save the next value
		temp[index + 1] = tempshort & 0xFF;
	}


	doSend(temp);

	int iindex;
	for(iindex = 0; iindex < BUFLEN; iindex++){
		printf("%i,", buffer[iindex]);
	}
	printf("\n"); 
	//exit(0);
	//end save to file
	

	//linear scale, real world(dBD) is log
  	for (i = 0; i < level; i++)
    		printf ("*");
  	for (i = level; i < 32; i++)
    		printf (".");
  	printf ("\r");
  	fflush (stdout);
}
void ReliableNetworkInterface::send(const Packet* packet, AddressPtr recipient) {
    unacknowledgedPackets.push_back(packet);
    doSend(packet, recipient);
    startAcknowledgmentTimer(packet, recipient);
}
Exemple #21
0
void MainWindow::sendKey(QString key)
{
    ui->log->append("KEY:" + key);
    method = KEY_MAP.find(key).value()->command();
    doSend();
}
void ReliableNetworkInterface::broadcast(const Packet* packet) {
    doSend(packet, broadcastAddress);
    delete packet;
}
Exemple #23
0
// Insert a message at the head of the queue
// Wait until there is either room on the queue or the timeout expires.
OsStatus OsMsgQShared::sendUrgent(const OsMsg& rMsg,
                                  const OsTime& rTimeout)
{
   return doSend(rMsg, rTimeout, TRUE, FALSE);
}
Exemple #24
0
// Insert a message at the tail of the queue.
// Sending from an ISR has a couple of implications.  Since we can't
// allocate memory within an ISR, we don't create a copy of the message
// before sending it and the sender and receiver need to agree on a
// protocol (outside this class) for when the message can be freed.
// The sentFromISR flag in the OsMsg object will be TRUE for messages
// sent using this method.
OsStatus OsMsgQShared::sendFromISR(const OsMsg& rMsg)
{
   return doSend(rMsg, OsTime::NO_WAIT, FALSE, TRUE);
}
Exemple #25
0
void parallelSend() {
  #pragma omp parallel
  doSend();
}
Exemple #26
0
int xsConnection::processEvent(xsEvent *e)
{
//	xsConnection *conn;
	xsConnEvent evt;

	// handle resolve event
	if (e->type == XS_EVT_RESOLVE)
	{
		XS_TRACE("[NET]xsConnResolveHandler: state:%d", state);
		if (state == XS_CONN_RESOLVING)
		{// should connect
			if (e->sys->data.resolve.success)
			{
				addr.addr.n = e->sys->data.resolve.addr.addr.n;
				return doConnect();
			}
			XS_ERROR("[NET]xsConnResolveHandler: Resolve failed.");
		}
		else
		{
			XS_ERROR("[NET]xsConnResolveHandler: Invoke XS_EVT_RESOLVE on wrong state: %d", state);
		}

		return XS_EC_ERROR;
	}

	// Cannot handle other event except socket event.
	if (e->type != XS_EVT_SOCK_READ && e->type != XS_EVT_SOCK_WRITE
		&& e->type != XS_EVT_SOCK_CONNECT && e->type != XS_EVT_SOCK_CLOSE)
		return XS_EC_OK;

	// handle socket event
	if (e->sys->data.socket.status != XS_EC_OK)
	{
		XS_ERROR("socket error. %d", e->sys->data.socket.status);
		destroyInstance();
		return XS_EC_OK;
	}

	switch (e->type)
	{
	case XS_EVT_SOCK_READ:
		XS_TRACE("[NET]xsConnHandler: OnRead");
		if (state == XS_CONN_ESTABLISHED)
			return doRecv();
		break;
	case XS_EVT_SOCK_WRITE:
		XS_TRACE("[NET]xsConnHandler: OnWrite");
		if (state == XS_CONN_ESTABLISHED)
			return doSend();
		break;
	case XS_EVT_SOCK_CONNECT:
		XS_TRACE("[NET]xsConnHandler: OnConnect");
		if (state == XS_CONN_CONNECTING)
		{
			state = XS_CONN_ESTABLISHED;
			evt.type = XS_EVT_CONN_ESTABLISHED;
			xsEvent::send(this, &evt);
		}
		else
		{
			XS_ERROR("[NET]xsConnHandler: Invoke XS_EVT_SOCK_CONNECT on wrong state: %d", state);
		}
		break;
	case XS_EVT_SOCK_CLOSE:
		XS_TRACE("[NET]xsConnHandler: OnClose");
		destroyInstance();
		break;
	}

	return XS_EC_OK;
}
Exemple #27
0
//called when the timer fires.
void  IRCQueue::sendNow()
{
    if (doSend())
        adjustTimer();
    //else //its a single-shot timer so if we don't adjust it, it won't run :)
}
Exemple #28
0
void Interpreter::Start() {
    // initialization
    method = GetFrame()->GetMethod();
    currentBytecodes = method->GetBytecodes();

    void* loopTargets[] = {
        &&LABEL_BC_HALT,
        &&LABEL_BC_DUP,
        &&LABEL_BC_PUSH_LOCAL,
        &&LABEL_BC_PUSH_ARGUMENT,
        &&LABEL_BC_PUSH_FIELD,
        &&LABEL_BC_PUSH_BLOCK,
        &&LABEL_BC_PUSH_CONSTANT,
        &&LABEL_BC_PUSH_GLOBAL,
        &&LABEL_BC_POP,
        &&LABEL_BC_POP_LOCAL,
        &&LABEL_BC_POP_ARGUMENT,
        &&LABEL_BC_POP_FIELD,
        &&LABEL_BC_SEND,
        &&LABEL_BC_SUPER_SEND,
        &&LABEL_BC_RETURN_LOCAL,
        &&LABEL_BC_RETURN_NON_LOCAL,
        &&LABEL_BC_JUMP_IF_FALSE,
        &&LABEL_BC_JUMP_IF_TRUE,
        &&LABEL_BC_JUMP
    };

    goto *loopTargets[currentBytecodes[bytecodeIndexGlobal]];

    //
    // THIS IS THE former interpretation loop
    LABEL_BC_HALT:
      PROLOGUE(1);
      return; // handle the halt bytecode

    LABEL_BC_DUP:
      PROLOGUE(1);
      doDup();
      DISPATCH_NOGC();

    LABEL_BC_PUSH_LOCAL:       
      PROLOGUE(3);
      doPushLocal(bytecodeIndexGlobal - 3);
      DISPATCH_NOGC();

    LABEL_BC_PUSH_ARGUMENT:
      PROLOGUE(3);
      doPushArgument(bytecodeIndexGlobal - 3);
      DISPATCH_NOGC();

    LABEL_BC_PUSH_FIELD:
      PROLOGUE(2);
      doPushField(bytecodeIndexGlobal - 2);
      DISPATCH_NOGC();

    LABEL_BC_PUSH_BLOCK:
      PROLOGUE(2);
      doPushBlock(bytecodeIndexGlobal - 2);
      DISPATCH_GC();

    LABEL_BC_PUSH_CONSTANT:
      PROLOGUE(2);
      doPushConstant(bytecodeIndexGlobal - 2);
      DISPATCH_NOGC();

    LABEL_BC_PUSH_GLOBAL:
      PROLOGUE(2);
      doPushGlobal(bytecodeIndexGlobal - 2);
      DISPATCH_GC();

    LABEL_BC_POP:
      PROLOGUE(1);
      doPop();
      DISPATCH_NOGC();

    LABEL_BC_POP_LOCAL:
      PROLOGUE(3);
      doPopLocal(bytecodeIndexGlobal - 3);
      DISPATCH_NOGC();

    LABEL_BC_POP_ARGUMENT:
      PROLOGUE(3);
      doPopArgument(bytecodeIndexGlobal - 3);
      DISPATCH_NOGC();

    LABEL_BC_POP_FIELD:
      PROLOGUE(2);
      doPopField(bytecodeIndexGlobal - 2);
      DISPATCH_NOGC();

    LABEL_BC_SEND:
      PROLOGUE(2);
      doSend(bytecodeIndexGlobal - 2);
      DISPATCH_GC();

    LABEL_BC_SUPER_SEND:
      PROLOGUE(2);
      doSuperSend(bytecodeIndexGlobal - 2);
      DISPATCH_GC();

    LABEL_BC_RETURN_LOCAL:
      PROLOGUE(1);
      doReturnLocal();
      DISPATCH_NOGC();

    LABEL_BC_RETURN_NON_LOCAL:
      PROLOGUE(1);
      doReturnNonLocal();
      DISPATCH_NOGC();

    LABEL_BC_JUMP_IF_FALSE:
      PROLOGUE(5);
      doJumpIfFalse(bytecodeIndexGlobal - 5);
      DISPATCH_NOGC();

    LABEL_BC_JUMP_IF_TRUE:
      PROLOGUE(5);
      doJumpIfTrue(bytecodeIndexGlobal - 5);
      DISPATCH_NOGC();

    LABEL_BC_JUMP:
      PROLOGUE(5);
      doJump(bytecodeIndexGlobal - 5);
      DISPATCH_NOGC();
}

VMFrame* Interpreter::PushNewFrame(VMMethod* method) {
    SetFrame(GetUniverse()->NewFrame(GetFrame(), method));
    return GetFrame();
}