• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: UDP Rate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UDP Rate


  • Subject: Re: UDP Rate
  • From: Eric Lengyel <email@hidden>
  • Date: Sat, 21 Feb 2004 16:16:25 -0800

Hi --

2. Is the udp mtu in OS X 8192 bytes? I can't seem to send 16384 byte
packets, or even 16000 bytes. And I thought the mtu for ethernet was 64k.

You'll be limited by lower-level MTUs -- Ethernet pins you at 1500 bytes per packet. I personally keep packets below ~500 bytes because bigger packets invite a higher loss rate.

4. Is there any benefit to threaded sockets? I am going to be calling
Idle() at least 30 fps in my game's loop, so I can't see how it would go
faster. I was thinking of making a thread with select() that only runs when
data comes in, or I would signal the thread to run by sending data to it on
a local socket (is this a pipe???). My code is about 90% interrupt safe, as
I was writing it to run on 9 too, but if I can avoid threads/interrupts,
that would be great as they are an evil icky can of disgusting worms.

You absolutely want to run your socket code in a separate thread. I think the select() function is horribly designed, but you can hack it to work more like the WSAEventSelect() function in Windows. What you do is block forever in a select() call that is waiting on a socket and a pipe that you create in your main thread. The pipe is used only to signal that the thread should exit (just write a byte to it when you shut down to wake up the socket thread). When you receive data on the socket, you're able to respond to it immediately (for instance, to send an acknowledgement) instead of having to wait for your main event loop to cycle through.

Below is the actual code that I use in my socket thread.

-- Eric Lengyel


// The thread's entry-point:
void NetworkSocket::SocketThread(const Thread *thread, void *data)
{
NetworkSocket *networkSocket = static_cast<NetworkSocket *>(data);

fd_set readSet;
fd_set writeSet;

networkSocket->sendBlocked = false;

FD_ZERO(&readSet);
FD_ZERO(&writeSet);

int socketDesc = networkSocket->socketDesc;
int pipeDesc = networkSocket->pipeDesc[0]; // Read end of pipe

int num = Max(socketDesc, pipeDesc) + 1;
for (;;)
{
// Add file descriptors for the socket and read end of the pipe
FD_SET(socketDesc, &readSet);
FD_SET(pipeDesc, &readSet);

fd_set *ws = NULL;
if (networkSocket->sendBlocked)
{
// A previous send operation would have blocked,
// so listen for write availability too.
networkSocket->sendBlocked = false;
FD_SET(socketDesc, &writeSet);
ws = &writeSet;
}

// Wait forever
select(num, &readSet, ws, NULL, NULL);
if (FD_ISSET(pipeDesc, &readSet)) break; // Pipe got written to -- exit thread

if (FD_ISSET(socketDesc, &readSet)) networkSocket->ReceivePackets();
if ((ws) && (FD_ISSET(socketDesc, ws))) networkSocket->SendPackets();
}
}
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.
References: 
 >UDP Rate (From: Zack Morris <email@hidden>)

  • Prev by Date: Re: UDP Rate
  • Next by Date: Re: UDP Rate
  • Previous by thread: Re: UDP Rate
  • Next by thread: Re: UDP Rate
  • Index(es):
    • Date
    • Thread