LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Closed Thread
  Search this Thread
Old 09-17-2012, 03:09 AM   #1
gajananh999
Member
 
Registered: Aug 2012
Posts: 94

Rep: Reputation: Disabled
Cool read(newsockfd buffer to read) sometimes getting struck


Hello Everyone,

I have written socket programming in c++.
some times my read will get strucked.

Code:

void handlesocket(int newsockfd)
{
        char *buffer, *temp, *temp2;
        int n,i;
        int readNow, toRead;
        if (newsockfd < 0)
                error("ERROR on accept");

        buffer = new char[960000];
        temp = new char[16];
        temp[0] = '\0';
        temp2 = new char[1];
        temp2[0] = '\0';
        i = 0;
        do
        {
                n = read(newsockfd,temp2, 1);
                if(temp2[0]=='@') break;
                temp[i++] = temp2[0];
                temp[i] = '\0';
        }
        while(n > 0);

        n = 0;
        do
        {
                buffer[0] = '\0';
                toRead = atoi(temp) - n;
          printf("ready to read\n ToRead=%d\n",toRead);
          //Sometime strucking at this next line
             readNow = read(newsockfd,buffer,toRead);
                printf("ReadNow is %d\n",readNow);
                if(readNow < 0) break;
                n += readNow;
                printf("ISAC %d --- %d --- %d\n",atoi(temp),n,readNow);
                buffer[readNow] = '\0';
                writeintofile(buffer);
        }
        while(n < atoi(temp));
  close(newsockfd);
        free(buffer);
        free(temp);
        free(temp2);
}

Please help me out...
 
Old 09-17-2012, 03:20 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

http://www.linuxquestions.org/questi...ck-4175427589/

Last edited by Tinkster; 09-17-2012 at 05:06 PM.
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
read(newsockfd, buffer ,to read) sometimes getting struck gajananh999 Linux - Newbie 1 09-17-2012 11:51 AM
how to read from the stderr and stdout buffer? omega341991 Linux - Newbie 1 06-08-2012 04:54 AM
How to read buffer in C? obladioblada Programming 19 02-05-2009 06:24 PM
buffer i/o read error from hdd fakie_flip Linux - Software 4 08-21-2006 12:26 AM
read from tty buffer vineeth789 Programming 1 01-12-2006 11:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration