private void beginAcceptCallback_forStartListening(IAsyncResult result) { Console.WriteLine("TransportLayerCommunicator::beginAcceptCallback_forStartListening ENTER"); SocketUtility.SocketListener.SocketListenState socketListenState = (SocketUtility.SocketListener.SocketListenState) result.AsyncState; // Signal the listener thread to continue. socketListenState.allDone.Set(); Socket listener = socketListenState.sock; Socket handler = listener.EndAccept(result); TransportLayerCommunicator transportLayerCommunicator = (TransportLayerCommunicator)(socketListenState.obj); SockMsgQueue sockMsgQueue = new SockMsgQueue(handler, transportLayerCommunicator ); IPAddress IP = ((IPEndPoint)(handler.RemoteEndPoint)).Address; SocketState socketState = new SocketState(); socketState.transportLayerCommunicator = transportLayerCommunicator; try { transportLayerCommunicator.commRegistry.Add(IP, sockMsgQueue); socketState.sock = handler; handler.BeginReceive( socketState.buffer, 0, socketState.buffer.Length, new SocketFlags(), new AsyncCallback(beginReceiveCallBack), socketState); Console.WriteLine("TransportLayerCommunicator::beginAcceptCallback_forStartListening EXIT"); } catch(System.ArgumentException) { socketState.sock = handler; handler.BeginReceive( socketState.buffer, 0, socketState.buffer.Length, new SocketFlags(), new AsyncCallback(beginReceiveCallBack), socketState); Console.WriteLine("TransportLayerCommunicator::beginAcceptCallback_forStartListening EXIT"); } Console.WriteLine("TransportLayerCommunicator::beginAcceptCallback_forStartListening EXIT"); }
private void addToSockMsgQueue(IPAddress IP, byte[] buffer, int offset, int size, Guid clientGuid, AsyncCallback callBack, Object appState, CallType callType) { Console.WriteLine("TransportLayerCommunicator::addToSockMsgQueue ENTER"); Console.Write("TransportLayerCommunicator::DEEPCHK overlayRegistry count = "); Console.WriteLine(overlayRegistry.Count); Msg msg = new Msg(buffer, offset, size, clientGuid, callBack, appState, callType); SockMsgQueue sockMsgQueue; if(commRegistry.TryGetValue(IP, out sockMsgQueue)) sockMsgQueue.enqueue(msg); else { sockMsgQueue = new SockMsgQueue(IP, this); sockMsgQueue.enqueue(msg); try { commRegistry.Add(IP, sockMsgQueue); } catch(System.ArgumentException) { //this will take care of the situation where multiple //threads try to add a new enrty to the registry with //the same IP address if(commRegistry.TryGetValue(IP, out sockMsgQueue)) sockMsgQueue.enqueue(msg); else addToSockMsgQueue(IP, buffer, offset, size, clientGuid, callBack, appState, callType); } } Console.Write("TransportLayerCommunicator::DEEPCHK overlayRegistry count = "); Console.WriteLine(overlayRegistry.Count); Console.WriteLine("TransportLayerCommunicator::addToSockMsgQueue EXIT"); }