00001 // Copyright (c) Xerox Corporation 1998. All rights reserved. 00002 // 00003 // License is granted to copy, to use, and to make and to use derivative 00004 // works for research and evaluation purposes, provided that Xerox is 00005 // acknowledged in all documentation pertaining to any such copy or 00006 // derivative work. Xerox grants no other licenses expressed or 00007 // implied. The Xerox trade name should not be used in any advertising 00008 // without its written permission. 00009 // 00010 // XEROX CORPORATION MAKES NO REPRESENTATIONS CONCERNING EITHER THE 00011 // MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE 00012 // FOR ANY PARTICULAR PURPOSE. The software is provided "as is" without 00013 // express or implied warranty of any kind. 00014 // 00015 // These notices must be retained in any copies of any part of this 00016 // software. 00017 // 00018 // $Header: /nfs/jade/vint/CVSROOT/ns-2/webcache/tcpapp.h,v 1.14 1999/08/24 04:16:29 haoboy Exp $ 00019 // 00020 // TcpApp - Transmitting real application data via TCP 00021 // 00022 // XXX Model a TCP connection as a FIFO byte stream. It shouldn't be used 00023 // if this assumption is violated. 00024 00025 #ifndef ns_tcpapp_h 00026 #define ns_tcpapp_h 00027 00028 #include "ns-process.h" 00029 #include "app.h" 00030 00031 class CBuf { 00032 public: 00033 CBuf(AppData *c, int nbytes); 00034 ~CBuf() { 00035 if (data_ != NULL) 00036 delete data_; 00037 } 00038 AppData* data() { return data_; } 00039 int size() { return size_; } 00040 int bytes() { return nbytes_; } 00041 00042 #ifdef TCPAPP_DEBUG 00043 // debug only 00044 double& time() { return time_; } 00045 #endif 00046 00047 protected: 00048 friend class CBufList; 00049 AppData *data_; 00050 int size_; 00051 int nbytes_; // Total length of this transmission 00052 CBuf *next_; 00053 00054 #ifdef TCPAPP_DEBUG 00055 // for debug only 00056 double time_; 00057 #endif 00058 }; 00059 00060 // A FIFO queue 00061 class CBufList { 00062 public: 00063 #ifdef TCPAPP_DEBUG 00064 CBufList() : head_(NULL), tail_(NULL), num_(0) {} 00065 #else 00066 CBufList() : head_(NULL), tail_(NULL) {} 00067 #endif 00068 ~CBufList(); 00069 00070 void insert(CBuf *cbuf); 00071 CBuf* detach(); 00072 00073 protected: 00074 CBuf *head_; 00075 CBuf *tail_; 00076 #ifdef TCPAPP_DEBUG 00077 int num_; 00078 #endif 00079 }; 00080 00081 00082 class TcpApp : public Application { 00083 public: 00084 TcpApp(Agent *tcp); 00085 ~TcpApp(); 00086 00087 virtual void recv(int nbytes); 00088 virtual void send(int nbytes, AppData *data); 00089 00090 void connect(TcpApp *dst) { dst_ = dst; } 00091 00092 virtual void process_data(int size, AppData* data); 00093 virtual AppData* get_data(int&, AppData*) { 00094 // Not supported 00095 abort(); 00096 return NULL; 00097 } 00098 00099 // Do nothing when a connection is terminated 00100 virtual void resume(); 00101 00102 protected: 00103 virtual int command(int argc, const char*const* argv); 00104 CBuf* rcvr_retrieve_data() { return cbuf_.detach(); } 00105 00106 // We don't have start/stop 00107 virtual void start() { abort(); } 00108 virtual void stop() { abort(); } 00109 00110 TcpApp *dst_; 00111 CBufList cbuf_; 00112 CBuf *curdata_; 00113 int curbytes_; 00114 }; 00115 00116 #endif // ns_tcpapp_h
1.3.3