This commit is contained in:
Thulinma 2010-11-08 21:45:39 +01:00
parent f3d73b3df4
commit e80b413381
2 changed files with 24 additions and 9 deletions

View file

@ -94,12 +94,23 @@ bool DDV_ready(int sock){
fcntl(sock, F_SETFL, postflags);
int r = recv(sock, &tmp, 1, MSG_PEEK);
fcntl(sock, F_SETFL, preflags);
if (r != 1){
fprintf(stderr, "Er ging iets mis... %i\n", r);
}
return (r == 1);
}
int DDV_readycount(int sock){
static tmp[1048576];
int preflags = fcntl(sock, F_GETFL, 0);
int postflags = preflags | O_NONBLOCK;
fcntl(sock, F_SETFL, postflags);
int r = recv(sock, tmp, 1048576, MSG_PEEK);
fcntl(sock, F_SETFL, preflags);
if (r > 0){
return r;
}else{
return 0;
}
}
bool DDV_read(void * buffer, int todo, int sock){
int sofar = 0;
socketBlocking = false;

View file

@ -34,13 +34,17 @@ bool FLV_Isheader(char * header){
bool ReadUntil(char * buffer, unsigned int count, unsigned int & sofar, int sock){
if (sofar >= count){return true;}
fprintf(stderr, "Reading %i/%i\n", sofar, count);
bool r = DDV_read(buffer + sofar,count-sofar,sock);
sofar = count;
if (!r){
All_Hell_Broke_Loose = true;
fprintf(stderr, "ReadUntil fail: %s. All Hell Broke Loose!\n", strerror(errno));
if (DDV_readycount(sock) >= count-sofar){
bool r = DDV_read(buffer + sofar,count-sofar,sock);
sofar = count;
if (!r){
All_Hell_Broke_Loose = true;
fprintf(stderr, "ReadUntil fail: %s. All Hell Broke Loose!\n", strerror(errno));
}
return r;
}else{
return false;
}
return r;
}
//gets a packet, storing in given FLV_Pack pointer.