LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-03-2004, 10:14 PM   #1
zer0python
Member
 
Registered: Sep 2003
Posts: 104

Rep: Reputation: 20
Set/Unset Non-Blocking sockets?


I am working on an irc bot (big suprise?) and I need to set/unet non blocking sockets, I know how to set it with:

Code:
// ...

int sd, v;

// ...

v = fcntl(sd, F_GETFD, 0);
fcntl(sd, F_SETFD, v | O_NONBLOCK);

// ...
Anyway, any help would be appreciated
 
Old 01-04-2004, 12:43 AM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
since you have the previous flags saved in the variable v, all you have to do is:
fcntl(sd, F_SETFD, v);

but as an aside, lets say you had done this:

v = fcntl(sd, F_GETFD, 0);
v |= O_NONBLOCK;

now if you wanted to remove the nonblocking flag from v, you would go

v &= ~O_NONBLOCK

that would clear the O_NONBLOCK flag. remember flags are just bits that
have been "turned on", meaning set to 1. to turn off a bit you just set it back to 0.
the '~' complements O_NONBLOCK, setting all the bits that were 0 to 1, and the
bits that were 1 to 0. then when you '&=' it with v this has the effect of setting
the bit in v for O_NONBLOCK to 0.
 
Old 01-04-2004, 02:31 AM   #3
zer0python
Member
 
Registered: Sep 2003
Posts: 104

Original Poster
Rep: Reputation: 20
-sighs-, I knew it was something like that, and why I didn't think to just use v, I don't know, anyway thanks.. Though, I found that the problem was not from the ``blocking'' sockets... so back to the drawing board.
 
  


Reply


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
Problem w/ sockets, fdopen, and blocking. 95se Programming 3 11-17-2005 01:38 PM
Non blocking sockets in Perl ivanatora Programming 3 08-19-2005 03:14 AM
how to set sockets as nonblock cranium2004 Programming 2 03-20-2005 01:02 AM
Unset praveenv Linux - Newbie 1 09-14-2004 06:37 PM
how to unset cflags? shanenin Linux - Software 4 01-25-2004 10:36 PM


All times are GMT -5. The time now is 01:45 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration