Ejemplo n.º 1
0
static int dequeue_message(int for_proc, void *msg_data, size_t msg_size, void *session)
{
   int result, queue_lock_held = 0, read_partial_message;
   size_t bytes_read = 0, bytes_to_read, qsize, qbytes_read;
   unsigned char *read_from, *write_to;
   void *qdata;

   if (!has_message(for_proc, session))
      return 0;
   
   result = take_queue_lock(session);
   if (result == -1) {
      goto error;
   }
   queue_lock_held = 1;

   while (has_message(for_proc, session) && bytes_read < msg_size) {
      get_message(for_proc, &qdata, &qsize, &qbytes_read, session);
      
      read_partial_message = (qsize - qbytes_read) > (msg_size - bytes_read);
      read_from = ((unsigned char *) qdata) + qbytes_read;
      write_to = ((unsigned char *) msg_data) + bytes_read;
      if (read_partial_message)
         bytes_to_read = msg_size - bytes_read;
      else
         bytes_to_read = qsize - qbytes_read;
      
      memcpy(write_to, read_from, bytes_to_read);
      bytes_read += bytes_to_read;
      qbytes_read += bytes_to_read;
      update_bytes_read(for_proc, qbytes_read, session);
      
      if (!read_partial_message) {
         assert(qbytes_read == qsize);
         rm_message(for_proc, session);
      }
   }

   result = release_queue_lock(session);
   if (result == -1) {
      goto error;
   }
   queue_lock_held = 0;

   return bytes_read;

  error:

   if (queue_lock_held)
      release_queue_lock(session);
   return -1;
}
Ejemplo n.º 2
0
int Connection::check_for_input(float time)
{
    if (has_message())
        return 1;

    int i = 0;
    do
    {
        struct timeval timeout;
        timeout.tv_sec = (int)time;
        timeout.tv_usec = (int)((time - timeout.tv_sec) * 1000000);

        // initialize the bit fields according to the existing sockets
        // so far only reads are of interest

        fd_set fdread;
        FD_ZERO(&fdread);
        FD_SET(sock->get_id(), &fdread);

        i = select(sock->get_id() + 1, &fdread, NULL, NULL, &timeout);
    } while (i == -1 && errno == EINTR);

    // find the connection that has the read attempt

    if (i > 0)
        return (1);
    else if (i < 0)
    {
        char buf[1024];
        sprintf(buf, "select failed: %s\n", strerror(errno));
        // print_comment(__LINE__, __FILE__, buf);
    }
    return 0;
}
int AttentionMessage::ByteSize() const {
  int total_size = 0;
  
  if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
    // required string message = 1;
    if (has_message()) {
      total_size += 1 +
        ::google::protobuf::internal::WireFormatLite::StringSize(
          this->message());
    }
    
    // optional float time_to_show = 2;
    if (has_time_to_show()) {
      total_size += 1 + 4;
    }
    
    // optional .llsf_msgs.Team team_color = 3;
    if (has_team_color()) {
      total_size += 1 +
        ::google::protobuf::internal::WireFormatLite::EnumSize(this->team_color());
    }
    
  }
  if (!unknown_fields().empty()) {
    total_size +=
      ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
        unknown_fields());
  }
  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
  _cached_size_ = total_size;
  GOOGLE_SAFE_CONCURRENT_WRITES_END();
  return total_size;
}
::google::protobuf::uint8* AttentionMessage::SerializeWithCachedSizesToArray(
    ::google::protobuf::uint8* target) const {
  // required string message = 1;
  if (has_message()) {
    ::google::protobuf::internal::WireFormat::VerifyUTF8String(
      this->message().data(), this->message().length(),
      ::google::protobuf::internal::WireFormat::SERIALIZE);
    target =
      ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
        1, this->message(), target);
  }
  
  // optional float time_to_show = 2;
  if (has_time_to_show()) {
    target = ::google::protobuf::internal::WireFormatLite::WriteFloatToArray(2, this->time_to_show(), target);
  }
  
  // optional .llsf_msgs.Team team_color = 3;
  if (has_team_color()) {
    target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(
      3, this->team_color(), target);
  }
  
  if (!unknown_fields().empty()) {
    target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
        unknown_fields(), target);
  }
  return target;
}
void AttentionMessage::SerializeWithCachedSizes(
    ::google::protobuf::io::CodedOutputStream* output) const {
  // required string message = 1;
  if (has_message()) {
    ::google::protobuf::internal::WireFormat::VerifyUTF8String(
      this->message().data(), this->message().length(),
      ::google::protobuf::internal::WireFormat::SERIALIZE);
    ::google::protobuf::internal::WireFormatLite::WriteString(
      1, this->message(), output);
  }
  
  // optional float time_to_show = 2;
  if (has_time_to_show()) {
    ::google::protobuf::internal::WireFormatLite::WriteFloat(2, this->time_to_show(), output);
  }
  
  // optional .llsf_msgs.Team team_color = 3;
  if (has_team_color()) {
    ::google::protobuf::internal::WireFormatLite::WriteEnum(
      3, this->team_color(), output);
  }
  
  if (!unknown_fields().empty()) {
    ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
        unknown_fields(), output);
  }
}
void AttentionMessage::Clear() {
  if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
    if (has_message()) {
      if (message_ != &::google::protobuf::internal::kEmptyString) {
        message_->clear();
      }
    }
    time_to_show_ = 0;
    team_color_ = 0;
  }
  ::memset(_has_bits_, 0, sizeof(_has_bits_));
  mutable_unknown_fields()->Clear();
}
Ejemplo n.º 7
0
bool GameNetConnection::has_incoming_sync() {
	return has_message(_delayed_messages, PACKET_FORCE_SYNC);
}
Ejemplo n.º 8
0
int main()
{
    try {
        booster::locale::generator g;
        std::locale l=g("en_US.UTF-8");
        TEST(has_message(l));

        g.categories(g.categories() ^ booster::locale::message_facet);
        g.locale_cache_enabled(true);
        g("en_US.UTF-8");
        g.categories(g.categories() | booster::locale::message_facet);
        l=g("en_US.UTF-8");
        TEST(!has_message(l));
        g.clear_cache();
        g.locale_cache_enabled(false);
        l=g("en_US.UTF-8");
        TEST(has_message(l));
        g.characters(g.characters() ^ booster::locale::char_facet);
        l=g("en_US.UTF-8");
        TEST(!has_message(l));
        g.characters(g.characters() | booster::locale::char_facet);
        l=g("en_US.UTF-8");
        TEST(has_message(l));

        l=g("en_US.ISO8859-1");
        TEST(std::use_facet<booster::locale::info>(l).language()=="en");
        TEST(std::use_facet<booster::locale::info>(l).country()=="US");
        TEST(!std::use_facet<booster::locale::info>(l).utf8());
        TEST(std::use_facet<booster::locale::info>(l).encoding()=="iso8859-1");

        l=g("en_US.UTF-8");
        TEST(std::use_facet<booster::locale::info>(l).language()=="en");
        TEST(std::use_facet<booster::locale::info>(l).country()=="US");
        TEST(std::use_facet<booster::locale::info>(l).utf8());

        l=g("en_US.ISO8859-1");
        TEST(std::use_facet<booster::locale::info>(l).language()=="en");
        TEST(std::use_facet<booster::locale::info>(l).country()=="US");
        TEST(!std::use_facet<booster::locale::info>(l).utf8());
        TEST(std::use_facet<booster::locale::info>(l).encoding()=="iso8859-1");

        l=g("en_US.ISO8859-1");
        TEST(std::use_facet<booster::locale::info>(l).language()=="en");
        TEST(std::use_facet<booster::locale::info>(l).country()=="US");
        TEST(!std::use_facet<booster::locale::info>(l).utf8());
        TEST(std::use_facet<booster::locale::info>(l).encoding()=="iso8859-1");

        std::locale l_wt(std::locale::classic(),new test_facet);
        
        TEST(std::has_facet<test_facet>(g.generate(l_wt,"en_US.UTF-8")));
        TEST(std::has_facet<test_facet>(g.generate(l_wt,"en_US.ISO8859-1")));
        TEST(!std::has_facet<test_facet>(g("en_US.UTF-8")));
        TEST(!std::has_facet<test_facet>(g("en_US.ISO8859-1")));

        g.locale_cache_enabled(true);
        g.generate(l_wt,"en_US.UTF-8");
        g.generate(l_wt,"en_US.ISO8859-1");
        TEST(std::has_facet<test_facet>(g("en_US.UTF-8")));
        TEST(std::has_facet<test_facet>(g("en_US.ISO8859-1")));
        TEST(std::use_facet<booster::locale::info>(g("en_US.UTF-8")).utf8());
        TEST(!std::use_facet<booster::locale::info>(g("en_US.ISO8859-1")).utf8());

    }
    catch(std::exception const &e) {
        std::cerr << "Failed " << e.what() << std::endl;
        return EXIT_FAILURE;
    }
    FINALIZE();

}