EngineClient::EngineClient( ds::App& app, const ds::cfg::Settings& settings, ds::EngineData& ed, const ds::RootList& roots) : inherited(app, settings, ed, roots) , mLoadImageService(*this, mIpFunctions) , mRenderTextService(mRenderTextThread) , mSender(mSendConnection) , mReceiver(mReceiveConnection) , mBlobReader(mReceiver.getData(), *this) , mSessionId(0) , mConnectionRenewed(false) , mServerFrame(-1) , mState(nullptr) , mIoInfo(*this) { // NOTE: Must be EXACTLY the same items as in EngineServer, in same order, // so that the BLOB ids match. HEADER_BLOB = mBlobRegistry.add([this](BlobReader& r) {receiveHeader(r.mDataBuffer);}); COMMAND_BLOB = mBlobRegistry.add([this](BlobReader& r) {receiveCommand(r.mDataBuffer);}); DELETE_SPRITE_BLOB = mBlobRegistry.add([this](BlobReader& r) {receiveDeleteSprite(r.mDataBuffer);}); CLIENT_STATUS_BLOB = mBlobRegistry.add([this](BlobReader& r) {receiveClientStatus(r.mDataBuffer); }); CLIENT_INPUT_BLOB = mBlobRegistry.add([this](BlobReader& r) {receiveClientInput(r.mDataBuffer); }); mReceiver.setHeaderAndCommandIds(HEADER_BLOB, COMMAND_BLOB); try { if (settings.getBool("server:connect", 0, true)) { mSendConnection.initialize(true, settings.getText("server:ip"), ds::value_to_string(settings.getInt("server:listen_port"))); mReceiveConnection.initialize(false, settings.getText("server:ip"), ds::value_to_string(settings.getInt("server:send_port"))); } } catch(std::exception &e) { DS_LOG_ERROR_M("EngineClient::EngineClient() initializing UDP: " << e.what(), ds::ENGINE_LOG); } setState(mClientStartedState); }
/* client function that performs the list method */ int clientList(int sock) { if(!sendHeader(0,0,0, sock)) fatal_error("send header has failed\n"); header *rcvHead= receiveHeader(sock); if(!rcvHead) fatal_error("error receiving rcv header\n"); if(!rcvHead->indexes&&!rcvHead->length) { free(rcvHead); fprintf(stderr,"There are no songs on the server.\n\n"); return 1; } song *songs=recvSongArray(rcvHead->indexes,sock); if(!songs) fatal_error("error receiving song array\n"); fprintf(stderr,"Songs on the server are:\n"); int i; for(i=0;i<rcvHead->indexes;i++) { fprintf(stderr,"%s\n",songs[i].title); } fprintf(stderr,"\n"); free((void*)rcvHead); free((void*)songs); return 1; }
/* client function that performs the pull method */ int clientPull(int sock) { int numSongs=numSongsInDir(); if(numSongs) { if(!sendHeader(2, numSongs*sizeof(song), numSongs, sock)) fatal_error("send header has failed\n"); song *songs=createSongArray(numSongs); if(!songs) fatal_error("creating song array failed\n"); if(sendSongArray(songs,numSongs,sock)!=sizeof(song)*numSongs) fatal_error("sending song array failed\n"); free(songs); } else { if(!sendHeader(2, 0, 0, sock)) fatal_error("send header has failed\n"); } header *rcvHead= receiveHeader(sock); if(!rcvHead) fatal_error("error receiving rcv header\n"); if(!rcvHead->indexes) { fprintf(stderr,"You have all the songs that are on the server.\n\n"); } else { song *rcvSongs=recvSongArray(rcvHead->indexes,sock); if(!rcvSongs) fatal_error("error receiving song array\n"); fprintf(stderr, "The following songs have been added to your directory:\n"); int i; for(i=0;i<rcvHead->indexes;i++) { FILE *file = fopen(rcvSongs[i].title,"w+"); if(!receiveFile(file, rcvSongs[i].lenOfSong, sock)) fatal_error("receive file failed\n"); fclose(file); fprintf(stderr, "%s\n",rcvSongs[i].title); } fprintf(stderr,"\n"); free(rcvSongs); } free(rcvHead); return 1; }
void processPage(int sockfd, t_Buffer* document) { char *pos = document->ptr; char query_get[1024] = {0}; char qid[22] = {0}; t_Buffer *header_q = t_Buffer_new(1024); t_Buffer *document_q = t_Buffer_new(1024); srand(1200); // Busca URL de una pregunta de la página while ( (pos = strstr(pos, SEARCH_QUESTION_TOKEN )) ) { // Identifica el qid pos = strstr(pos, SEARCH_QID_TOKEN ); memcpy(qid, pos+5, 21); sprintf( query_get,\ "GET %s%s%s HTTP/%s\r\nHost: %s\r\nUser-Agent: Mozilla Firefox 11.0 \r\n\r\n",\ SEARCH_QUESTION_TOKEN, SEARCH_QID_TOKEN, qid,\ "1.1", HOST); // Enviar if ( send(sockfd, query_get, strlen(query_get), 0) < 0 ) { perror("send()"); exit(EXIT_FAILURE); } receiveHeader(sockfd, header_q); receiveContent(sockfd, document_q, TE_CHUNKED); if ( strstr(document_q->ptr, SEARCH_USER) ) printf("http://%s%s%s%s\n", HOST,SEARCH_QUESTION_TOKEN, SEARCH_QID_TOKEN,qid); sleep(rand() % 3); } printf("\n"); // Liberar recursos t_Buffer_delete(header_q); t_Buffer_delete(document_q); }
/* client function that performs the leave method */ int clientLeave(int sock) { if(!sendHeader(3,0,0, sock)) fatal_error("send header has failed\n"); header *rcvHead= receiveHeader(sock); if(!rcvHead) fatal_error("error receiving rcv header\n"); if(rcvHead->method!=3) fatal_error("leave did not work\n"); free(rcvHead); return 1; }
Message* MessageListener::listen(int socketfd) { int length; int type; receiveHeader(socketfd, &length, &type); char* msgData = (char*)malloc(length); if(receiveExactBytes(socketfd, msgData, length) != length) handle_error("recv"); Message* message = new Message(type, msgData, length); return message; }
/** * This function is used to receive an Acknowledge of an I frame * */ void receiveAcknowledge(struct file *filp) { respData_t *header=NULL; short rPcb = 0; short rLen = 0; int len = 1; unsigned char *cs=NULL; NFC_DBG_MSG(KERN_INFO "receiveAcknowledge - Enter\n"); cs = gRecvBuff; header =(respData_t *) receiveHeader(filp); rPcb = (header->data[0] & 0xFF); rLen = (header->data[1] & 0xFF); receiveAndCheckChecksum(filp,rPcb, rLen, cs,len); NFC_DBG_MSG(KERN_ALERT "receiveAcknowledge - Exit\n"); }
bool ReliableConduit::messageWaiting() { switch (state) { case HOLDING: // We've already read the message and are waiting // for a receive call. return true; case RECEIVING: if (! ok()) { return false; } // We're currently receiving the message. Read a little more. receiveIntoBuffer(); if (messageSize == receiveBufferUsedSize) { // We've read the whole mesage. Switch to holding state // and return true. state = HOLDING; return true; } else { // There are more bytes left to read. We'll read them on // the next call. Because the *entire* message is not ready, // return false. return false; } break; case NO_MESSAGE: if (Conduit::messageWaiting()) { // Message incoming. Read the header. state = RECEIVING; receiveHeader(); // Loop back around now that we're in the receive state; we // may be able to read the whole message before returning // to the caller. return messageWaiting(); } else { // No message incoming. return false; } } debugAssertM(false, "Should not reach this point"); return false; }
void ClientConnection::connect(std::string host, std::string username) { this->host = host; this->username = username; auto endpoint_iterator = resolver.resolve({this->host, std::to_string(GameState::tcpPort)}); async_connect(socket, endpoint_iterator, [&](boost::system::error_code ec, ip::tcp::resolver::iterator it) { std::cout << "Managed to connect to " << this->host << std::endl; auto mh = MessageHeader{ MessageType::CONNECT, this->username.length()+1 }; std::vector<uint8_t> sendBuffer; sendBuffer.resize( sizeof(MessageHeader) + mh.size ); memcpy(sendBuffer.data(), &mh, sizeof(MessageHeader)); memcpy(sendBuffer.data() + sizeof(MessageHeader), this->username.data(), mh.size); send(sendBuffer); receiveHeader(); }); }
void CDStarRepeaterRXThread::receiveModem() { for (;;) { DSMT_TYPE type = m_modem->read(); if (type == DSMTT_NONE) return; switch (m_rxState) { case DSRXS_LISTENING: if (type == DSMTT_HEADER) { CHeaderData* header = m_modem->readHeader(); receiveHeader(header); } else if (type == DSMTT_DATA) { unsigned char data[20U]; unsigned int length = m_modem->readData(data, 20U); setRadioState(DSRXS_PROCESS_SLOW_DATA); receiveSlowData(data, length); } break; case DSRXS_PROCESS_SLOW_DATA: if (type == DSMTT_DATA) { unsigned char data[20U]; unsigned int length = m_modem->readData(data, 20U); receiveSlowData(data, length); } else if (type == DSMTT_EOT || type == DSMTT_LOST) { setRadioState(DSRXS_LISTENING); } break; case DSRXS_PROCESS_DATA: if (type == DSMTT_DATA) { unsigned char data[20U]; unsigned int length = m_modem->readData(data, 20U); receiveRadioData(data, length); } else if (type == DSMTT_EOT || type == DSMTT_LOST) { unsigned char data[20U]; ::memcpy(data, END_PATTERN_BYTES, DV_FRAME_LENGTH_BYTES); processRadioFrame(data, FRAME_END); setRadioState(DSRXS_LISTENING); endOfRadioData(); } break; } } }
void NodeVersionLoader::sendHeader() { auto self = shared_from_this(); checkThread(); auto& item = currentDownloadItem(); state = State::SendingHeader; PacketGenerator gen; gen.write(VersionDownloadRequestMagic); gen.writeString(item.version); auto buf = std::make_shared<std::vector<char>>(std::move(gen.vector())); timer.expires_from_now(boost::posix_time::seconds(8)); timer.async_wait([this, self] (const error_code& error) { if (error) { return; } if (disposed) { return; } if (state == State::SendingHeader) { BOOST_LOG_SEV(log, LogLevel::Warn) << "Timed out."; socket.cancel(); } }); asio::async_write(socket, asio::buffer(buf->data(), buf->size()), [this, self, &item](const error_code& error, std::size_t) { checkThread(); if (disposed) { downloadCancelled(); return; } if (error) { downloadFailed(error.message()); return; } timer.cancel(); receiveHeader(); }); }
/************************************************************************************** * Abwicklung eines neuen Clients * - dynamische Erstellung der benutzten Datenstrukturen * 1 Anfrage vom Client erhalten (HEADER) * 2 Parameter extrahieren * 3 Neuen Socket erstellen * 4 Neue Adresse Richtung ausgesuchter IP erstellen * 5 Verbindung zu IP herstellen * 7 Empfangenen HEADER an IP schicken * 8 Antwort von IP empfangen * 9 Antwort an Client schicken */ void* handleClient(void* pTP){ #ifdef _DEBUG fprintf(stderr,"++ handleclient\n"); #endif /////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^ int sProxyWeb = ~0; struct sockaddr_in saProxyAddress; struct threadParam *pThreadParam=(struct threadParam*)pTP; /* Dynamische Bereitstellung des benötigten Speichers */ struct urlPar *pUrlPar = (struct urlPar*) malloc(sizeof(struct urlPar)); struct netStream *pWebBuf = (struct netStream*)malloc(sizeof(struct netStream)); struct netStream *pClientBuf = (struct netStream*)malloc(sizeof(struct netStream)); struct netStream *pErrBuf = (struct netStream*)malloc(sizeof(struct netStream)); /////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^ if (receiveHeader (pClientBuf ,pThreadParam->socketID)) if (fillParFromBuf (pUrlPar ,pClientBuf->pBuf)) if (createSocket (&sProxyWeb)) if (generateWebAddress (&saProxyAddress ,pUrlPar)) if (connectSocket (sProxyWeb ,&saProxyAddress)) if (sendBuffer (sProxyWeb ,pClientBuf)) if (receiveBuffer (pWebBuf ,sProxyWeb)) if (sendBuffer (pThreadParam->socketID ,pWebBuf)); #ifdef _DEBUG fprintf(stderr,"HC - END\n"); #endif close(pThreadParam->socketID); close(sProxyWeb); free(pClientBuf->pBuf); free(pClientBuf); free(pThreadParam); free(pWebBuf->pBuf); free(pWebBuf); free(pUrlPar); #ifdef _DEBUG fprintf(stderr,"-- handleclient\n"); #endif //return NULL; }
bool ClientHandler::acceptFile(IMessage *msg, Socket& socket_) { string filepath = "MockChannel/Root/DownloadDirectory/"; std::ofstream outfile(filepath + msg->getValue(), ios::binary); size_t BufLen = 1024; Socket::byte buffer[1024]; BufLen = stoi(msg->getContentLength()); bool ok; if (socket_.bytesWaiting() == 0) { return false; } while (true) { ok = socket_.recv(BufLen, buffer); if (socket_ == INVALID_SOCKET || !ok) return false; outfile.write(buffer, BufLen); if (BufLen < 1024) { outfile.close(); //recvr->postMessage(msg); return true; } else if (socket_.bytesWaiting() != 0) { msg = receiveHeader(socket_); BufLen = stoi(msg->getContentLength()); } else { //recvr->postMessage(msg); return true; } } return false; }
void ClientHandler::operator()(Socket& socket_) { try { IMessage *msg = receiveHeader(socket_); if (msg->getCommand() == "send_string") Verbose::show("\nString received: " + msg->getValue() + "\n"); else if (msg->getCommand() == "file_upload") { using HighResolutionClock = chrono::high_resolution_clock; HighResolutionClock::time_point t1 = HighResolutionClock::now(); if (acceptFile(msg, socket_)) { } else Verbose::show("\nFile Upload Failed!\n"); HighResolutionClock::time_point t2 = HighResolutionClock::now(); auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count(); msg->setTime(to_string(duration)); } else if (msg->getCommand() == "ack") { string s = "\n Reply from " + msg->getSendIP() + msg->getSendPort(); s += ": " + msg->getValue() + " uploaded successfully!\n"; Verbose::show(s); } else //(msg->getCommand() == "ack_get_dir") { receiveBody(socket_,msg); } recvr->postMessage(msg); } catch (std::exception& ex) { Verbose::show(" Exception caught:", always); Verbose::show(std::string("\n ") + ex.what() + "\n\n"); } socket_.shutDown(); socket_.close(); }
void ClientConnection::receiveHeader() { if (recBuffer.size() == 0) { recTotal = sizeof(MessageHeader); recBytes = 0; recBuffer.resize(recTotal); } socket.async_receive(buffer(recBuffer.data() + recBytes, (recTotal - recBytes)), [&](boost::system::error_code ec, size_t size) { recBytes += size; if (recBytes < recTotal) { receiveHeader(); } else { MessageHeader* header = reinterpret_cast<MessageHeader*>(recBuffer.data()); recBytes = 0; recTotal = header->size; recType = header->type; recBuffer.clear(); receiveBody(); } }); }
void ClientConnection::interpretData() { switch (recType) { case MessageType::CONFIRM: { std::string content = std::string(reinterpret_cast<char*>(recBuffer.data())); std::stringstream ss(content); std::string idSubstring; ss >> idSubstring; id = std::atoi(idSubstring.c_str()); username = ""; std::string temp; while (ss >> temp) username += temp + " "; if (username.length() > 0) username = username.substr(0, username.length() - 1); std::cout << "Confirmed to be: " << username << " with id of " << (int)id << std::endl; std::string toSend = ""; auto mh = MessageHeader{ MessageType::MAP_REQUEST, toSend.length() + 1 }; std::vector<uint8_t> sendBuffer; sendBuffer.resize(sizeof(MessageHeader) + mh.size); memcpy(sendBuffer.data(), &mh, sizeof(MessageHeader)); memcpy(sendBuffer.data() + sizeof(MessageHeader), toSend.data(), mh.size); send(sendBuffer); break; } case MessageType::MAP_DATA: { auto recdata = reinterpret_cast<MapMessage*>(recBuffer.data()); auto linearized = std::string(reinterpret_cast<char*>(recBuffer.data() + sizeof(MapMessage))); gamestate->totalClients = recdata->clients; std::cout << "Got a " << recdata->height << " x " << recdata->width << " map!" << std::endl; std::cout << "Length of string: " << linearized.length() << std::endl; gamestate->mapData = new uint8_t*[ recdata->height ]; for (auto i = 0; i < recdata->height; i++) { gamestate->mapData[i] = new uint8_t[ recdata->width ]; for (auto j = 0; j < recdata->width; j++) { auto position = i*recdata->width + j; gamestate->mapData[i][j] = (uint8_t)(linearized[position] - '0'); } } gamestate->map = new Map(gamestate->mapData, recdata->height, recdata->width); gamestate->entities = new std::vector<std::shared_ptr<Entity>>(); gamestate->entities->resize(gamestate->totalClients*3); for (auto i = 0; i < gamestate->totalClients * 3; i++) (*gamestate->entities)[i] = std::make_shared<Entity>(0, 0, gamestate, false, i); std::string toSend = ""; auto mh = MessageHeader{ MessageType::READY, toSend.length() + 1 }; std::vector<uint8_t> sendBuffer; sendBuffer.resize(sizeof(MessageHeader) + mh.size); memcpy(sendBuffer.data(), &mh, sizeof(MessageHeader)); memcpy(sendBuffer.data() + sizeof(MessageHeader), toSend.data(), mh.size); send(sendBuffer); break; } case MessageType::GAME_START: { gamestate->inGame = true; std::cout << "Game has started!" << std::endl; break; } case MessageType::UPDATE_DATA: { auto data = reinterpret_cast<UpdateDataMessage*>(recBuffer.data()); gamestate->dataMtx.lock(); (*gamestate->entities)[data->ID]->update(*data); gamestate->dataMtx.unlock(); break; } case MessageType::GAME_FINISH: { isActive = false; gamestate->inGame = false; gamestate->isFinished = true; std::cout << "Game has finished!" << std::endl; std::string toSend = ""; auto mh = MessageHeader{ MessageType::DISCONNECT, toSend.length() + 1 }; std::vector<uint8_t> sendBuffer; sendBuffer.resize(sizeof(MessageHeader) + mh.size); memcpy(sendBuffer.data(), &mh, sizeof(MessageHeader)); memcpy(sendBuffer.data() + sizeof(MessageHeader), toSend.data(), mh.size); send(sendBuffer); break; } } recBuffer.clear(); if (isActive) receiveHeader(); }
static respData_t* p61_dev_receiveData_internal(struct file *filp) { short rPcb = 0; short rLen = 0; respData_t *header=NULL; respData_t *respData=NULL; unsigned char *wtx=NULL; unsigned char *data=NULL; //unsigned char *data1=NULL; int len=0; int len1=0; int stat_timer; Start: NFC_DBG_MSG(KERN_INFO "receiveData -Enter\n"); // receive the T=1 header header = (respData_t*)receiveHeader(filp); if(header == NULL) { NFC_ERR_MSG(KERN_ALERT "ERROR:Failed to receive header data\n"); return NULL; } rPcb = header->data[0]; rLen = (short) (header->data[1] & 0xFF); NFC_DBG_MSG(KERN_ALERT "receive header data rPcb = 0x%x , rLen = %d\n", rPcb, rLen); #if 1 //check the header if wtx is requested if ((rPcb & PH_SCAL_T1_S_BLOCK) == PH_SCAL_T1_S_BLOCK) { NFC_DBG_MSG(KERN_ALERT "receiveDatav - WTX requested\n"); data = gRecvBuff; len = 1; NFC_DBG_MSG(KERN_ALERT "receiveDatav - WTX1 requested\n"); receive(filp,&data,len, C_TRANSMIT_NO_STOP_CONDITION | C_TRANSMIT_NO_START_CONDITION); NFC_DBG_MSG(KERN_ALERT "receiveDatav - WTX2 requested\n"); receiveAndCheckChecksum(filp,rPcb, rLen, data,len); NFC_DBG_MSG(KERN_ALERT "receiveDatav - WTX3 requested\n"); NFC_DBG_MSG(KERN_ALERT "value is %x %x",data[0],data[1]); memset(gRecvBuff,0,300); wtx = gRecvBuff; wtx[0] = 0x00; wtx[1] = 0xE3; wtx[2] = 0x01; wtx[3] = 0x01; wtx[4] = 0xE3; len1 = 5; udelay(1000); send(filp,&wtx, C_TRANSMIT_NORMAL_SPI_OPERATION,len1); udelay(1000); //gStRecvData->len = 5; //memcpy(gStRecvData->data, wtx, 5);; #ifdef TIMER_ENABLE stat_timer = start_timer(); #endif //return gStRecvData; goto Start; } //check the header if retransmit is requested if ((rPcb & PH_SCAL_T1_R_BLOCK) == PH_SCAL_T1_R_BLOCK) { memset(data1,0,1); len1=1; receiveAndCheckChecksum(filp,rPcb, rLen, data1,len1); udelay(1000); send(filp,&lastFrame, C_TRANSMIT_NORMAL_SPI_OPERATION,lastFrameLen); udelay(1000); goto Start; // return (ssize_t)p61_dev_receiveData_internal(filp); } //check the PCB byte and receive the rest of the frame if ((rPcb & PH_SCAL_T1_CHAINING) == PH_SCAL_T1_CHAINING) { NFC_DBG_MSG(KERN_ALERT "Chained Frame Requested\n"); return receiveChainedFrame(filp,rPcb, rLen); } else { NFC_DBG_MSG(KERN_ALERT "receiveFrame Requested\n"); respData = receiveFrame(filp,rPcb, rLen); NFC_DBG_MSG(KERN_ALERT "***************** 0x%x \n",respData->data[0]); return respData; } #endif return NULL; }
int HttpClient::requestWebPage(Url &url, HttpHeader &httpHeader, HttpContent &httpContent) { // construct a request string requestStr; string path = url.getPath(); if (path.empty()) path = "/"; requestStr = "GET " + path + " HTTP/1.0\r\nHost: " + url.getHost() + "\r\nUser-Agent: openSE/1.0 (Ubuntu11.04)\r\nAccept-Language: zh,en-us\r\nAccept-Charset: gb2312,utf-8\r\nConnection: Keep-Alive\r\n\r\n"; cout << "requestStr:\n" << requestStr << endl; // send request: if (url.getHost() != _preHost) { if (_preSockFd != -1) { closesocket(_preSockFd); _preSockFd = -1; } } int sockFd; bool sendSuccess = false; // try to use previous connection if (_preSockFd != -1) { sockFd = _preSockFd; if (rio_writen(sockFd, requestStr.c_str(), requestStr.size()) == -1) { cerr << "use previous connection:rio_writen error !" << endl; closesocket(_preSockFd); _preSockFd = -1; } else sendSuccess = true; } if (!sendSuccess) { // try to creat a new connection sockFd = tcpConnect(url.getIp(), url.getPort()); if (sockFd == -1) { cerr << "tcpConnect error" << endl; return -1; } // try to use new connection if (rio_writen(sockFd, requestStr.c_str(), requestStr.size()) == -1) { cerr << "rio_writen error for requestStr:" << requestStr << endl; closesocket(sockFd); return -1; } } // receive http header string headerStr; headerStr.reserve(1024); if (receiveHeader(sockFd, headerStr, DEFAULT_TIMEOUT_SECONDS) <= 0) { cerr << "receiveHeader error" << endl; closesocket(sockFd); _preSockFd = -1; return -1; } //cout << "headerStr:\n" << headerStr << endl; // parser http header httpHeader.setHeaderStr(headerStr); // check StatusCode int stausCode = httpHeader.getStatusCode(); if (stausCode == -1) { cerr << "not find status code in httpHeader: " << httpHeader.getHeaderStr() << endl; } if (stausCode == 301 || stausCode == 302) { closesocket(sockFd); _preSockFd = -1; string locationUrlStr = httpHeader.getLocation(); if (locationUrlStr.empty()) { cerr << "error location in httpHeader: " << httpHeader.getHeaderStr() << endl; } //locationStr = location; Url locationUrl(locationUrlStr); return requestWebPage(locationUrl, httpHeader, httpContent); } if (stausCode < 200 || stausCode > 299) { closesocket(sockFd); _preSockFd = -1; cerr << "status code beyond [200-300) in httpHeader: " << httpHeader.getHeaderStr() << endl; return -1; } // check content type string contentType = httpHeader.getContentType(); if (contentType.find("image") != string::npos) { closesocket(sockFd); _preSockFd = -1; cerr << "contentType is image in httpHeader: " << httpHeader.getHeaderStr() << endl; return -1; } // check ContentLength int contentLength = httpHeader.getContentLength(); if (contentLength == -1) { //cerr << "contentLength is not finded in httpHeader: " << httpHeader.getHeaderStr() << endl; contentLength = MAX_HTTPCONTENT_SIZE / 10; } if (contentLength == 0) { closesocket(sockFd); _preSockFd = -1; cerr << "contentLength is 0 in httpHeader: " << httpHeader.getHeaderStr() << endl; return -1; } if (contentLength > MAX_HTTPCONTENT_SIZE) { closesocket(sockFd); _preSockFd = -1; cerr << "contentLength > MAX_HTTPCONTENT_SIZE in httpHeader: " << httpHeader.getHeaderStr() << endl; return -1; } // receive content string contentStr; if (receiveContent(sockFd, contentLength, contentStr, DEFAULT_TIMEOUT_SECONDS) == -1) { closesocket(sockFd); _preSockFd = -1; cerr << "receiveContent error for url: " << url.getUrlStr() << endl; //cout << contentStr << endl; return -1; } else _preSockFd = sockFd; //cout << "contentStr:\n" << contentStr << endl; // cout << "content finished,url is:"<<url.getUrlStr()<<endl; // set http content httpContent.setContentStr(contentStr); return 0; }
respData_t *receiveChainedFrame(struct file *filp,short rPcb, short rLen) { respData_t *data_rec=NULL; respData_t *header=NULL ; respData_t *respData=NULL; respData_t *apdbuff=NULL; NFC_DBG_MSG(KERN_ALERT "receiveChainedFrame -Enter\n"); // receive a chained frame as long as chaining is indicated in the PCB do { // receive the DATA field of the current frame NFC_DBG_MSG(KERN_ALERT "p61_dev_read - test4 count [0x%x] \n",rLen); data_rec = receiveFrame(filp,rPcb, rLen); // write it into an apduBuffer memory memcpy((apduBuffer+apduBufferidx),data_rec->data,data_rec->len); //update the index to next free slot apduBufferidx += data_rec->len; // send the acknowledge for the current frame udelay(1000); sendAcknowledge(filp); udelay(1000); // receive the header of the next frame header = receiveHeader(filp); rPcb = header->data[0]; rLen = (header->data[1] & 0xFF); }while ((rPcb & PH_SCAL_T1_CHAINING) == PH_SCAL_T1_CHAINING); // receive the DATA field of the last frame respData = receiveFrame(filp,rPcb, rLen); memcpy(apduBuffer+apduBufferidx,respData->data,respData->len); //update the index to next free slot apduBufferidx += respData->len; // return the entire received apdu apdbuff=(respData_t *)kmalloc(sizeof(respData_t),GFP_KERNEL); if(apdbuff == NULL) { NFC_ERR_MSG(KERN_ALERT "receiveChainedFrame 2-KMALLOC FAILED!!!\n"); return NULL; } apdbuff->data= (unsigned char*)kmalloc(apduBufferidx,GFP_KERNEL); if(apdbuff->data == NULL) { NFC_ERR_MSG(KERN_ALERT "receiveChainedFrame 3-KMALLOC FAILED!!!\n"); return NULL; } memcpy(apdbuff->data,apduBuffer,apduBufferidx); apdbuff->len=apduBufferidx; NFC_DBG_MSG(KERN_ALERT "receiveChainedFrame -Exit\n"); return apdbuff; }
/* client function that performs the diff method */ int clientDiff(int sock) { if(!sendHeader(1,0,0, sock)) fatal_error("send header has failed\n"); header *rcvHead= receiveHeader(sock); if(!rcvHead) fatal_error("error receiving rcv header\n"); if(!rcvHead->indexes&&!rcvHead->length) { free(rcvHead); fprintf(stderr,"There are no songs on the server.\n\n"); return 1; } song *rcvSongs=recvSongArray(rcvHead->indexes,sock); if(!rcvSongs) fatal_error("error receiving song array\n"); int i; song *clientSongs=0; int numSongs=numSongsInDir(); if(numSongs<0) fatal_error("number of songs calculation failed\n"); else if(numSongs>0) { clientSongs=createSongArray(numSongs); int diffLen=0; song *diffSongs = compareSongDir(rcvSongs, rcvHead->indexes, clientSongs, numSongs,&diffLen); if(!diffLen) { fprintf(stderr,"You have all the songs that are on the server.\n\n"); free(diffSongs); free(clientSongs); free(rcvHead); free(rcvSongs); return 1; } fprintf(stderr,"Songs on the server that you do not have are:\n"); for(i=0;i<diffLen;i++) { fprintf(stderr,"%s\n",diffSongs[i].title); } fprintf(stderr,"\n"); free(diffSongs); free(clientSongs); } else { fprintf(stderr,"Songs on the server that you do not have are:\n"); for(i=0;i<rcvHead->indexes;i++) { fprintf(stderr,"%s\n",rcvSongs[i].title); } fprintf(stderr,"\n"); } free(rcvHead); free(rcvSongs); return 1; }
void CDVRPTRRepeaterRXThread::receiveRadio() { for (;;) { unsigned char data[50U]; unsigned int length; DATA_QUEUE_TYPE type = m_dvrptr->readQueue(data, length); switch (type) { case DQT_NONE: return; case DQT_HEADER: // CUtils::dump(wxT("DQT_HEADER"), data, length); break; case DQT_DATA: // CUtils::dump(wxT("DQT_DATA"), data, length); break; case DQT_EOT: // wxLogMessage(wxT("DQT_EOT")); break; case DQT_LOST: // wxLogMessage(wxT("DQT_LOST")); break; default: wxLogMessage(wxT("type=%d"), int(type)); CUtils::dump(wxT("DQT_???"), data, length); break; } switch (m_rxState) { case DSRXS_LISTENING: if (type == DQT_HEADER) { receiveHeader(data, length); } else if (type == DQT_DATA) { setRadioState(DSRXS_PROCESS_SLOW_DATA); } break; case DSRXS_PROCESS_SLOW_DATA: if (type == DQT_DATA) { receiveSlowData(data, length); } else if (type == DQT_EOT) { setRadioState(DSRXS_LISTENING); } else if (type == DQT_LOST) { setRadioState(DSRXS_LISTENING); } break; case DSRXS_PROCESS_DATA: if (type == DQT_DATA) { receiveRadioData(data, length); } else if (type == DQT_EOT) { processRadioFrame(data, FRAME_END); setRadioState(DSRXS_LISTENING); endOfRadioData(); } else if (type == DQT_LOST) { ::memcpy(data, NULL_FRAME_DATA_BYTES, DV_FRAME_LENGTH_BYTES); processRadioFrame(data, FRAME_END); setRadioState(DSRXS_LISTENING); endOfRadioData(); } break; } } }