| @@ -31,6 +31,10 @@ | |||||
| #include <sys/select.h> | #include <sys/select.h> | ||||
| /* Generic TCP server class */ | /* Generic TCP server class */ | ||||
| /* */ | |||||
| #define MAX_HOST_NAME 512 | #define MAX_HOST_NAME 512 | ||||
| /** open a socket listening on TCP port /port/. Returns -1 in case of error. */ | /** open a socket listening on TCP port /port/. Returns -1 in case of error. */ | ||||
| @@ -154,21 +158,23 @@ Server::run ( void ) | |||||
| } | } | ||||
| else | 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'; | buf[ l ] = '\0'; | ||||
| handle_request( buf, l ); | |||||
| handle_request( i, buf, l ); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -31,7 +31,9 @@ public: | |||||
| protected: | protected: | ||||
| virtual bool echos ( void ) { return true; } | |||||
| virtual void handle_hang_up ( int s ) = 0; | virtual void handle_hang_up ( int s ) = 0; | ||||
| virtual void handle_new ( 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; | |||||
| }; | }; | ||||
| @@ -26,6 +26,8 @@ | |||||
| #include "Timeline_Server.H" | #include "Timeline_Server.H" | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <string.h> | |||||
| #include <sys/socket.h> | |||||
| /* Timeline Server. | /* Timeline Server. | ||||
| @@ -65,7 +67,9 @@ Timeline_Server::handle_hang_up ( int s ) | |||||
| } | } | ||||
| void | 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 ); | |||||
| } | } | ||||
| @@ -28,7 +28,7 @@ protected: | |||||
| void handle_new ( int s ); | void handle_new ( int s ); | ||||
| void handle_hang_up ( 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: | public: | ||||