Exemple #1
0
  void passPacket(const SOCKADDR& sender, Util::MemoryFrame packet)
  {
    INTERLOCKED;
    GamePacket gamePacket;
    memcpy(gamePacket.data, packet.begin(), packet.size());
    gamePacket.packetSize = packet.size();
    gamePacket.sender = sender;
    gamePacket.timeStamp = GetTickCount();

    incomingGamePackets.push(gamePacket);

    SetEvent(receiveEvent);
  }
void UDPSocket::sendPacket(const UDPAddr &target, Util::MemoryFrame data)
{
  int success = ::sendto(_s, (char*)data.begin(), data.size(), NULL, (sockaddr*)&target, sizeof(sockaddr_in));
  if(success == SOCKET_ERROR)
  {
    throw GeneralException("::send failed");
  }
}
Exemple #3
0
  void LocalPC::sendAsyn(const int& him, Util::MemoryFrame packet)
  {
    processIncomingPackets();

    if(!shd->peer[him].isOccupied())
      return;

    INTERLOCKED;
    // push the packet on target's packetqueue
    PeerData &peerData = shd->peer[him];
    int slotIndex = peerData.incomingCount++;
    if(slotIndex >= 16)
    {
      DropMessage(1, "stacked 16 packets, no space");
      return;
    }
    if(packet.size() > 508)
    {
      DropMessage(1, "packet bigger than 508 bytes (%d), being cut", packet.size());
    }
    Util::MemoryFrame::from(peerData.incoming[slotIndex].data).write(packet);
    peerData.incoming[slotIndex].length = packet.size();
    peerData.incoming[slotIndex].sender = self;
  }
Util::MemoryFrame UDPSocket::receivePacket(UDPAddr &target, Util::MemoryFrame dest)
{
  //int targetSize = sizeof(target);
  _state = 0;
  int fromlen = sizeof(sockaddr);
  int byteCount = ::recvfrom(_s, (char*)dest.begin(), dest.size(), NULL, (sockaddr*)&target, &fromlen);
  if(byteCount == SOCKET_ERROR)
  {
    _state = WSAGetLastError();
    if( _state == WSAEWOULDBLOCK
      ||_state == WSAECONNRESET)
      return Util::MemoryFrame();
    throw GeneralException("::recv failed");
  }
  return dest.getSubFrame(0, byteCount);
}