// file name : tcpstream.h // written by Ee-Chien Chang //============================================================ // T C P _ S T R E A M //------------------------------------------------------------ // // maintain a iostream. // // include lossless compression //------------------------------------------------------------ // // //-------------- I M P O R T A N T ------------------------ // 1) POSSIBILITY for improvment? // reserve a large buffer size // 2) break the input/output stream into small pieces. //--------------------------------------------------------- #ifndef TCP_STREAM_H #define TCP_STREAM_H class tcp_Stream { public: tcp_Stream () { stream_fd = 0; COMPRESSION_TYPE = COMPRESS_NON; total_byte_read =0; total_byte_write=0; } tcp_Stream ( int fd ) { stream_fd = fd; total_byte_read =0; total_byte_write=0; } // ~tcp_Stream () {cout << "delete stream " // << stream_fd << endl; } int write_byte ( unsigned char * buffer, unsigned long nos_byte ); int write_int ( int ); int write_integers( int * buffer, long nos_int ); int write_string ( char * ); int read_int ( int *); int read_string (char *, int); int read_integers( int * buffer, long nos_int_to_be_read ); int read_byte ( unsigned char * buffer, unsigned long nos_byte ); // ::close refers to the original close () // the statement is redudent. // the stream should be close in the // main program which open it. // int close () {return ::close (stream_fd);} int stream_fd; unsigned long total_byte_read; unsigned long total_byte_write; int COMPRESSION_TYPE; const static int COMPRESS_NON = 0; const static int COMPRESS_LZW = 1; const static int COMPRESS_GZ = 2; }; #endif