Stripped some unused code from Socket::Connection and FLV::Tag, made some Socket::Connection methods private.

This commit is contained in:
Thulinma 2012-08-26 20:08:16 +02:00
parent 9ca532523c
commit 0e0ecb1bdf
4 changed files with 47 additions and 258 deletions

View file

@ -627,79 +627,6 @@ bool FLV::Tag::MemLoader(char * D, unsigned int S, unsigned int & P){
}//Tag::MemLoader
/// Helper function for FLV::SockLoader.
/// This function will try to read count bytes from socket sock into buffer.
/// This function should be called repeatedly until true.
/// \param buffer The target buffer.
/// \param count Amount of bytes to read.
/// \param sofar Current amount read.
/// \param sock Socket to read from.
/// \return True if count bytes are read succesfully, false otherwise.
bool FLV::Tag::SockReadUntil(char * buffer, unsigned int count, unsigned int & sofar, Socket::Connection & sock){
if (sofar >= count){return true;}
int r = 0;
r = sock.iread(buffer + sofar,count-sofar);
sofar += r;
if (sofar >= count){return true;}
return false;
}//Tag::SockReadUntil
/// Try to load a tag from a socket.
/// This is a stateful function - if fed incorrect data, it will most likely never return true again!
/// While this function returns false, the Tag might not contain valid data.
/// \param sock The socket to read from.
/// \return True if a whole tag is succesfully read, false otherwise.
bool FLV::Tag::SockLoader(Socket::Connection sock){
if (buf < 15){data = (char*)realloc(data, 15); buf = 15;}
if (done){
if (SockReadUntil(data, 11, sofar, sock)){
//if its a correct FLV header, throw away and read tag header
if (FLV::is_header(data)){
if (SockReadUntil(data, 13, sofar, sock)){
if (FLV::check_header(data)){
sofar = 0;
memcpy(FLV::Header, data, 13);
}else{FLV::Parse_Error = true; Error_Str = "Invalid header received."; return false;}
}
}else{
//if a tag header, calculate length and read tag body
len = data[3] + 15;
len += (data[2] << 8);
len += (data[1] << 16);
if (buf < len){data = (char*)realloc(data, len); buf = len;}
if (data[0] > 0x12){
data[0] += 32;
FLV::Parse_Error = true;
Error_Str = "Invalid Tag received (";
Error_Str += data[0];
Error_Str += ").";
return false;
}
done = false;
}
}
}else{
//read tag body
if (SockReadUntil(data, len, sofar, sock)){
//calculate keyframeness, next time read header again, return true
if ((data[0] == 0x09) && (((data[11] & 0xf0) >> 4) == 1)){isKeyframe = true;}else{isKeyframe = false;}
done = true;
sofar = 0;
return true;
}
}
return false;
}//Tag::SockLoader
/// Try to load a tag from a socket.
/// This is a stateful function - if fed incorrect data, it will most likely never return true again!
/// While this function returns false, the Tag might not contain valid data.
/// \param sock The socket to read from.
/// \return True if a whole tag is succesfully read, false otherwise.
bool FLV::Tag::SockLoader(int sock){
return SockLoader(Socket::Connection(sock));
}//Tag::SockLoader
/// Helper function for FLV::FileLoader.
/// This function will try to read count bytes from file f into buffer.
/// This function should be called repeatedly until true.