//要得到返回值 to do....
int JtEventServer::DoInSync(AsyncEvent Event)
{
	int res = -1;
	if(IsInThread())
	{
		res = Event.m_Functor(Event.m_Cmd,Event.m_Seq);
	}
	else
	{
		if(1)///////////////??????????????????????????  z在那个线程循环时才发的??????to do。。。。。
		{
			//  1.先添加把异步Affair的同步成员初始完毕
			ST_AFFAIR_CALLBACK AffairCallBack((long)this,NULL,NULL,-1);
			tr1::shared_ptr<CCachedAffair> pCachedAffairItem(new CCachedAffair(&AffairCallBack));
			unsigned long long AffairId = CCachedAffairMap::Static_PushNewAffair_Pre(m_cachedMap, m_Lock
				, pCachedAffairItem, Event.m_Seq, Event.m_Cmd, Event.m_Cmd);

			ExCommand Head;
			Head.nSrcType				= 0;
			Head.nCmdType				= Event.m_Cmd;
			Head.nCmdSeq				= Event.m_Seq;
			Head.nContentSize			= 0;
			
			{
				//lock....
				JtMutexAutoLock L(m_EventLock);
				m_AsynEventS.push_back(Event);
			}

			if(!InHandling)
			{
				res = pEventPairPipe->SendCmd((const char*)&Head, sizeof(Head));
				if(res)
				{
					CCachedAffairMap::Static_CancelAffair_Pre(m_cachedMap, m_Lock, Event.m_Seq);
					jtprintf("[%s]Static_CancelAffair_Pre--------------------------------------\n", __FUNCTION__);
					return res;
				}
			}

			// 2.等待该同步事件 
			if(AffairCallBack.m_pOnGotData==NULL)
			{
				res = CCachedAffairMap::Static_PushNewAffair(m_cachedMap, m_Lock
					, pCachedAffairItem, Event.m_Seq);
			}
		}
	}

	if(res)
		jtprintf("[%s]res-------------------%d-------------------\n", __FUNCTION__, res);
	
	return res;
}
int CTCPSocketAsync::Send(const char *pBuffer,
						  unsigned long ulBufferLength)
{
	try
	{
		//Reset the event
		ResetEvent();

		//Send the data
		int iResult;
		iResult=SendNoAdd(pBuffer,
						  ulBufferLength);

		//Did we succeed ?
		if (iResult==GetErrorCode())
			//Is it blocked send ?
			if (WSAGetLastError()==WSAEWOULDBLOCK)
				if (GetBlockedBuffer())
				{
					//Add to the buffer, if we have one
					GetBlockedBuffer()->AddRecord(CBlockedBuffer::CBlockedData(pBuffer,
																			   ulBufferLength));

					//We have not error
					iResult=0;
				}
				else if (IsBlockSend())
					//Are we in the same thread?
					if (!IsInThread())
						if (WaitForBlockEvent())
						{
							//Set the error
							::SetLastError(WSAENOTCONN);

							//Exit
							return GetErrorCode();
						}
						else
							//Retry to send
							return Send(pBuffer,
										ulBufferLength);
					else
					{
						//We'll have to do a loop
						Sleep(10);

						//Try again
						if (SendNoAdd(pBuffer,
									  ulBufferLength)==GetErrorCode())
							//Which error
							if (WSAGetLastError()==WSAEWOULDBLOCK)
								return 0;
							else
								return GetErrorCode();
					}
				//Blocking error (not really an error)
				else
					return 0;
			else
				//Set the error code
				SetLastError("Send");

		//Done
		return iResult;
	}
	ERROR_HANDLER_RETURN("Send",GetErrorCode())
}