Pthread-ed filetransfer application crash
Posted
by
N.R.S.Sowrabh
on Stack Overflow
See other posts from Stack Overflow
or by N.R.S.Sowrabh
Published on 2011-02-13T15:21:17Z
Indexed on
2011/02/13
15:25 UTC
Read the original article
Hit count: 289
I am developing a file transfer application and am using pthreads on the receiver side for receiving multiple files.
The function which is passed to pthreads calls the following function and at the end of this function I get a SIGABRT error and stack-smashing error appears on the terminal.
Please help me find the bugs. If you need anymore code I'd be able to post the same. Thanks in advance.
void recv_mesg(int new_sockid, char *fname)
{
cout<<"New Thread created with "<<new_sockid<<" and "<<fname<<endl;
char buf[MAXLINE];
int fd;
fd = open(fname, O_WRONLY );
int len =0;
while (len<1024)
{
int curr = recv(new_sockid, buf, 1024-len, 0);
//fprintf(stdout,"Message from Client:\n");
len += curr;
//write (fd, buf, curr);
fputs(buf, stderr);
}
int file_size = 0;
sscanf(buf,"%d",&file_size);
if(file_size<=0)
perror("File Size < 0");
sprintf(buf,"Yes");
send(new_sockid,buf,strlen(buf),0);
len = 0;
while (len<file_size)
{
int curr = recv(new_sockid, buf, min(file_size-len,MAXLINE), 0);
len += curr;
write (fd, buf, curr);
//fputs(buf, stdout);
//fflush(stdout);
}
len = 0;
close(fd);
close(new_sockid);
}
© Stack Overflow or respective owner