LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-23-2004, 05:14 AM   #1
cynthia
LQ Newbie
 
Registered: Sep 2004
Posts: 20

Rep: Reputation: 0
errno


my code contains the lines

x=recv(...)
if(errno = WOULD_BLOCK)...

I want to avoid a situation that in this line errno will get a value from previous calls to recv().

how can I prevent such a mistake from happening?

do I need to flush error que in order to avoid that situation?
 
Old 09-23-2004, 05:26 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
Re: errno

Quote:
Originally posted by cynthia
my code contains the lines

x=recv(...)
if(errno = WOULD_BLOCK)...

I want to avoid a situation that in this line errno will get a value from previous calls to recv().

how can I prevent such a mistake from happening?

do I need to flush error que in order to avoid that situation?
First off, you are assigning the value WOULD_BLOCK to errno, which is an error. (Note that errno can be implemented as a macro).

According to the standard, the only correct way to use errno is to set its value to 0 prior to a procedure call, and then test its value afterwards:
Code:
errno = 0;
x=recv(…);
if (errno == WOULD_BLOCK) …
Standard C does not implement an error “queue” that can be flushed as far as I am aware.

Hope that helps,

— Robert J. Lee
 
Old 09-23-2004, 07:39 AM   #3
cynthia
LQ Newbie
 
Registered: Sep 2004
Posts: 20

Original Poster
Rep: Reputation: 0
that assignment works fine for UNIX. how about WINDOWS? there they call function and not using a variable?

would that function empy the queue?

Last edited by cynthia; 09-23-2004 at 07:41 AM.
 
Old 09-24-2004, 01:58 PM   #4
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
The Microsoft Windows C library extensions may well define an error queue but standard C does not.

That code will work fine in any standard C compiler, regardless of the platform. If it doesn't work in Microsoft's C compiler, then it isn't a standards-complient C compiler. In which case, my best advice is to upgrade.
 
  


Reply



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
under HP-UX, why errno is always 0 in a thread? iclinux Programming 8 10-21-2014 04:58 AM
MySQL, errno 13 Ephracis Linux - Software 1 01-02-2005 07:11 PM
How to use errno sibtay Programming 4 09-24-2004 09:38 AM
errno.h, but it IS declared...... privateprimate Linux - Software 3 09-08-2004 07:37 PM
apache died HELP (errno:13) rob_roman23 Linux - General 4 09-03-2003 06:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:17 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