DDVSocket edits

This commit is contained in:
Thulinma 2010-11-08 16:09:42 +01:00
parent 708829b5a9
commit 3539e95f07
2 changed files with 7 additions and 4 deletions

View file

@ -484,7 +484,7 @@ chunkpack getWholeChunk(){
if (!clean){gwc_complete.data = 0; clean = true;}//prevent brain damage if (!clean){gwc_complete.data = 0; clean = true;}//prevent brain damage
chunkpack * ret = 0; chunkpack * ret = 0;
scrubChunk(gwc_complete); scrubChunk(gwc_complete);
while (counter < 10000){ while (counter < 1000){
gwc_next = getChunk(); gwc_next = getChunk();
ret = AddChunkPart(gwc_next); ret = AddChunkPart(gwc_next);
scrubChunk(gwc_next); scrubChunk(gwc_next);
@ -493,7 +493,7 @@ chunkpack getWholeChunk(){
free(ret);//cleanup returned chunk free(ret);//cleanup returned chunk
return gwc_complete; return gwc_complete;
} }
if (socketError){break;} if (socketError || socketBlocking){break;}
counter++; counter++;
} }
gwc_complete.msg_type_id = 0; gwc_complete.msg_type_id = 0;

View file

@ -9,6 +9,7 @@
#include <fcntl.h> #include <fcntl.h>
bool socketError = false; bool socketError = false;
bool socketBlocking = false;
int DDV_OpenUnix(const char adres[], bool nonblock = false){ int DDV_OpenUnix(const char adres[], bool nonblock = false){
int s = socket(AF_UNIX, SOCK_STREAM, 0); int s = socket(AF_UNIX, SOCK_STREAM, 0);
@ -67,11 +68,12 @@ int DDV_Accept(int sock, bool nonblock = false){
bool DDV_write(void * buffer, int todo, int sock){ bool DDV_write(void * buffer, int todo, int sock){
int sofar = 0; int sofar = 0;
socketBlocking = false;
while (sofar != todo){ while (sofar != todo){
int r = send(sock, (char*)buffer + sofar, todo-sofar, 0); int r = send(sock, (char*)buffer + sofar, todo-sofar, 0);
if (r <= 0){ if (r <= 0){
switch (errno){ switch (errno){
case EWOULDBLOCK: printf("Would block\n"); break; case EWOULDBLOCK: printf("Would block\n"); socketBlocking = true; break;
default: default:
socketError = true; socketError = true;
printf("Could not write! %s\n", strerror(errno)); printf("Could not write! %s\n", strerror(errno));
@ -86,11 +88,12 @@ bool DDV_write(void * buffer, int todo, int sock){
bool DDV_read(void * buffer, int todo, int sock){ bool DDV_read(void * buffer, int todo, int sock){
int sofar = 0; int sofar = 0;
socketBlocking = false;
while (sofar != todo){ while (sofar != todo){
int r = recv(sock, (char*)buffer + sofar, todo-sofar, 0); int r = recv(sock, (char*)buffer + sofar, todo-sofar, 0);
if (r <= 0){ if (r <= 0){
switch (errno){ switch (errno){
case EWOULDBLOCK: printf("Read: Would block\n"); break; case EWOULDBLOCK: printf("Read: Would block\n"); socketBlocking = true; break;
default: default:
socketError = true; socketError = true;
printf("Could not read! %s\n", strerror(errno)); printf("Could not read! %s\n", strerror(errno));