本文整理汇总了C++中PacketReader::position方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketReader::position方法的具体用法?C++ PacketReader::position怎么用?C++ PacketReader::position使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PacketReader
的用法示例。
在下文中一共展示了PacketReader::position方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pushDataPacket
void Listener::pushDataPacket(const string& name,PacketReader& packet) {
// TODO create _dataWriter ??
if(_unbuffered) {
UInt16 offset = name.size()+9;
if(packet.position()>=offset) {
packet.reset(packet.position()-offset);
_writer.writeUnbufferedMessage(packet.current(),packet.available());
return;
}
WARN("Written unbuffered impossible, it requires %u head bytes available on PacketReader given",offset);
}
StreamCopier::copyStream(packet.stream(),_writer.writeAMFPacket(name).writer.stream());
}
示例2: buildPacket
bool WSSession::buildPacket(PacketReader& packet) {
if (packet.available()<2)
return false;
UInt8 type = packet.read8() & 0x0F;
UInt8 lengthByte = packet.read8();
UInt32 size=lengthByte&0x7f;
if (size==127) {
if (packet.available()<8)
return false;
size = (UInt32)packet.read64();
} else if (size==126) {
if (packet.available()<2)
return false;
size = packet.read16();
}
if(lengthByte&0x80)
size += 4;
if (packet.available()<size)
return false;
packet.shrink(size);
if (lengthByte & 0x80) {
shared_ptr<WSUnmasking> pWSUnmasking(new WSUnmasking(invoker, packet.current(),packet.available(), type));
decode<WSUnmasking>(pWSUnmasking);
} else {
packet.reset(packet.position()-1);
*(UInt8*)packet.current() = type;
}
return true;
}
示例3: pushRawPacket
void Publication::pushRawPacket(UInt8 type,PacketReader& packet) {
list<Listener*>::const_iterator it;
int pos = packet.position();
for(it=_listeners.begin();it!=_listeners.end();++it) {
(*it)->pushRawPacket(type,packet);
packet.reset(pos);
}
}
示例4: pushVideoPacket
void Publication::pushVideoPacket(PacketReader& packet) {
UInt32 time = packet.read32(); // TODO?
list<Listener*>::const_iterator it;
int pos = packet.position();
for(it=_listeners.begin();it!=_listeners.end();++it) {
(*it)->pushVideoPacket(packet);
packet.reset(pos);
}
}
示例5: write
void write(UInt32 time,PacketReader& data,bool unbuffered) {
// if(_type==0x08)
// time=0;
/* if(_type==0x09)
TRACE("Video timestamp : %u",_time)
else
TRACE("Audio timestamp : %u",_time);*/
if(unbuffered) {
if(data.position()>=5) {
data.reset(data.position()-5);
PacketWriter writer(data.current(),5);
writer.write8(_type);
writer.write32(time);
writeUnbufferedMessage(data.current(),data.available(),data.current(),5);
return;
}
WARN("Written unbuffered impossible, it requires 5 head bytes available on PacketReader given");
}
BinaryWriter& out = writeRawMessage(true);
out.write8(_type);
out.write32(time);
StreamCopier::copyStream(data.stream(),out.stream());
}
示例6: acknowledgment
void RTMFPWriter::acknowledgment(PacketReader& packet) {
UInt64 bufferSize = packet.read7BitLongValue(); // TODO use this value in reliability mechanism?
if(bufferSize==0) {
// In fact here, we should send a 0x18 message (with id flow),
// but it can create a loop... We prefer the following behavior
fail("Negative acknowledgment");
return;
}
UInt64 stageAckPrec = _stageAck;
UInt64 stageReaden = packet.read7BitLongValue();
UInt64 stage = _stageAck+1;
if(stageReaden>_stage) {
ERROR("Acknowledgment received ",stageReaden," superior than the current sending stage ",_stage," on writer ",id);
_stageAck = _stage;
} else if(stageReaden<=_stageAck) {
// already acked
if(packet.available()==0)
DEBUG("Acknowledgment ",stageReaden," obsolete on writer ",id);
} else
_stageAck = stageReaden;
UInt64 maxStageRecv = stageReaden;
UInt32 pos=packet.position();
while(packet.available()>0)
maxStageRecv += packet.read7BitLongValue()+packet.read7BitLongValue()+2;
if(pos != packet.position()) {
// TRACE(stageReaden,"..x"Util::FormatHex(reader.current(),reader.available()));
packet.reset(pos);
}
UInt64 lostCount = 0;
UInt64 lostStage = 0;
bool repeated = false;
bool header = true;
bool stop=false;
auto it=_messagesSent.begin();
while(!stop && it!=_messagesSent.end()) {
RTMFPMessage& message(**it);
if(message.fragments.empty()) {
CRITIC("RTMFPMessage ",(stage+1)," is bad formatted on fowWriter ",id);
++it;
continue;
}
map<UInt32,UInt64>::iterator itFrag=message.fragments.begin();
while(message.fragments.end()!=itFrag) {
// ACK
if(_stageAck>=stage) {
message.fragments.erase(message.fragments.begin());
itFrag=message.fragments.begin();
++_ackCount;
++stage;
continue;
}
// Read lost informations
while(!stop) {
if(lostCount==0) {
if(packet.available()>0) {
lostCount = packet.read7BitLongValue()+1;
lostStage = stageReaden+1;
stageReaden = lostStage+lostCount+packet.read7BitLongValue();
} else {
stop=true;
break;
}
}
// check the range
if(lostStage>_stage) {
// Not yet sent
ERROR("Lost information received ",lostStage," have not been yet sent on writer ",id);
stop=true;
} else if(lostStage<=_stageAck) {
// already acked
--lostCount;
++lostStage;
continue;
}
break;
}
if(stop)
break;
// lostStage > 0 and lostCount > 0
if(lostStage!=stage) {
if(repeated) {
++stage;
++itFrag;
header=true;
} else // No repeated, it means that past lost packet was not repeatable, we can ack this intermediate received sequence
_stageAck = stage;
//.........这里部分代码省略.........
示例7: handshakeHandler
UInt8 Handshake::handshakeHandler(UInt8 id,PacketReader& request,PacketWriter& response) {
switch(id){
case 0x30: {
request.read8(); // passer un caractere (boite dans boite)
UInt8 epdLen = request.read8()-1;
UInt8 type = request.read8();
string epd;
request.readRaw(epdLen,epd);
string tag;
request.readRaw(16,tag);
response.writeString8(tag);
if(type == 0x0f)
return _gateway.p2pHandshake(tag,response,peer.address,(const UInt8*)epd.c_str());
if(type == 0x0a){
/// Handshake
HelloAttempt& attempt = helloAttempt<HelloAttempt>(tag);
if(edges().size()>0 && (_invoker.edgesAttemptsBeforeFallback==0 || attempt.count <_invoker.edgesAttemptsBeforeFallback)) {
if(_invoker.edgesAttemptsBeforeFallback>0) {
try {
URI uri(epd);
response.writeAddress(SocketAddress(uri.getHost(),uri.getPort()),false); // TODO check with true!
} catch(Exception& ex) {
ERROR("Parsing %s URL problem in hello attempt : %s",epd.c_str(),ex.displayText().c_str());
}
}
map<int,list<Edge*> > edgesSortedByCount;
map<string,Edge*>::const_iterator it;
for(it=edges().begin();it!=edges().end();++it)
edgesSortedByCount[it->second->count].push_back(it->second);
UInt8 count=0;
map<int,list<Edge*> >::const_iterator it2;
for(it2=edgesSortedByCount.begin();it2!=edgesSortedByCount.end();++it2) {
list<Edge*>::const_iterator it3;
for(it3=it2->second.begin();it3!=it2->second.end();++it3) {
response.writeAddress((*it3)->address,false);
if((++count)==6) // 6 redirections maximum
break;
}
if(it3!=it2->second.end())
break;
}
return 0x71;
}
if(edges().size()>0)
WARN("After %u hello attempts, impossible to connect to edges. Edges are busy? or unreachable?",_invoker.edgesAttemptsBeforeFallback);
// New Cookie
createCookie(response,attempt,tag,epd);
// instance id (certificat in the middle)
response.writeRaw(_certificat,sizeof(_certificat));
return 0x70;
} else
ERROR("Unkown handshake first way with '%02x' type",type);
break;
}
case 0x39:
case 0x38: {
(UInt32&)farId = request.read32();
if(request.read7BitLongValue()!=COOKIE_SIZE) {
ERROR("Bad handshake cookie '%s': its size should be 64 bytes",Util::FormatHex(request.current(),COOKIE_SIZE).c_str());
return 0;
}
map<const UInt8*,Cookie*,CompareCookies>::iterator itCookie = _cookies.find(request.current());
if(itCookie==_cookies.end()) {
if(id!=0x39) {
ERROR("Handshake cookie '%s' unknown",Util::FormatHex(request.current(),COOKIE_SIZE).c_str());
return 0;
}
Cookie* pCookie = new Cookie();
UInt32 pos = request.position();
request.readRaw((UInt8*)pCookie->value,COOKIE_SIZE);
request >> (string&)pCookie->queryUrl;
request.reset(pos);
itCookie = _cookies.insert(pair<const UInt8*,Cookie*>(pCookie->value,pCookie)).first;
}
Cookie& cookie(*itCookie->second);
if(cookie.id==0) {
UInt8 decryptKey[AES_KEY_SIZE];UInt8* pDecryptKey=&decryptKey[0];
UInt8 encryptKey[AES_KEY_SIZE];UInt8* pEncryptKey=&encryptKey[0];
if(id==0x38) {
//.........这里部分代码省略.........