Socket bugfix
This commit is contained in:
parent
06e0aa40ab
commit
0f125ca0e9
1 changed files with 14 additions and 24 deletions
|
@ -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){
|
|
||||||
case EWOULDBLOCK: Blocking = true; break;
|
|
||||||
default:
|
|
||||||
Error = true;
|
Error = true;
|
||||||
#if DEBUG >= 2
|
#if DEBUG >= 2
|
||||||
fprintf(stderr, "Could not write data! Error: %s\n", strerror(errno));
|
fprintf(stderr, "Could not write data! Error: %s\n", strerror(errno));
|
||||||
#endif
|
#endif
|
||||||
close();
|
close();
|
||||||
return false;
|
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){
|
|
||||||
case EWOULDBLOCK: Blocking = true; break;
|
|
||||||
default:
|
|
||||||
Error = true;
|
Error = true;
|
||||||
#if DEBUG >= 2
|
#if DEBUG >= 2
|
||||||
fprintf(stderr, "Could not read data! Error: %s\n", strerror(errno));
|
fprintf(stderr, "Could not read data! Error: %s\n", strerror(errno));
|
||||||
#endif
|
#endif
|
||||||
close();
|
close();
|
||||||
return false;
|
return false;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
sofar += r;
|
sofar += r;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue