Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

problems reading 0 byte from a socket and writing it to a file

2 réponses
Avatar
polustanislas
hello when i receive the 0 byte from the network my program stops...
could you help me please. here is parts of my code :

:--------------main function ----------------------:

ofstream * writepersist = new ofstream
((userpath+newid).c_str(),ios::out|ios::app|ios::binary);

int size = 0;
char c;
while((int)(c=getchar(s))!=0)
{
writepersist->put(c);
size++;
}

:----------------getchar implementation--------------:


char netaction::getchar(int s)
{
char c;
int error=0;
int err;
while(1)
{
getsockopt(s,SOL_SOCKET,SO_ERROR,(char*)&err,(unsigned
int*)sizeof(err));
if(read(s,&c,1)==1) break;
if(errno!=0) {error = 1; break; }
}
if(error==1)
{
shutdown(s,2);
close(s);
exit(0);
}
return c;
}


:--------------------------:


thank you for your help

2 réponses

Avatar
polustanislas
désolé d'avoir écrit en anglais...

lorsque je lis 0 caractère oui c'est pas initialisé mais je n'essaye
pas de l'utiliser... mon problème arrive quand je recois la valeur 0
que j'ai envoyé depuis un client

(Stanislas) wrote in message news:...
hello when i receive the 0 byte from the network my program stops...
could you help me please. here is parts of my code :

:--------------main function ----------------------:

ofstream * writepersist = new ofstream
((userpath+newid).c_str(),ios::out|ios::app|ios::binary);

int size = 0;
char c;
while((int)(c=getchar(s))!=0)
{
writepersist->put(c);
size++;
}

:----------------getchar implementation--------------:


char netaction::getchar(int s)
{
char c;
int error=0;
int err;
while(1)
{
getsockopt(s,SOL_SOCKET,SO_ERROR,(char*)&err,(unsigned
int*)sizeof(err));
if(read(s,&c,1)==1) break;
if(errno!=0) {error = 1; break; }
}
if(error==1)
{
shutdown(s,2);
close(s);
exit(0);
}
return c;
}


:--------------------------:


thank you for your help


Avatar
Ahmed MOHAMED ALI
Bonjour,


char c;
if(read(s,&c,1)==1) break;
...

return c;
Vous lisez 1 char.Lorsque vous recevez 0 char.Que contient c ? Il n'est pas
initialisé.

Vous aurez de meilleures réponses si vous posez votre question sur un news
groupe qui traite de la programation réseau.

Ahmed

"Stanislas" wrote in message
news:
hello when i receive the 0 byte from the network my program stops...
could you help me please. here is parts of my code :

:--------------main function ----------------------:

ofstream * writepersist = new ofstream
((userpath+newid).c_str(),ios::out|ios::app|ios::binary);

int size = 0;
char c;
while((int)(c=getchar(s))!=0)
{
writepersist->put(c);
size++;
}

:----------------getchar implementation--------------:


char netaction::getchar(int s)
{
char c;
int error=0;
int err;
while(1)
{
getsockopt(s,SOL_SOCKET,SO_ERROR,(char*)&err,(unsigned
int*)sizeof(err));
if(read(s,&c,1)==1) break;
if(errno!=0) {error = 1; break; }
}
if(error==1)
{
shutdown(s,2);
close(s);
exit(0);
}
return c;
}


:--------------------------:


thank you for your help