void CHyperFeedStructureProviderEx::OnResponse(CResponseBasePtr pResponse)
{
	switch(pResponse->m_enType)
	{
	case _enResponseStock:
		{
			CStockResultExResponse* pStockResponse = dynamic_cast<CStockResultExResponse*>(pResponse.get());
			if(pStockResponse)
				OnStock(pStockResponse->m_vtParams, pStockResponse->m_vtResult);
		}
		break;
	case _enResponseOption:
		{
			COptionResultExResponse* pOptionResponse = dynamic_cast<COptionResultExResponse*>(pResponse.get());
			if(pOptionResponse)
				OnOption(pOptionResponse->m_vtParams, pOptionResponse->m_vtResult, CComVariant(pOptionResponse->m_bIsLast));
		}
		break;
	case _enResponseFuture:
		{
			CFutureResultExResponse* pFutureResponse = dynamic_cast<CFutureResultExResponse*>(pResponse.get());
			if(pFutureResponse)
				OnFuture(pFutureResponse->m_vtParams, pFutureResponse->m_vtResult);
		}
		break;
	case _enResponseFutures:
		{
			CFuturesResultExResponse* pFuturesResponse = dynamic_cast<CFuturesResultExResponse*>(pResponse.get());
			if(pFuturesResponse)
				OnFutureByRoot(pFuturesResponse->m_vtParams, pFuturesResponse->m_vtResult, CComVariant(pFuturesResponse->m_bIsLast));
		}
		break;
	case _enResponseFuturesOption:
		{
			CFutureOptionResultExResponse* pFutureOptionResponse = dynamic_cast<CFutureOptionResultExResponse*>(pResponse.get());
			if(pFutureOptionResponse)
				OnFuturesOption(pFutureOptionResponse->m_vtParams, pFutureOptionResponse->m_vtResult, CComVariant(pFutureOptionResponse->m_bIsLast));
		}
		break;
	}
}
void CHyperFeedStructureInfo::OnResponse(CResponseBasePtr pResponse)
{
	
	switch(pResponse->m_enType)
	{
	case _enResponseStock:
		{
			CStockInfoResponse* pStockResponse = dynamic_cast<CStockInfoResponse*>(pResponse.get());
			if(pStockResponse)
				OnStock(pStockResponse->m_vtParams, pStockResponse->m_vtInfo);
		}
		break;
	case _enResponseOption:
		{
			COptionInfoResponse* pOptionResponse = dynamic_cast<COptionInfoResponse*>(pResponse.get());
			if(pOptionResponse)
				OnOption(pOptionResponse->m_vtParams, pOptionResponse->m_vtInfo, CComVariant(pOptionResponse->m_bIsLast));
		}
		break;
	}
}
示例#3
0
文件: socket.cpp 项目: wdgrusse/Aspen
bool Socket::Read()
{
    char temp[4096 + 2];
    int size = 0;
    int k = 0;
    int buflen = 0;
    size_t nlpos = 0;
    char option = '\0';
    std::string line;

    while (true)
        {
            size = recv(_control, temp, 4096, 0);
            if (size <= 0)
                {
                    break;
                }
            /*
                  else if (errno == EAGAIN || size == 4096)
                    {
                      break;
                    }
            */
//we have something to read
            _totalReceived += size; //add the number of bytes received to the counter.
            temp[size] = '\0'; //sets the last byte we received to null.
//iterate through the list and add each command to the input string.
//also parse out telnet sequences.
            for (k=0; k<size; k++)
                {
                    if (temp[k] == TELNET_IAC)
                        {
                            //handle telnet sequence
                            k++; //move k to the option/command
                            if (k < size && temp[k] == TELNET_IAC)
                                {
                                    //check for iac iac
                                    _inBuffer += temp[k];
                                    continue;
                                }
                            if (temp[k] == TELNET_SB)
                                {
                                    //subnegotiation
                                    k++;
                                    if (k+1 >= size) //malformed sequence
                                        {
//bail out of read.
                                            return true;
                                        }
                                    option = temp[k];
                                    buflen = 0;
                                    k++;
                                    for (; k<size; ++k, ++buflen)
                                        {
                                            if (temp[k] == TELNET_SE)
                                                {
//                                                    k += 2; //move it past the sb, iac and to the char after.
                                                    break;
                                                }
                                        } //finding the end of subneg.
                                    char *subneg = new char[buflen];
                                    memcpy(subneg, temp+(k-2-buflen), buflen);
                                    OnNegotiation(option, subneg, buflen);
                                    delete []subneg;
                                    continue;
                                }
                            if (temp[k] == TELNET_DO || temp[k] == TELNET_DONT || temp[k] == TELNET_WILL || temp[k] == TELNET_WONT)
                                {
                                    //check for options
                                    k++;
                                    if (k >= size) //make sure the buffer actually has the right amount of data
                                        {
                                            return true;
                                        }
                                    OnOption(temp[k-1], temp[k]);
                                    continue;
                                } //option
                            else
                                {
                                    //command provided
                                    OnCommand(temp[k]);
                                    continue;
                                } //command
                        } //check for IAC
                    _inBuffer+=temp[k];
                } //end iteration of buffer
//check for a newline character.
            nlpos = _inBuffer.find_first_of("\r\n");
            if (nlpos != std::string::npos)
                {
                    line=_inBuffer.substr(0, nlpos);
//we have a newline, push it to our command queue.
                    if (line.length())
                        {
                            _cqueue.push(line);
                        }
                    _inBuffer.clear();
                    break;
                }
        }
    return true;
}