Guest User

Untitled

a guest
Jan 22nd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. private void Connect(Socket socket)
  2. {
  3. // Try to acquire a slot for our client
  4.  
  5. #if x86
  6. int handle = socket.Handle.ToInt32();
  7. #elif x64
  8. long handle = socket.Handle.ToInt64();
  9. handle = unchecked((int)((handle << 32) ^ (handle >> 32)));
  10. #endif
  11. short id;
  12. bool failure = true;
  13. for (id = unchecked((short)(((handle << 16) ^ (handle >> 16)) % this.clients.Length)); id < this.clients.Length; id++)
  14. {
  15. if (Interlocked.CompareExchange(ref this.clients[id].Socket, socket, null) == null)
  16. {
  17. failure = false;
  18. break;
  19. }
  20. }
  21.  
  22. if (failure)
  23. {
  24. // Exceptional condition
  25. // We incorrectly assumed there was a slot available
  26.  
  27. throw new InvalidOperationException("Server.Connect relies on client slot resource availability.");
  28. }
  29.  
  30. // Prepare our client and begin receiving and processing
  31. }
Add Comment
Please, Sign In to add comment