void processControls (string &msgsStr,const socket_t &sock) { int msgsStrEnd; const CStrings msgs=split("\n",msgsStr,std::numeric_limits<int>::max(),&msgsStrEnd); for (CStringsIterator msgsItem=msgs.begin();msgsItem!=msgs.end();msgsItem++) { if (!msgsItem->empty()) { string resp=processControl(*msgsItem,sock); if (!resp.empty()) { // makeLog(LOG_DEBUG,"Sending control {%s}",resp.c_str()); sendControl(resp);//socket,resp.c_str(),resp.length(),0,(const sockaddr*)&control.peer,sizeof(control.peer)); } } } msgsStr=msgsStrEnd?msgs.back():""; }
string processControl (const string Msg,const socket_t &sock) { const CStrings data=split(" ",Msg); const CStringsIterator name=data.begin(); string result=""; makeLog(LOG_DEBUG,"Control: Processing {%s}",Msg.c_str()); if (name->compare("SEND")==0) { uint16_t resendNumber = (data.size()>1)?atoi(data[1].c_str()):0; uint16_t cnt = (data.size()>2)?atoi(data[2].c_str()):0; if (cnt<1) cnt=1; // makeLog(LOG_DEBUG,"RESEND request: %d:%d",resendNumber,cnt); bool wasMissing=false; for (int i=0;i<cnt;i++) { int missing = getDatagramLength(resendNumber); if (missing<=0) { wasMissing=true; makeLog(LOG_INFO,"Streamer: Datagram lost: %d",resendNumber); sendControl(stringprintf("SEND_OOB %d",resendNumber)); } else { ictDatagram_t ictDatagram; getDatagram(ictDatagram,resendNumber); outQueue.push_front ( resendNumber ); // sendto(sender.socket,ictDatagram,ictDatagram.size(),0,(const sockaddr*)&sender.peer,sizeof(sender.peer)); } resendNumber++; } if (wasMissing) { makeLog(LOG_WARNING,"Streamer: Packet(s) is out of buffer"); } } else if (name->compare("STARTED")==0) { makeLog (LOG_INFO,"Control: method STARTED"); } else if (name->compare("KEPT")==0) { keptLastTime=getMNow(); } else if (name->compare("SETBUF")==0) { //makelog ("Control message: {$msg1}"); int newBufferTime=(data.size()>1)?atoi(data[1].c_str()):-1; if (newBufferTime!=-1 && cleaningArgs.bufferSize!=newBufferTime) { cleaningArgs.bufferSize=newBufferTime; makeLog (LOG_INFO,"Buffer is set to new value: %d",cleaningArgs.bufferSize); } return stringprintf("BUFSET %d",cleaningArgs.bufferSize); } else if (name->compare("RESETSTREAM")==0) { FD_CLR(sender.getHandle(),&master); sender.reinit(); FD_SET(sender.getHandle(),&master); makeLog (LOG_INFO,"Streamer: Restart on receiver requested"); result+=stringprintf("STREAMRESET %d",0); } else if (name->compare("SUSPEND")==0) { if (!sendingSuspended) { sendingSuspended=true; makeLog(LOG_INFO,"Streamer: Supended on receiver request"); } return stringprintf("SUSPENDED %d",0); //TODO O by malo byt cislo noveho portu na vysielacej strane } else if (name->compare("RESUME")==0) { sendingSuspended=false; return stringprintf("RESUMED %d",0); //TODO O by malo byt cislo noveho portu na vysielacej strane } else if (name->compare("CINIT")==0) { int newBufferTime=data.size()>1?atoi(data[1].c_str()):-1; sendingSuspended=false; makeLog(LOG_INFO,"Clinet initialization request from receiver"); if (newBufferTime!=-1 && cleaningArgs.bufferSize!=newBufferTime) { cleaningArgs.bufferSize=newBufferTime; makeLog (LOG_INFO,"Buffer is set to new value: %d",cleaningArgs.bufferSize); result+=stringprintf("BUFSET %d",cleaningArgs.bufferSize); } result+=stringprintf("CINITED %d",0);//getSocketLocalPort(sender.socket)); //TODO O by malo byt cislo noveho portu na vysielacej strane } else if (name->compare("CUNINIT")==0) { clearBuffer(); sendingInitialized=false; result+=stringprintf("CUNINITED %d",0); //TODO O by malo byt cislo noveho portu na vysielacej strane } else if (name->compare("CONNECTCONTROL")==0) { return "CONTROLCONNECT\n"; } else { makeLog(LOG_ERR,"Control: unknown command: %s",name->c_str()); } return result; }