 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Stanislas Guest
|
Posted: Mon Mar 28, 2005 2:18 pm Post subject: problems reading 0 byte from a socket and writing it to a fi |
|
|
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
|
|
| Back to top |
|
 |
Stanislas Guest
|
Posted: Mon Mar 28, 2005 10:08 pm Post subject: Re: problems reading 0 byte from a socket and writing it to |
|
|
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
[email]polustanislas (AT) hotmail (DOT) com[/email] (Stanislas) wrote in message news:<744a1eb5.0503280618.2ffce43f (AT) posting (DOT) google.com>...
| Quote: | 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
|
|
|
| Back to top |
|
 |
Ahmed MOHAMED ALI Guest
|
Posted: Mon Mar 28, 2005 11:42 pm Post subject: Re: problems reading 0 byte from a socket and writing it to |
|
|
Bonjour,
| Quote: | 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" <polustanislas (AT) hotmail (DOT) com> wrote
| Quote: | 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
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|