Socket bugfix

This commit is contained in:
Thulinma 2011-04-18 15:09:31 +02:00
parent 7cb55a400a
commit ca1e60b461
2 changed files with 15 additions and 25 deletions

View file

@ -50,7 +50,7 @@ int Connector_RTMP::Connector_RTMP(DDV::Socket conn){
//first timestamp set //first timestamp set
RTMPStream::firsttime = RTMPStream::getNowMS(); RTMPStream::firsttime = RTMPStream::getNowMS();
while (RTMPStream::handshake_in.size() < 1537){ while (Socket.connected() && (RTMPStream::handshake_in.size() < 1537)){
Socket.read(RTMPStream::handshake_in); Socket.read(RTMPStream::handshake_in);
} }
RTMPStream::rec_cnt += 1537; RTMPStream::rec_cnt += 1537;

View file

@ -106,21 +106,16 @@ bool DDV::Socket::connected(){
/// \returns True if the whole write was succesfull, false otherwise. /// \returns True if the whole write was succesfull, false otherwise.
bool DDV::Socket::write(const void * buffer, int len){ bool DDV::Socket::write(const void * buffer, int len){
int sofar = 0; int sofar = 0;
Blocking = false; if (sock < 0){return false;}
while (sofar != len){ while (sofar != len){
int r = send(sock, (char*)buffer + sofar, len-sofar, 0); int r = send(sock, (char*)buffer + sofar, len-sofar, 0);
if (r <= 0){ if (r <= 0){
switch (errno){ Error = true;
case EWOULDBLOCK: Blocking = true; break; #if DEBUG >= 2
default: fprintf(stderr, "Could not write data! Error: %s\n", strerror(errno));
Error = true; #endif
#if DEBUG >= 2 close();
fprintf(stderr, "Could not write data! Error: %s\n", strerror(errno)); return false;
#endif
close();
return false;
break;
}
}else{ }else{
sofar += r; sofar += r;
} }
@ -137,21 +132,16 @@ bool DDV::Socket::write(const void * buffer, int len){
/// \returns True if the whole read was succesfull, false otherwise. /// \returns True if the whole read was succesfull, false otherwise.
bool DDV::Socket::read(void * buffer, int len){ bool DDV::Socket::read(void * buffer, int len){
int sofar = 0; int sofar = 0;
Blocking = false; if (sock < 0){return false;}
while (sofar != len){ while (sofar != len){
int r = recv(sock, (char*)buffer + sofar, len-sofar, 0); int r = recv(sock, (char*)buffer + sofar, len-sofar, 0);
if (r <= 0){ if (r <= 0){
switch (errno){ Error = true;
case EWOULDBLOCK: Blocking = true; break; #if DEBUG >= 2
default: fprintf(stderr, "Could not read data! Error: %s\n", strerror(errno));
Error = true; #endif
#if DEBUG >= 2 close();
fprintf(stderr, "Could not read data! Error: %s\n", strerror(errno)); return false;
#endif
close();
return false;
break;
}
}else{ }else{
sofar += r; sofar += r;
} }