Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
C programming calling read in a loop?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
methodtwo
Apprentice
Apprentice


Joined: 01 Feb 2008
Posts: 231

PostPosted: Mon May 27, 2013 11:10 pm    Post subject: C programming calling read in a loop? Reply with quote

Hi
I did have a question but the answer was so obvious that i think that i shouldn't have asked the question. I'm too embarrassed to keep the question up here. I'm very sorry i will try my best to post with more fore-thought in future. Very sorry
regards
Back to top
View user's profile Send private message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1611
Location: U.S.A.

PostPosted: Wed May 29, 2013 4:23 am    Post subject: Reply with quote

methodtwo wrote:
Hi
I did have a question but the answer was so obvious that i think that i shouldn't have asked the question. I'm too embarrassed to keep the question up here. I'm very sorry i will try my best to post with more fore-thought in future. Very sorry
regards

Shame on you. :P

For your future information, you can delete posts (just log in, and click that little [x] in the upper right hand corner of the post), and if the post is the only post in the thread, this will delete the entire thread.

Unfortunately, a side-effect of my telling you this is that you can no longer delete this thread. So now it's trapped here on the Internet, forever and ever.
_________________
patrix_neo wrote:
The human thought: I cannot win.
The ratbrain in me : I can only go forward and that's it.
Back to top
View user's profile Send private message
wcg
Guru
Guru


Joined: 06 Jan 2009
Posts: 588

PostPosted: Thu May 30, 2013 8:30 am    Post subject: Reply with quote

Now that you have removed the orignal question, I was wondering
why you were not immediately testing the return value of send()
for error. Do send() errors not matter to the logic of your program,
meaning there is nothing that it should do differently if it finds out
that a send() failed?

(pseudo-code)
Code:

 if (send_result < 0) {
    local_err = errno;  /* minimize the risk of a signal handler changing the value of errno */
    switch (local_err) {
        case (ENOTCONN):
            do_this;
        case (ENOMEM):
            do_that;
        case (EWHATEVER):
            do_whatever;
        default:
             catchall_misc_error_handler;
      }
  }


Code with error handling like this can seem cluttered, but it can seriously
shorten debugging time when your program does not behave as expected.
Often it is convenient to put something like this in an error handling function,
annotate it as "noinline", and then you only have the code to call that
function inline in your code, instead of the switch{} code itself (reduces the
impact of error handling on icache).
_________________
TIA
Back to top
View user's profile Send private message
methodtwo
Apprentice
Apprentice


Joined: 01 Feb 2008
Posts: 231

PostPosted: Fri May 31, 2013 6:40 pm    Post subject: Reply with quote

Thanks very much for your reply. I'm sorry if you don't get to see this response. I've only just noticed your reply. Yes you are right. I should look at the return value from send() because the send is to notify the client that that i'm accepting window size changes on the server that the client can send when the pseudo term window size at the client end changes. So yes you're absolutely right matie!
Erm if you do see this i was wondering if you'd answer another question about my program? I'll just wait for you to answer yes or no to that so that i don't post the question on this thread unless you specifically don't mind answering it. I promise that it's much more interesting than the question from the first post of this thread!
TIA regards
Back to top
View user's profile Send private message
wcg
Guru
Guru


Joined: 06 Jan 2009
Posts: 588

PostPosted: Sat Jun 01, 2013 3:43 pm    Post subject: Reply with quote

Well, I might not have the answer, or I might not have the right answer,
or what I think would be the right answer would involve such a large
restructuring of your code that you do not think it is the right answer
even if it could work. I also read the list at rather irregular intervals
(when I have the time and inclination to do so), so I might not see it
anytime soon.

For C questions (is this correct C? more or less), I would guess that
comp.lang.c.moderated (Usenet newsgroup) would be the right forum
to ask on, because those are the kinds of questions many expert readers
of that forum are accustomed to answering, and among the answers
that you get, at least one is usually dead on right. (If your ISP does not
have Usenet, there is always Google Groups.)

For unix programming kinds of questions, here is probably as good a place
as any, but "helping people with their homework" is kind of frowned on
in linux distribution forums, so you may not get enough responses to
separate the usable from the useless if people see this as a likely school
project.

The best response is often "well, what does this program from package xyz
do in that situation?" (Ie, "read the source, Luke" and hope the source is in
a programming language that you know).
_________________
TIA
Back to top
View user's profile Send private message
wcg
Guru
Guru


Joined: 06 Jan 2009
Posts: 588

PostPosted: Sun Jun 02, 2013 2:25 pm    Post subject: Reply with quote

PS: While *unmoderated* Usenet newsgroups frequently have
intolerably low signal-to-noise ratios, the comp.unix.programmer
faqs may still be useful:
http://www.faqs.org/faqs/unix-faq/programmer/faq/
http://www.faqs.org/faqs/unix-faq/socket/
_________________
TIA
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
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