?writing bug in a multi-process Linux server application?

This is a discussion on ?writing bug in a multi-process Linux server application? within the C Programming forums, part of the General Programming Boards category; I am trying to write a concurrent web server for Linux. I am doing this just for fun (I am ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    5

    ?writing bug in a multi-process Linux server application?

    I am trying to write a concurrent web server for Linux. I am doing this just for fun (I am not trying to match IIS or Apache). My actual program is quite large so I will only post some highlights.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: ?writing bug in a multi-process Linux server application?

    Originally posted by Arrummzen
    I am trying to write a concurrent web server for Linux. I am doing this just for fun (I am not trying to match IIS or Apache). My actual program is quite large so I will only post some highlights.
    Is this just an informative post, or is there some purpose?

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    5
    Code:
     
    void HTTPserver ( int socket , int IPCout , int IPCin )
    {
      fprintf ( stderr , " the HTTP server is up! \n " );
    
      struct sockaddr_in HTTPSocketRemote;
      socklen_t SockInSize;
      int ClientSocket;
      SockInSize = sizeof ( sockaddr_in );
    
      fd_set read_fds;
      struct timeval tv;
      int ret=0;
      FD_ZERO(&read_fds);
      FD_SET(socket , &read_fds); /*listen_sock is socket where are you listening*/
      FD_SET(IPCin , &read_fds);
    
      tv.tv_sec = 30;
      tv.tv_usec = 0;
    
      while ( 1 )
      {
         ret = select(socket+1, &read_fds, NULL, NULL, &tv);
         if( FD_ISSET ( socket , &read_fds ) )
         {
          ClientSocket = accept ( socket ,  ( struct sockaddr *)&HTTPSocketRemote , &SockInSize  );
          switch ( fork ( ) )
          {
          case 0: // This is the child proccess
            close ( socket );
            close ( IPCout );
            close ( IPCin );
            HTTPdeamon ( ClientSocket );
            break;
          default:  // this is the parrent proccess
            close ( ClientSocket );
            break;
          }
         }
      }
    }
    --------------------------------------------------------
    void HTTPdeamon ( int socket )
    {
      Awrite ( socket , " It works!! \ " );
      halt ( socket );
      close ( socket );
      exit ( 0 );
    }
    --------------------------------------------------------
    void halt ( int output )
    {
      int hold = 0;
      Awrite ( output , "Press Enter To Continue \n " );
      read ( output , &hold , 1 );
    }
    --------------------------------------------------------
    void Awrite ( int fd , char str[] )
    {
      write ( fd , str , sizeof ( str ) );
    }
    --------------------------------------------------------
    From what I can see this program runs fine. However when I connect with telnet to the HTTP port I only read 'it'. When I put the "Awrite ( socket , " It works!! \n " );" in a for loop it printed it it it it it. Once for ever iteration of the loop! Why did it not write It works!! \n It works!! \n It works!! \n It works!! \n It works!! \n?
    I hope you can help me.
    Thank you for your time,
    Arrummzen

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    5
    WOW quick response. No, I think something went wrong. The sever only posted part of my message.
    Thank you for your time,
    Arrummzen

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You might want to check your return values for write to make sure it's writing the entire block. Write is not guarinteed to write the whole block. It will return the number it was able to write. Commonly you want to use write in a loop to make sure it ends up writing the whole thing.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Dec 2002
    Posts
    5
    Thank you. Who would have thought it would be something as simple as that. I was expecting some big error in my multi-tasking error.
    Thank you for your time,
    Arrummzen

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    29
    This is not on topic of this thread but Arrummzen are you a common visitor to the HDC BBS?

  8. #8
    Registered User
    Join Date
    Dec 2002
    Posts
    5
    Yes, I visit the HDC BBS on a fairly regular basis.
    Thank you for your time,
    Arrummzen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bug listing application wanted..
    By BrownB in forum Tech Board
    Replies: 5
    Last Post: 02-08-2005, 02:33 AM
  2. Linux Server
    By Carp in forum C++ Programming
    Replies: 3
    Last Post: 01-24-2003, 01:52 PM
  3. turbo linux 6.0 server
    By xds4lx in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-02-2002, 10:21 PM
  4. Linux X server installation
    By Unregistered in forum Linux Programming
    Replies: 3
    Last Post: 01-18-2002, 01:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21