Browse Source

Continue work on Server base class.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
fda03b174a
4 changed files with 26 additions and 14 deletions
  1. +16
    -10
      Engine/Server.C
  2. +3
    -1
      Engine/Server.H
  3. +6
    -2
      Engine/Timeline_Server.C
  4. +1
    -1
      Engine/Timeline_Server.H

+ 16
- 10
Engine/Server.C View File

@@ -31,6 +31,10 @@
#include <sys/select.h>

/* Generic TCP server class */

/* */


#define MAX_HOST_NAME 512

/** open a socket listening on TCP port /port/. Returns -1 in case of error. */
@@ -154,21 +158,23 @@ Server::run ( void )
}
else
{
/* echo to others */
for ( int j = maxfd; j-- ; )
{
if ( ! FD_ISSET( j, &master ) )
continue;

if ( j != server && j != i )
if ( echos() )
/* echo to others */
for ( int j = maxfd; j-- ; )
{
if ( send( j, buf, l, 0 ) < 0 )
perror( "send()" );
if ( ! FD_ISSET( j, &master ) )
continue;

if ( j != server && j != i )
{
if ( send( j, buf, l, 0 ) < 0 )
perror( "send()" );
}
}
}

buf[ l ] = '\0';
handle_request( buf, l );
handle_request( i, buf, l );
}
}
}


+ 3
- 1
Engine/Server.H View File

@@ -31,7 +31,9 @@ public:

protected:

virtual bool echos ( void ) { return true; }

virtual void handle_hang_up ( int s ) = 0;
virtual void handle_new ( int s ) = 0;
virtual void handle_request ( const char *s, int l ) = 0;
virtual void handle_request ( int s, const char *s, int l ) = 0;
};

+ 6
- 2
Engine/Timeline_Server.C View File

@@ -26,6 +26,8 @@
#include "Timeline_Server.H"

#include <stdio.h>
#include <string.h>
#include <sys/socket.h>

/* Timeline Server.

@@ -65,7 +67,9 @@ Timeline_Server::handle_hang_up ( int s )
}

void
Timeline_Server::handle_request ( const char *s, int l )
Timeline_Server::handle_request ( int s, const char *buf, int l )
{
printf( "request: %s", s );
printf( "request: %s", buf );

send( s, "fuckoff\n", strlen( "fuckoff\n" ), 0 );
}

+ 1
- 1
Engine/Timeline_Server.H View File

@@ -28,7 +28,7 @@ protected:

void handle_new ( int s );
void handle_hang_up ( int s );
void handle_request ( const char *s, int l );
void handle_request ( int s, const char *s, int l );

public:



Loading…
Cancel
Save