コード例 #1
0
ファイル: UIPClient.cpp プロジェクト: eduardofigs/arduino_uip
// This function is going to use uIP's protosockets to handle the connection.
// This means it must return int, because of the way the protosockets work.
// In a nutshell, when a PSOCK_* macro needs to wait for something, it will
// return from handle_connection so that other work can take place.  When the
// event is triggered, uip_callback() will call this function again and the
// switch() statement (see below) will take care of resuming execution where
// it left off.  It *looks* like this function runs from start to finish, but
// that's just an illusion to make it easier to code :-)
int
UIPClient::handle_connection(uip_tcp_appstate_t *s)
{
  // All protosockets must start with this macro.  Its internal implementation
  // is that of a switch() statement, so all code between PSOCK_BEGIN and
  // PSOCK_END is actually inside a switch block.  (This means for example,
  // that you can't declare variables in the middle of it!)

  struct psock *p = &s->p;
  uip_userdata_t *u = (uip_userdata_t *) s->user;

  PSOCK_BEGIN(p);

    if (uip_newdata() && readyToReceive(s))
      {
        PSOCK_READBUF_LEN(p, 0); //TODO check what happens when there's more new data incoming than space left in UIPClients buffer (most likely this is just discarded, isn't it?)
        dataReceived(s);
      }

    if (readyToSend(s))
      {
        PSOCK_SEND(p, u->out_buffer, u->out_len);
        dataSent(s);
      }

    if (isClosed(s))
      {
        // Disconnect.
        PSOCK_CLOSE(p);
      }

    // All protosockets must end with this macro.  It closes the switch().
  PSOCK_END(p);
}
コード例 #2
0
    bool SpiPollingReader::read(uint8_t& byte) {

        while(!readyToReceive())
            if(_peripheral.hasError())
                return false;

        byte=SPI_I2S_ReceiveData(_peripheral);
        return true;
    }
コード例 #3
0
ファイル: qasyncio.cpp プロジェクト: AliYousuf/univ-aca-mips
/*!
  This should be called whenever readyToReceive() might have become non-zero.
  It is merely calls QAsyncIO::ready() if readyToReceive() is non-zero.
*/
void QDataSink::maybeReady()
{
    if (readyToReceive()) ready();
}