Thread: The Infinit loop that doesn't loop.

  1. #1
    Registered User errigour's Avatar
    Join Date
    Mar 2009
    Posts
    102

    The Infinit loop that doesn't loop.

    My question is, if you use an infinit loop what does your computer actually do conserning sockets.
    And if i'm correct about this how can I listen to connections and accept them without using an infinite
    loop, using the c programming langauge, and mayby using fcntl(). makes a connection not close I
    read but nim not sure how to actually use it yet but i dont like using infinie loops for something my
    computer isn't infinently looping. Id rather use something in the cprogram that commands what the
    computer actually does. You can leave out the fcntl part if its not required but i like the function
    because commands your computer to do something it does which is not close the connection.
    Now I'm wondering if my computer is capable of leaveing a connection open without using an
    infinite loop but if it can do it using a c programming infinite loop then how can i just leave a socket
    open and accepting connections.. My opinion, the accept function should and doesn't do just that.

    could anyone help me with this?
    Last edited by errigour; 11-09-2010 at 11:18 AM.

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    It's called multi-tasking. Your computer is capable of running things concurrently so you can have your infinite loop waiting for new connections in one thread and the actual communication with the sockets in another.

    I agree with you that infinite loops are not "elegant" but sometimes they are necessary, such as when you are waiting for an unknown number of connections. The trick is to control the loop and know when to break from it.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help with a loop
    By Darkw1sh in forum C Programming
    Replies: 19
    Last Post: 09-13-2009, 09:46 PM
  2. funny-looking while loop
    By Aisthesis in forum C++ Programming
    Replies: 3
    Last Post: 08-30-2009, 11:54 PM
  3. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  4. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM