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