コード例 #1
0
int
InetSocket::maxIPPayload(void) const throw()
{
  SockAddr addr;
  if (getSockAddr(addr)) {
    switch (addr.family()) {
      case InetAddr::Invalid:
      default:
        break;
      case InetAddr::IPv4:
        return (mtu() - 20);
      case InetAddr::IPv6:
        return (mtu() - 40);
    }
  }
  return 0;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: CCJY/coliru
 void write(Internal, int64_t remaining)
 {
     std::vector<uint8_t> buf(mtu());
     while (auto n = tcp->write(in, buf.data(), std::min(buf.size(), remaining)))
     {
         remaining -= n;
         
         if (remaining <= 0)
         {
             return;
         }
     }
     
     dispatch([=](Internal in) { this->write(in, remaining); });
 }
コード例 #3
0
ファイル: pc.cpp プロジェクト: cyclefusion/galera
void gcomm::PC::connect(bool start_prim)
{
    try
    {
        // for backward compatibility with old approach: gcomm://0.0.0.0
        start_prim = (start_prim || host_is_any (uri_.get_host()));
    }
    catch (gu::NotSet& ns)
    {
        start_prim = true;
    }

    const bool wait_prim(
        gu::from_string<bool>(
            uri_.get_option(Conf::PcWaitPrim, Defaults::PcWaitPrim)));

    const gu::datetime::Period wait_prim_timeout(
        gu::from_string<gu::datetime::Period>(
            uri_.get_option(Conf::PcWaitPrimTimeout,
                            Defaults::PcWaitPrimTimeout)));

    pstack_.push_proto(gmcast_);
    pstack_.push_proto(evs_);
    pstack_.push_proto(pc_);
    pstack_.push_proto(this);
    pnet().insert(&pstack_);

    gmcast_->connect();

    closed_ = false;

    evs_->shift_to(evs::Proto::S_JOINING);
    pc_->connect(start_prim);

    // Due to #658 there is limited announce period after which
    // node is allowed to proceed to non-prim if other nodes
    // are not detected.
    gu::datetime::Date try_until(gu::datetime::Date::now() + announce_timeout_);
    while (start_prim == false && evs_->known_size() <= 1)
    {
        // Send join messages without handling them
        evs_->send_join(false);
        pnet().event_loop(gu::datetime::Sec/2);

        if (try_until < gu::datetime::Date::now())
        {
            break;
        }
    }

    log_debug << "PC/EVS Proto initial state: " << *evs_;
    if (evs_->state() != evs::Proto::S_OPERATIONAL)
    {
        log_debug << "PC/EVS Proto sending join request";
        evs_->send_join();
    }
    gcomm_assert(evs_->state() == evs::Proto::S_GATHER ||
                 evs_->state() == evs::Proto::S_INSTALL ||
                 evs_->state() == evs::Proto::S_OPERATIONAL);

    // - Due to #658 we loop here only if node is told to start in prim.
    // - Fix for #680, bypass waiting prim only if explicitly required
    try_until = gu::datetime::Date::now() + wait_prim_timeout;
    while ((wait_prim == true || start_prim == true) &&
           pc_->state() != pc::Proto::S_PRIM)
    {
        pnet().event_loop(gu::datetime::Sec/2);
        if (try_until < gu::datetime::Date::now())
        {
            pc_->close();
            evs_->close();
            gmcast_->close();
            pnet().erase(&pstack_);
            pstack_.pop_proto(this);
            pstack_.pop_proto(pc_);
            pstack_.pop_proto(evs_);
            pstack_.pop_proto(gmcast_);
            gu_throw_error(ETIMEDOUT) << "failed to reach primary view";
        }
    }

    pc_->set_mtu(mtu());
}
コード例 #4
0
ファイル: pppsetting.cpp プロジェクト: Bridges/libnm-qt5
QVariantMap NetworkManager::PppSetting::toMap() const
{
    QVariantMap setting;

    if (!noAuth()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_NOAUTH), noAuth());
    }

    if (refuseEap()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_REFUSE_EAP), refuseEap());
    }

    if (refusePap()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_REFUSE_PAP), refusePap());
    }

    if (refuseChap()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_REFUSE_CHAP), refuseChap());
    }

    if (refuseMschap()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAP), refuseMschap());
    }

    if (refuseMschapv2()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAPV2), refuseMschapv2());
    }

    if (noBsdComp()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_NOBSDCOMP), noBsdComp());
    }

    if (noDeflate()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_NODEFLATE), noDeflate());
    }

    if (noVjComp()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_NO_VJ_COMP), noVjComp());
    }

    if (requireMppe()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE), requireMppe());
    }

    if (requireMppe128()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE_128), requireMppe128());
    }

    if (mppeStateful()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_MPPE_STATEFUL), mppeStateful());
    }

    if (cRtsCts()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_CRTSCTS), cRtsCts());
    }

    if (baud()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_BAUD), baud());
    }

    if (mru()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_MRU), mru());
    }

    if (mtu()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_MTU), mtu());
    }

    if (lcpEchoFailure()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_LCP_ECHO_FAILURE), lcpEchoFailure());
    }

    if (lcpEchoInterval()) {
        setting.insert(QLatin1String(NM_SETTING_PPP_LCP_ECHO_INTERVAL), lcpEchoInterval());
    }

    return setting;
}
コード例 #5
0
ファイル: ReadCCMIO.cpp プロジェクト: chrismullins/moab
ErrorCode ReadCCMIO::construct_cells(TupleList &face_map, 
#ifndef TUPLE_LIST
                                     SenseList &sense_map, 
#endif
                                     TupleList & /* vert_map */,
                                     std::map<int,int> &cell_topo_types,
                                     std::vector<EntityHandle> &new_cells) 
{
  std::vector<EntityHandle> facehs;
  std::vector<int> senses;
  EntityHandle cell;
  ErrorCode tmp_rval, rval = MB_SUCCESS;
  EntityType this_type = MBMAXTYPE;
  bool has_mid_nodes = false;
#ifdef TUPLE_LIST
  unsigned int i = 0;
  while (i < face_map.n) {
      // pull out face handles bounding the same cell
    facehs.clear();
    int this_id = face_map.get_int(i);
    unsigned int inext = i;
    while (face_map.get_int(inext) == this_id && inext <= face_map.n) {
      inext++;
      EntityHandle face = face_map.get_ulong(inext);
      facehs.push_back(face);
      senses.push_back(face_map.get_short(inext));
    }
    this_type = MBMAXTYPE;
    has_mid_nodes = false;
#else
      
  std::map<int,std::vector<EntityHandle> >::iterator fmit;
  std::map<int,std::vector<int> >::iterator smit;
  std::map<int,int>::iterator typeit;
  for (fmit = face_map.begin(), smit = sense_map.begin();
       fmit != face_map.end(); fmit++, smit++) {
      // pull out face handles bounding the same cell
    facehs.clear();
    int this_id = (*fmit).first;
    facehs = (*fmit).second;
    senses.clear();
    senses = (*smit).second;
    typeit = cell_topo_types.find(this_id);
    if (typeit != cell_topo_types.end()) {
      rval = ccmio_to_moab_type(typeit->second, this_type, has_mid_nodes);
    }
    else {
      this_type = MBMAXTYPE;
      has_mid_nodes = false;
    }
#endif
    tmp_rval = create_cell_from_faces(facehs, senses, this_type, has_mid_nodes, cell);
    if (MB_SUCCESS != tmp_rval) rval = tmp_rval;
    else {
      new_cells.push_back(cell);
        // tag cell with global id
      tmp_rval = mbImpl->tag_set_data(mGlobalIdTag, &cell, 1, &this_id);
      if (MB_SUCCESS != tmp_rval) rval = tmp_rval;
    }
  }
    
  return rval;
}

ErrorCode ReadCCMIO::ccmio_to_moab_type(int ccm_type, EntityType &moab_type, bool &has_mid_nodes) 
{
  switch (ccm_type) {
    case 1:
        moab_type = MBVERTEX;
        break;
    case 2:
    case 28:
        moab_type = MBEDGE;
        break;
    case 29:
        moab_type = MBMAXTYPE;
        break;
    case 3:
    case 4:
        moab_type = MBQUAD;
        break;
    case 11:
    case 21:
        moab_type = MBHEX;
        break;
    case 12:
    case 22:
        moab_type = MBPRISM;
        break;
    case 13:
    case 23:
        moab_type = MBTET;
        break;
    case 14:
    case 24:
        moab_type = MBPYRAMID;
        break;
    case 255:
        moab_type = MBPOLYHEDRON;
        break;
    default:
        moab_type = MBMAXTYPE;
  }
  
  switch (ccm_type) {
    case 28:
    case 4:
    case 21:
    case 22:
    case 23:
    case 24:
        has_mid_nodes = true;
        break;
    default:
        break;
  }
  
  return MB_SUCCESS;
}

ErrorCode ReadCCMIO::create_cell_from_faces(std::vector<EntityHandle> &facehs,
                                            std::vector<int> &senses,
                                            EntityType this_type,
                                            bool /* has_mid_nodes */,
                                            EntityHandle &cell) 
{
  ErrorCode rval;

    // test up front to see if they're one type
  EntityType face_type = mbImpl->type_from_handle(facehs[0]);
  bool same_type = true;
  for (std::vector<EntityHandle>::iterator vit = facehs.begin(); vit != facehs.end(); vit++) {
    if (face_type != mbImpl->type_from_handle(*vit)) {
      same_type = false;
      break;
    }
  }

  std::vector<EntityHandle> verts;
  EntityType input_type = this_type;
  std::vector<EntityHandle> storage;
  MeshTopoUtil mtu(mbImpl);
  
    // preset this to maxtype, so we get an affirmative choice in loop
  this_type = MBMAXTYPE;
  
  if ((MBTET == input_type || MBMAXTYPE == input_type) && same_type &&
      face_type == MBTRI && facehs.size() == 4) {
      // try to get proper connectivity for tet

      // get connectivity of first face, and reverse it if sense is forward, since 
      // base face always points into entity
    rval = mbImpl->get_connectivity(&facehs[0], 1, verts);
    CHKERR(rval, "Couldn't get connectivity.");
    if (senses[0] > 0) std::reverse(verts.begin(), verts.end());

      // get the 4th vertex through the next tri
    const EntityHandle *conn; int conn_size;
    rval = mbImpl->get_connectivity(facehs[1], conn, conn_size, true, &storage);
    CHKERR(rval, "Couldn't get connectivity.");
    int i = 0;
    while (std::find(verts.begin(), verts.end(), conn[i]) != verts.end() && i < conn_size) i++;

      // if i is not at the end of the verts, found the apex; otherwise fall back to polyhedron
    if (conn_size != i) {
      this_type = MBTET;
      verts.push_back(conn[i]);
    }
  }
  else if ((MBHEX == input_type || MBMAXTYPE == input_type) && same_type &&
           MBQUAD == face_type && facehs.size() == 6) {
      // build hex from quads
      // algorithm:
      // - verts = vertices from 1st quad
      // - find quad q1 sharing verts[0] and verts[1]
      // - find quad q2 sharing other 2 verts in q1
      // - find v1 = opposite vert from verts[1] in q1 , v2 = opposite from verts[0]
      // - get i = offset of v1 in verts2 of q2, rotate verts2 by i
      // - if verts2[i+1%4] != v2, flip verts2 by switching verts2[1] and verts2[3]
      // - append verts2 to verts


      // get the other vertices for this hex; need to find the quad with no common vertices
    Range tmp_faces, tmp_verts;
      // get connectivity of first face, and reverse it if sense is forward, since 
      // base face always points into entity
    rval = mbImpl->get_connectivity(&facehs[0], 1, verts);
    CHKERR(rval, "Couldn't get connectivity.");
    if (senses[0] > 0) std::reverse(verts.begin(), verts.end());


      // get q1, which shares 2 vertices with q0
    std::copy(facehs.begin(), facehs.end(), range_inserter(tmp_faces));
    rval = mbImpl->get_adjacencies(&verts[0], 2, 2, false, tmp_faces);
    if (MB_SUCCESS != rval || tmp_faces.size() != 2)
      CHKERR(MB_FAILURE, "Couldn't get adj face.");
    tmp_faces.erase(facehs[0]);
    EntityHandle q1 = *tmp_faces.begin();
      // get other 2 verts of q1
    rval = mbImpl->get_connectivity(&q1, 1, tmp_verts);
    CHKERR(rval, "Couldn't get adj verts.");
    tmp_verts.erase(verts[0]); tmp_verts.erase(verts[1]);
      // get q2
    std::copy(facehs.begin(), facehs.end(), range_inserter(tmp_faces));
    rval = mbImpl->get_adjacencies(tmp_verts, 2, false, tmp_faces);
    if (MB_SUCCESS != rval || tmp_faces.size() != 2)
      CHKERR(MB_FAILURE, "Couldn't get adj face.");
    tmp_faces.erase(q1);
    EntityHandle q2 = *tmp_faces.begin();
      // get verts in q2
    rval = mbImpl->get_connectivity(&q2, 1, storage);
    CHKERR(rval, "Couldn't get adj vertices.");

      // get verts in q1 opposite from v[1] and v[0] in q0
    EntityHandle v0 = 0, v1 = 0;
    rval = mtu.opposite_entity(q1, verts[1], v0);
    rval = mtu.opposite_entity(q1, verts[0], v1);
    if (v0 && v1) {

        // offset of v0 in q2, then rotate and flip
      unsigned int ioff = std::find(storage.begin(), storage.end(), v0) - storage.begin();
      if (4 == ioff)
        CHKERR(MB_FAILURE, "Trouble finding offset.");

      if (storage[(ioff+1)%4] != v1) {
        std::reverse(storage.begin(), storage.end());
        ioff = std::find(storage.begin(), storage.end(), v0) - storage.begin();
      }
      if (0 != ioff)
        std::rotate(storage.begin(), storage.begin()+ioff, storage.end());

        // copy into verts, and make hex
      std::copy(storage.begin(), storage.end(), std::back_inserter(verts));
      this_type = MBHEX;
    }
  }

  if (MBMAXTYPE == this_type && facehs.size() == 5) {
      // some preliminaries
    std::vector<EntityHandle> tris, quads;
    for (unsigned int i = 0; i < 5; i++) {
      if (MBTRI == mbImpl->type_from_handle(facehs[i])) tris.push_back(facehs[i]);
      else if (MBQUAD == mbImpl->type_from_handle(facehs[i])) quads.push_back(facehs[i]);
    }

      // check for prisms
    if (2 == tris.size() && 3 == quads.size()) {
        // ok, we have the right number of tris and quads; try to find the proper verts

        // get connectivity of first tri, and reverse if necessary
      int index = std::find(facehs.begin(), facehs.end(), tris[0]) - facehs.begin();
      rval = mbImpl->get_connectivity(&tris[0], 1, verts);
      CHKERR(rval, "Couldn't get connectivity.");
      if (senses[index] > 0) std::reverse(verts.begin(), verts.end());

        // now align vertices of other tri, through a quad, similar to how we did hexes
        // get q1, which shares 2 vertices with t0
      Range tmp_faces, tmp_verts;
      std::copy(facehs.begin(), facehs.end(), range_inserter(tmp_faces));
      rval = mbImpl->get_adjacencies(&verts[0], 2, 2, false, tmp_faces);
      if (MB_SUCCESS != rval || tmp_faces.size() != 2)
      CHKERR(MB_FAILURE, "Couldn't get adj face.");
      tmp_faces.erase(tris[0]);
      EntityHandle q1 = *tmp_faces.begin();
        // get verts in q1
      rval = mbImpl->get_connectivity(&q1, 1, storage);
      CHKERR(rval, "Couldn't get adj vertices.");

        // get verts in q1 opposite from v[1] and v[0] in q0
      EntityHandle v0 = 0, v1 = 0;
      rval = mtu.opposite_entity(q1, verts[1], v0);
      rval = mtu.opposite_entity(q1, verts[0], v1);
      if (v0 && v1) {
          // offset of v0 in t2, then rotate and flip
        storage.clear();
        rval = mbImpl->get_connectivity(&tris[1], 1, storage);
        CHKERR(rval, "Couldn't get connectivity.");
    
        index = std::find(facehs.begin(), facehs.end(), tris[1]) - facehs.begin();
        if (senses[index] < 0) std::reverse(storage.begin(), storage.end());
        unsigned int ioff = std::find(storage.begin(), storage.end(), v0) - storage.begin();
        if (3 == ioff) CHKERR(MB_FAILURE, "Trouble finding offset.");
        for (unsigned int i = 0; i < 3; i++)
          verts.push_back(storage[(ioff+i)%3]);

        this_type = MBPRISM;
      }
    }
    else if (tris.size() == 4 && quads.size() == 1) {
        // check for pyramid
        // get connectivity of first tri, and reverse if necessary
      int index = std::find(facehs.begin(), facehs.end(), quads[0]) - facehs.begin();
      rval = mbImpl->get_connectivity(&quads[0], 1, verts);
      CHKERR(rval, "Couldn't get connectivity.");
      if (senses[index] > 0) std::reverse(verts.begin(), verts.end());

        // get apex node
      rval = mbImpl->get_connectivity(&tris[0], 1, storage);
      CHKERR(rval, "Couldn't get connectivity.");
      for (unsigned int i = 0; i < 3; i++) {
        if (std::find(verts.begin(), verts.end(), storage[i]) == verts.end()) {
          verts.push_back(storage[i]);
          break;
        }
      }

      if (5 == verts.size()) this_type = MBPYRAMID;
    }
    else {
        // dummy else clause to stop in debugger
      this_type = MBMAXTYPE;
    }
  }

  if (MBMAXTYPE != input_type && input_type != this_type && this_type != MBMAXTYPE)
    std::cerr << "Warning: types disagree (cell_topo_type = " << CN::EntityTypeName(input_type)
              << ", faces indicate type " << CN::EntityTypeName(this_type) << std::endl;

  if (MBMAXTYPE != input_type && this_type == MBMAXTYPE && input_type != MBPOLYHEDRON)
    std::cerr << "Warning: couldn't find proper connectivity for specified topo_type = " 
              << CN::EntityTypeName(input_type) << std::endl;

    // now make the element; if we fell back to polyhedron, use faces, otherwise use verts
  if (MBPOLYHEDRON == this_type || MBMAXTYPE == this_type) 
    rval = mbImpl->create_element(MBPOLYHEDRON, &facehs[0], facehs.size(), cell);
  else
    rval = mbImpl->create_element(this_type, &verts[0], verts.size(), cell);
  CHKERR(rval, "create_element failed.");
  
  return MB_SUCCESS;
}