Logo Search packages:      
Sourcecode: egoboo version File versions  Download package

int enet_peer_send ( ENetPeer peer,
enet_uint8  channelID,
ENetPacket packet 
)

Queues a packet to be sent.

Parameters:
peer destination for the packet
channelID channel on which to send
packet packet to send
Return values:
0 on success
< 0 on failure

Definition at line 102 of file peer.c.

Referenced by enet_host_broadcast().

{
   ENetChannel * channel = & peer -> channels [channelID];
   ENetProtocol command;
   size_t fragmentLength;

   if (peer -> state != ENET_PEER_STATE_CONNECTED)
     return -1;

   fragmentLength = peer -> mtu - sizeof (ENetProtocolHeader) - sizeof (ENetProtocolSendFragment);

   if (packet -> dataLength > fragmentLength)
   {
      enet_uint32 fragmentCount = ENET_HOST_TO_NET_32 ((packet -> dataLength + fragmentLength - 1) / fragmentLength),
             startSequenceNumber = ENET_HOST_TO_NET_32 (channel -> outgoingReliableSequenceNumber + 1),
             fragmentNumber,
             fragmentOffset;

      packet -> flags |= ENET_PACKET_FLAG_RELIABLE;

      for (fragmentNumber = 0,
             fragmentOffset = 0;
           fragmentOffset < packet -> dataLength;
           ++ fragmentNumber,
             fragmentOffset += fragmentLength)
      {
         command.header.command = ENET_PROTOCOL_COMMAND_SEND_FRAGMENT;
         command.header.channelID = channelID;
         command.header.flags = ENET_PROTOCOL_FLAG_ACKNOWLEDGE;
         command.header.commandLength = sizeof (ENetProtocolSendFragment);
         command.sendFragment.startSequenceNumber = startSequenceNumber;
         command.sendFragment.fragmentCount = fragmentCount;
         command.sendFragment.fragmentNumber = ENET_HOST_TO_NET_32 (fragmentNumber);
         command.sendFragment.totalLength = ENET_HOST_TO_NET_32 (packet -> dataLength);
         command.sendFragment.fragmentOffset = ENET_NET_TO_HOST_32 (fragmentOffset);

         if (packet -> dataLength - fragmentOffset < fragmentLength)
           fragmentLength = packet -> dataLength - fragmentOffset;

         enet_peer_queue_outgoing_command (peer, & command, packet, fragmentOffset, fragmentLength);
      }

      return 0;
   }

   command.header.channelID = channelID;

   if (packet -> flags & ENET_PACKET_FLAG_RELIABLE)
   {
      command.header.command = ENET_PROTOCOL_COMMAND_SEND_RELIABLE;
      command.header.flags = ENET_PROTOCOL_FLAG_ACKNOWLEDGE;
      command.header.commandLength = sizeof (ENetProtocolSendReliable);
   }
   else
   {
      command.header.command = ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE;
      command.header.flags = 0;
      command.header.commandLength = sizeof (ENetProtocolSendUnreliable);
      command.sendUnreliable.unreliableSequenceNumber = ENET_HOST_TO_NET_32 (channel -> outgoingUnreliableSequenceNumber + 1);
   }

   enet_peer_queue_outgoing_command (peer, & command, packet, 0, packet -> dataLength);

   return 0;
}


Generated by  Doxygen 1.6.0   Back to index