Ejemplo n.º 1
0
Archivo: View.cpp Proyecto: sajty/eris
void View::appear(const std::string& eid, float stamp)
{
    Entity* ent = getEntity(eid);
    if (!ent) {
        getEntityFromServer(eid);
        return; // everything else will be done once the SIGHT arrives
    }

    if (ent->m_recentlyCreated)
    {
        EntityCreated.emit(ent);
        ent->m_recentlyCreated = false;
    }
    
    if (ent->isVisible()) return;
    
    if ((stamp == 0) || (stamp > ent->getStamp())) {
        if (isPending(eid)) {
            m_pending[eid] = SACTION_APPEAR;
        } else {
            // local data is out of data, re-look
            getEntityFromServer(eid);
        }
    } else
        ent->setVisible(true);

}
Ejemplo n.º 2
0
ssize_t Socket::writeData(const void *Source, size_t Size, timeout_t timeout)
{
    if (Size < 1)
        return (0);

    ssize_t nstat;
    const char *Slide = (const char *) Source;

    while (true) {
        if (timeout) {
            if (!isPending (pendingOutput, timeout)) {
                error(errOutput);
                return (-1);
            }
        }
        nstat =::send (so, Slide, _IOLEN64 Size, MSG_NOSIGNAL);

        if (nstat <= 0) {
            error(errOutput);
            return (-1);
        }
        Size -= nstat;
        Slide += nstat;


        if (Size <= 0)
            break;
    }
    return (nstat);
}
Ejemplo n.º 3
0
bool RObject::updateStructure (RData *new_data) {
	RK_TRACE (OBJECTS);
	if (new_data->getDataLength () == 0) { // can happen, if the object no longer exists
		return false;
	}

	RK_ASSERT (new_data->getDataLength () >= 5);
	RK_ASSERT (new_data->getDataType () == RData::StructureVector);

	if (!canAccommodateStructure (new_data)) return false;

	bool properties_change = false;

	properties_change = updateName (new_data->getStructureVector ()[0]);
	properties_change = updateType (new_data->getStructureVector ()[1]);
	properties_change = updateClasses (new_data->getStructureVector ()[2]);
	properties_change = updateMeta (new_data->getStructureVector ()[3]);
	properties_change = updateDimensions (new_data->getStructureVector ()[4]);

	if (properties_change) RKGlobals::tracker ()->objectMetaChanged (this);
	if (type & NeedDataUpdate) updateDataFromR (0);
	if (isPending ()) type -= Pending;

	return true;
}
Ejemplo n.º 4
0
ssize_t Socket::readLine(char *str, size_t request, timeout_t timeout)
{
    bool crlf = false;
    bool nl = false;
    size_t nleft = request - 1; // leave also space for terminator
    int nstat,c;

    if(request < 1)
        return 0;

    str[0] = 0;

    while(nleft && !nl) {
        if(timeout) {
            if(!isPending(pendingInput, timeout)) {
                error(errTimeout,(char *)"Read timeout", 0);
                return -1;
            }
        }
        nstat = ::recv(so, str, _IOLEN64 nleft, MSG_PEEK);
        if(nstat <= 0) {
            error(errInput,(char *)"Could not read from socket", socket_errno);
            return -1;
        }

        // FIXME: if unique char in buffer is '\r' return "\r"
        //        if buffer end in \r try to read another char?
        //        and if timeout ??
        //        remember last \r

        for(c=0; c < nstat; ++c) {
            if(str[c] == '\n') {
                if (c > 0 && str[c-1] == '\r')
                    crlf = true;
                ++c;
                nl = true;
                break;
            }
        }
        nstat = ::recv(so, str, _IOLEN64 c, 0);
        // TODO: correct ???
        if(nstat < 0)
            break;

        // adjust ending \r\n in \n
        if(crlf) {
            --nstat;
            str[nstat - 1] = '\n';
        }

        str += nstat;
        nleft -= nstat;
    }
    *str = 0;
    return (ssize_t)(request - nleft - 1);
}
Ejemplo n.º 5
0
int 
Socket::read(
            String& buff, 
            const int sz)
{
    if (m_status != STATUS_CONNECTED)
    {
        return -1;
    }

    std::auto_ptr<char> sockbuff(new char[ BUFF_SIZE + 1 ]);

    int totalRead = 0;
    int bytesToRead = sz;

    while ( isPending( SOCKPENDING_IN, TIMEOUT_READ ) && ( bytesToRead > 0 ) )
    {
        int readSize = bytesToRead > BUFF_SIZE ? BUFF_SIZE : bytesToRead;
#if defined(_WINDOWS) || defined(WIN32)
        int bytesRead = ::recv(m_sock, sockbuff.get(), readSize, 0);
#else
        int bytesRead = ::recv(m_sock, (void*)sockbuff.get(), readSize, 0);
#endif
        // couple of things can happen here.
        // 1.  bytesRead == readSize, all data was read
        // 2. bytesRead < 0, an error occurred - kill the connection
        // 3. bytesRead < readSize, not all data has arrived - keep trying to read
        // 4. bytesRead == 0, no data was read - same as #3
        if (bytesRead < 0)
        {
            String errStr = NTEXT("Socket::read: recv() failed, err:");
            errStr += StringUtils::toString( errno );
            DBG_LOGERR(errStr);
            m_status = STATUS_DISCONNECTED;
            return -1;
        }
        else if ( bytesRead == 0 )
        {
            // this happens when the other side has
            // performed an orderly shutdown
            m_status = STATUS_READ_SHUTDOWN;
            break;
        }
        else
        {
            sockbuff.get()[ bytesRead ] = '\0';

            buff += StringUtils::toString(sockbuff.get());
            totalRead += bytesRead;
            bytesToRead -= bytesRead;
        }
    }

    return totalRead;
}
Ejemplo n.º 6
0
ByteArray UDPInternalConnection::receiveImpl(unsigned long size)
{
  if (readyForRead() == 0) {

    if (!isPending())
      setPending();
    else
      throw netman::SockConnectionError("Already pending");

    std::unique_lock<std::mutex> lock(syncMutex);
    waitVar.wait(lock, [&] {return !isPending();});

    if (isTimedOut()) {
      setIdle();
      throw netman::SockRecieveFailed("Operation timeout");
    } else
      setIdle();
  }

  return readBuffer();
}
Ejemplo n.º 7
0
Archivo: View.cpp Proyecto: sajty/eris
void View::getEntityFromServer(const std::string& eid)
{
    if (isPending(eid)) return;
    
    // don't apply pending queue cap for anoynmous LOOKs
    if (!eid.empty() && (m_pending.size() >= m_maxPendingCount)) {
        m_lookQueue.push_back(eid);
        m_pending[eid] = SACTION_QUEUED;
        return;
    }
    
    sendLookAt(eid);
}
Ejemplo n.º 8
0
Archivo: View.cpp Proyecto: sajty/eris
void View::disappear(const std::string& eid)
{    
    Entity* ent = getEntity(eid);
    if (ent) {
        ent->setVisible(false); // will ultimately cause disapeparances
    } else {
        if (isPending(eid)) {
            //debug() << "got disappearance for pending " << eid;
            m_pending[eid] = SACTION_HIDE;
        } else
            warning() << "got disappear for unknown entity " << eid;
    }
}
Ejemplo n.º 9
0
// Return true if we successfully sent an ARP request, false otherwise
bool IPv4Handler::resolveMac(SwitchState* state, IPAddressV4 dest) {
  // need to find out our own IP and MAC addresses so that we can send the
  // ARP request out. Since the request will be broadcast, there is no need to
  // worry about which port to send the packet out.

  // TODO: assume vrf 0 now
  auto routeTable = state->getRouteTables()->getRouteTableIf(RouterID(0));
  if (!routeTable) {
    throw FbossError("No routing tables found");
  }

  auto route = routeTable->getRibV4()->longestMatch(dest);
  if (!route || !route->isResolved()) {
    // No way to reach dest
    return false;
  }

  auto intfs = state->getInterfaces();
  auto nhs = route->getForwardInfo().getNexthops();
  for (auto nh : nhs) {
    auto intf = intfs->getInterfaceIf(nh.intf);
    if (intf) {
      auto source = intf->getAddressToReach(nh.nexthop)->first.asV4();
      auto target = route->isConnected() ? dest : nh.nexthop.asV4();
      if (source == target) {
        // This packet is for us.  Don't send ARP requess for our own IP.
        continue;
      }

      auto vlanID = intf->getVlanID();
      auto vlan = state->getVlans()->getVlanIf(vlanID);
      if (vlan) {
        auto entry = vlan->getArpTable()->getEntryIf(target);
        if (entry == nullptr) {
          // No entry in ARP table, send ARP request
          auto mac = intf->getMac();
          ArpHandler::sendArpRequest(sw_, vlanID, mac, source, target);

          // Notify the updater that we sent an arp request
          sw_->getNeighborUpdater()->sentArpRequest(vlanID, target);
        } else {
          VLOG(4) << "not sending arp for " << target.str() << ", "
                  << ((entry->isPending()) ? "pending " : "")
                  << "entry already exists";
        }
      }
    }
  }

  return true;
}
Ejemplo n.º 10
0
/// \brief Add a teleport authentication entry
///
/// \param entity_id The ID of the entity whose data is to be removed
/// \param possess_key The possess key to authenticate the entity with
int TeleportAuthenticator::addTeleport(const std::string & entity_id,
                                       const std::string & possess_key)
{
    if (isPending(entity_id)) {
        return -1;
    }
    PendingTeleport * pt = new PendingTeleport(entity_id, possess_key);
    if (pt == 0) {
        return -1;
    }
    m_teleports.insert(std::make_pair(entity_id, pt));
    log(INFO, String::compose("Added teleport auth entry for %1,%2",
                              entity_id, possess_key));
    return 0;
}
Ejemplo n.º 11
0
void UDPInternalConnection::notifyReceive()
{
  auto packet = socket_->readDataFrom(); //data:address

  //if (packet.second == this->host_address_) {
  // Если мы получили данные от хоста, с которым работаем - читаем пакет
  // Иначе - отбрасываем как некорректный
  appendBuffer(packet.first);

  if (isPending()) {
    setIdle();
    waitVar.notify_one();
  }

  //}
}
Ejemplo n.º 12
0
ssize_t SampleSocketPort::DoSend(void *buf, size_t len)
{
	//If we are disconnecting, just pretend all the bytes were sent
	if(m_bDoDisconnect)
		return((ssize_t)len);

	ssize_t nSent = send(buf, len);
	while(!isPending(Socket::pendingOutput, 0))		//Wait for output to complete
	{
		if(m_bDoDisconnect || !m_bOpen)
		{
			//If we are disconnecting, just pretend all the bytes were sent
			return((ssize_t)len);
		}
		//I like to yield whenever waiting for things...
		//this is optional and may not suit your implementation!
		Thread::yield();
	}
	return(nSent);
}
Ejemplo n.º 13
0
int main(int argc, char *argv[])
{
	PolonetConn conn;
	char buffer[256];
	int bytesReceived;
	int returnValue = 1;
	
	/* Open the connection */
	if ((conn = openConnection(CONN_HOSTNAME, 80)))
	{
		/* Wait for the connection establishment.
		   If the connection is pending, wait 10 milliseconds */
		while (isPending(conn))
			usleep(10000);
		
		if (isConnected(conn))
		{
			/* Send the GET command */
			sendData(conn, getCommand, strlen(getCommand));
			
			/* Receive the response */
			while (bytesReceived = getData(conn, buffer, sizeof(buffer) - 1))
			{
				buffer[bytesReceived] = '\0';
				printf("%s", buffer);
			}
			
			/* Signal success */
			returnValue = 0;
		}
		else
			printf("Connection refused from " CONN_HOSTNAME ".\n");
		
		/* Always close an open connection! */
		closeConnection(conn);
	}
	else
		printf("Couldn't connect to " CONN_HOSTNAME ".\n");
	
	return returnValue;
}
Ejemplo n.º 14
0
Archivo: View.cpp Proyecto: sajty/eris
void View::deleteEntity(const std::string& eid)
{
    Entity* ent = getEntity(eid);
    if (ent) {
        // copy the child array, since setLocation will modify it
        EntityArray contents;
        for (unsigned int c=0; c < ent->numContained(); ++c) {
            contents.push_back(ent->getContained(c));
        }
        
        while (!contents.empty()) {
            Entity* child = contents.back();
            child->setLocation(ent->getLocation());
            
            WFMath::Point<3> newPos = ent->toLocationCoords(child->getPosition());
            WFMath::Quaternion newOrient = ent->getOrientation() * child->getOrientation();
            child->m_position = newPos;
            child->m_orientation = newOrient;
            
            contents.pop_back();
        }

        // force a disappear if one hasn't already happened
        ent->setVisible(false); // redundant?
        EntityDeleted.emit(ent);
        ent->shutdown();
		//Check if the deleted entity is the avatar one.
        bool avatarDeleted = ent == m_owner->getEntity();
        delete ent; // actually kill it off
        if (avatarDeleted) {
            AvatarEntityDeleted.emit();
        }
    } else {
        if (isPending(eid)) {
            //debug() << "got delete for pending entity, argh";
            m_pending[eid] = SACTION_DISCARD;
        } else
            warning() << "got delete for unknown entity " << eid;
    }
}
Ejemplo n.º 15
0
ssize_t Socket::readData(void *Target, size_t Size, char Separator, timeout_t timeout)
{
    if ((Separator == 0x0D) || (Separator == 0x0A))
        return (readLine ((char *) Target, Size, timeout));

    if (Size < 1)
        return (0);

    ssize_t nstat;

    if (Separator == 0) {       // Flat-out read for a number of bytes.
        if (timeout) {
            if (!isPending (pendingInput, timeout)) {
                error(errTimeout);
                return (-1);
            }
        }
        nstat =::recv (so, (char *)Target, _IOLEN64 Size, 0);

        if (nstat < 0) {
            error (errInput);
            return (-1);
        }
        return (nstat);
    }
    /////////////////////////////////////////////////////////////
    // Otherwise, we have a special char separator to use
    /////////////////////////////////////////////////////////////
    bool found = false;
    size_t nleft = Size;
    int c;
    char *str = (char *) Target;

    memset (str, 0, Size);

    while (nleft && !found) {
        if (timeout) {
            if (!isPending (pendingInput, timeout)) {
                error(errTimeout);
                return (-1);
            }
        }
        nstat =::recv (so, str, _IOLEN64 nleft, MSG_PEEK);
        if (nstat <= 0) {
            error (errInput);
            return (-1);
        }

        for (c = 0; (c < nstat) && !found; ++c) {
            if (str[c] == Separator)
                found = true;
        }

        memset (str, 0, nleft);
        nstat =::recv (so, str, c, 0);
        if (nstat < 0)
            break;

        str += nstat;
        nleft -= nstat;
    }
    return (ssize_t)(Size - (ssize_t) nleft);
}