diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-08-27 03:37:04 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-08-27 03:37:04 +0000 |
commit | 57445a91ddd4186e2b43892e88ced05abf21c15b (patch) | |
tree | ad2f213796e1bc368ce1ad7b3ec3428a3f5c7ca5 /apps | |
parent | 31cd8808cb8e200c0efb9bde1bb04649e7f07d55 (diff) | |
download | ATCD-57445a91ddd4186e2b43892e88ced05abf21c15b.tar.gz |
*** empty log message ***
Diffstat (limited to 'apps')
-rw-r--r-- | apps/JAWS/clients/Caching/ID_Generator.cpp | 21 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/ID_Generator.h | 12 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/Local_Locator.cpp | 32 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/Local_Locator.h | 9 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/Local_Locator.i | 7 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/Locator_Request_Reply.h | 28 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/URL_Locator.h | 13 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/URL_Properties.cpp | 28 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/URL_Properties.h | 41 | ||||
-rw-r--r-- | apps/JAWS/clients/Caching/http_handler.h | 17 |
10 files changed, 140 insertions, 68 deletions
diff --git a/apps/JAWS/clients/Caching/ID_Generator.cpp b/apps/JAWS/clients/Caching/ID_Generator.cpp index d6b8decd730..fa3e1cbe4be 100644 --- a/apps/JAWS/clients/Caching/ID_Generator.cpp +++ b/apps/JAWS/clients/Caching/ID_Generator.cpp @@ -6,15 +6,11 @@ #define ACE_BUILD_DLL #include "ID_Generator.h" -// #if !defined (__ACE_INLINE__) -// #include "ID_Generator.i" -// #endif /* __ACE_INLINE__ */ - time_t ACE_ID_Generator::last_time_ = 0; size_t ACE_ID_Generator::last_number_ = 0; -ACE_MT (ACE_SYNCH_MUTEX *ACE_ID_Generator::lock_ = 0;) +ACE_SYNCH_MUTEX *ACE_ID_Generator::lock_ = 0; char * ACE_ID_Generator::get_new_id (char *id) @@ -32,9 +28,9 @@ ACE_ID_Generator::get_new_id (char *id) void ACE_ID_Generator::get_serial_id (time_t &t, size_t &s) { - ACE_MT (ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, - *ACE_ID_Generator::get_lock ())); + ACE_MT (ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, *ACE_ID_Generator::get_lock ())); ACE_OS::time (&t); + if (t != ACE_ID_Generator::last_time_) { ACE_ID_Generator::last_time_ = t; @@ -44,19 +40,20 @@ ACE_ID_Generator::get_serial_id (time_t &t, size_t &s) s = ACE_ID_Generator::last_number_++; } -ACE_MT ( ACE_SYNCH_MUTEX * -ACE_ID_Generator::get_lock () +ACE_ID_Generator::get_lock (void) { +#if defined (ACE_HAS_THREADS) if (ACE_ID_Generator::lock_ == 0) { - ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, - *ACE_Static_Object_Lock::instance (), 0)); + ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, *ACE_Static_Object_Lock::instance (), 0)); + + // Double-checked Locking Optimization. if (ACE_ID_Generator::lock_ == 0) ACE_NEW_RETURN (ACE_ID_Generator::lock_, ACE_SYNCH_MUTEX, 0); } +#endif /* ACE_HAS_THREADS */ return ACE_ID_Generator::lock_; } - ) #endif /* ACE_ID_GENERATOR_C */ diff --git a/apps/JAWS/clients/Caching/ID_Generator.h b/apps/JAWS/clients/Caching/ID_Generator.h index 5fdb9c8ebdc..556ce8dbfde 100644 --- a/apps/JAWS/clients/Caching/ID_Generator.h +++ b/apps/JAWS/clients/Caching/ID_Generator.h @@ -23,6 +23,9 @@ #define ACE_OFFER_ID_LENGTH 21 class ACE_Export ACE_ID_Generator +// Nanbor, please make sure you use the official ACE "= TITLE" syntax +// here. Also, what is "beckry's algorithm?" Do you mean "Berkeley's +// algorithm?" // Generate an offer ID according to current time and // avoid duplicate ID. Using a similar method like // beckry's algorithm. @@ -30,11 +33,12 @@ class ACE_Export ACE_ID_Generator public: static char *get_new_id (char *id); // allocate a new ID string and point <id> to it. + private: static void get_serial_id (time_t &t, size_t &s); // Atomically get info required to generate an offer ID. - ACE_MT (static ACE_SYNCH_MUTEX *get_lock ();) + static ACE_SYNCH_MUTEX *get_lock (void); // Get the lock instance. static time_t last_time_; @@ -44,12 +48,8 @@ private: // Record serial number of last offer ID with same // generation time. - ACE_MT (static ACE_SYNCH_MUTEX *lock_;) + static ACE_SYNCH_MUTEX *lock_; // mutex to access private member. }; -// #if defined (__ACE_INLINE__) -// #include "ID_Generator.i" -// #endif /* __ACE_INLINE__ */ - #endif /* ACE_ID_GENERATOR_H */ diff --git a/apps/JAWS/clients/Caching/Local_Locator.cpp b/apps/JAWS/clients/Caching/Local_Locator.cpp index 784229471f1..66a879ea145 100644 --- a/apps/JAWS/clients/Caching/Local_Locator.cpp +++ b/apps/JAWS/clients/Caching/Local_Locator.cpp @@ -18,11 +18,14 @@ ACE_URL_Local_Locator::url_query (const ACE_URL_Locator::ACE_Selection_Criteria ACE_URL_Offer_Seq *offer) { ACE_URL_Record *item = 0; - ACE_NEW_RETURN (offer, ACE_URL_Offer_Seq (how_many), - ACE_URL_Locator::NOMEM); + + // Nanbor, do you really want to return NOMEM, or -1 (since errno + // will already be set to ENOMEM by the ACE_NEW_RETURN macro). + ACE_NEW_RETURN (offer, ACE_URL_Offer_Seq (how_many), ACE_URL_Locator::NOMEM); for (ACE_Unbounded_Stack_Iterator<ACE_URL_Record> iter (this->repository_); - iter.next (item) != 0; iter.advance ()) + iter.next (item) != 0; + iter.advance ()) { switch (how) { @@ -47,6 +50,10 @@ ACE_URL_Local_Locator::url_query (const ACE_URL_Locator::ACE_Selection_Criteria break; } + // Nanbor, I recommend just returning 0 for success and -1 for + // failure. That is more consistent with the rest of ACE. In + // general, it's a better idea to use errno to indicate *which* + // error occurred, and -1 to indicate to the caller to check errno. return ACE_URL_Locator::OK; } @@ -56,17 +63,22 @@ ACE_URL_Local_Locator::export_offer (ACE_URL_Offer *offer, { ACE_URL_Record *item = 0; - // First check if we have registered this url already. + // First check if we have registered this URL already. for (ACE_Unbounded_Stack_Iterator<ACE_URL_Record> iter (this->repository_); - iter.next (item) != 0; iter.advance ()) + iter.next (item) != 0; + iter.advance ()) if (*item->offer_->url () == *offer->url ()) + // Nanbor, here's a good example of where it might make more + // sense to set errno to EEXIST and return -1. return ACE_URL_Locator::OFFER_EXIST; ACE_URL_Record *new_offer; ACE_NEW_RETURN (new_offer, ACE_URL_Record (offer), ACE_URL_Locator::NOMEM); + this->repository_.push (*new_offer); + offer_id = *new_offer->id_; return ACE_URL_Locator::OK; } @@ -76,8 +88,10 @@ ACE_URL_Local_Locator::withdraw_offer (const ACE_WString &offer_id) { ACE_URL_Record *item = 0; + // Nanbor, please make sure that you comment code like this. for (ACE_Unbounded_Stack_Iterator<ACE_URL_Record> iter (this->repository_); - iter.next (item) != 0; iter.advance ()) + iter.next (item) != 0; + iter.advance ()) if (offer_id == *item->id_) { if (this->repository_.remove (*item) == 0) @@ -85,6 +99,7 @@ ACE_URL_Local_Locator::withdraw_offer (const ACE_WString &offer_id) else return ACE_URL_Locator::UNKNOWN; } + return ACE_URL_Locator::NO_SUCH_OFFER; } @@ -94,14 +109,17 @@ ACE_URL_Local_Locator::describe_offer (const ACE_WString &offer_id, { ACE_URL_Record *item = 0; + // Nanbor, please make sure that you comment this code. for (ACE_Unbounded_Stack_Iterator<ACE_URL_Record> iter (this->repository_); - iter.next (item) != 0; iter.advance ()) + iter.next (item) != 0; + iter.advance ()) if (offer_id == *item->id_) { ACE_NEW_RETURN (offer, ACE_URL_Offer (*item->offer_), ACE_URL_Locator::NOMEM); return ACE_URL_Locator::OK; } + return ACE_URL_Locator::NO_SUCH_OFFER; } diff --git a/apps/JAWS/clients/Caching/Local_Locator.h b/apps/JAWS/clients/Caching/Local_Locator.h index a0e303866bb..0c85c6d5425 100644 --- a/apps/JAWS/clients/Caching/Local_Locator.h +++ b/apps/JAWS/clients/Caching/Local_Locator.h @@ -33,6 +33,8 @@ class ACE_URL_Record // out of scope. { friend class ACE_URL_Local_Locator; + // Nanbor, is it really necessary to have ACE_Node<> as a friend? + // That seems like it breaks encapsulation. friend class ACE_Node<ACE_URL_Record>; public: ACE_URL_Record (ACE_URL_Offer *offer); @@ -46,15 +48,17 @@ public: int operator!= (const ACE_URL_Record &rhs) const; // Unequal, complement of equal. + private: ACE_URL_Record (void); + // Nanbor, please explain why this is private. // default ctor. ACE_WString *id_; // Offer ID in the repository. ACE_URL_Offer *offer_; - // Offer (and its properties.) + // Offer (and its properties). }; class ACE_Export ACE_URL_Local_Locator @@ -95,8 +99,11 @@ class ACE_Export ACE_URL_Local_Locator const ACE_URL_Property_Seq *del = 0, const ACE_URL_Property_Seq *modify = 0); // Modify a previously registered offer. + protected: ACE_Unbounded_Stack<ACE_URL_Record> repository_; + // Nanbor, please add a comment here. In particular, why do you use + // a stack rather than, e.g., a set? }; #if defined (__ACE_INLINE__) diff --git a/apps/JAWS/clients/Caching/Local_Locator.i b/apps/JAWS/clients/Caching/Local_Locator.i index f974e1b2c31..1d693472eb8 100644 --- a/apps/JAWS/clients/Caching/Local_Locator.i +++ b/apps/JAWS/clients/Caching/Local_Locator.i @@ -28,16 +28,13 @@ ACE_URL_Record::~ACE_URL_Record (void) ACE_INLINE int ACE_URL_Record::operator== (const ACE_URL_Record &rhs) const { - if (this == &rhs || *this->id_ == *rhs.id_) - return 1; - else - return 0; + return this == &rhs || *this->id_ == *rhs.id_; } ACE_INLINE int ACE_URL_Record::operator!= (const ACE_URL_Record &rhs) const { - return ! (*this == rhs); + return !(*this == rhs); } ACE_INLINE diff --git a/apps/JAWS/clients/Caching/Locator_Request_Reply.h b/apps/JAWS/clients/Caching/Locator_Request_Reply.h index a6036fc7586..cc53f593b9d 100644 --- a/apps/JAWS/clients/Caching/Locator_Request_Reply.h +++ b/apps/JAWS/clients/Caching/Locator_Request_Reply.h @@ -21,6 +21,7 @@ #include "URL_Properties.h" class ACE_Export ACE_URL_Locator_Request +// Nanbor, please make sure you explain what this class is *used* for! // = TITLE // A URL request message formater/wrapper. // @@ -74,6 +75,24 @@ public: const ACE_URL_Property_Seq &modify = 0); // Modify a previously registered offer. +<<<<<<< Locator_Request_Reply.h + int encode (void); + // Encode request for network communication. + + int decode (void); + // Restore from network data. + + // = A bunch of methods to access internal data. + int how (void); + int how_many (void); + ACE_URL_Property_Seq &seq (void); + ACE_URL_Property_Seq &del (void); + ACE_URL_Property_Seq &modify (void); + ACE_WString &id (void); + ACE_WString &url (void); + void *buffer (void); + +======= size_t encode (void); // Encode request for network communication. If succeed, // returns the size of the buffer, otherwise, return 0. @@ -95,14 +114,17 @@ public: void dump (void); // Print out this object. + protected: + u_int code_; + // Request type code. + + // Nanbor, please make sure that you comment all of these data + // members. size_t bsize (void) const; // Return the size of buffer required to encode // this request. - unsigned int code_; - // Request type code. - int how_; int how_many_; ACE_URL_Property_Seq *seq1_; diff --git a/apps/JAWS/clients/Caching/URL_Locator.h b/apps/JAWS/clients/Caching/URL_Locator.h index ffa9aa5e406..d7b0a616f7d 100644 --- a/apps/JAWS/clients/Caching/URL_Locator.h +++ b/apps/JAWS/clients/Caching/URL_Locator.h @@ -27,8 +27,13 @@ class ACE_Export ACE_URL_Locator // // = DESCRIPTION // This class defines the basic URL_Locator APIs. +// Nanbor, please make sure that you explain more about what a URL +// Locator is in the description here. { public: + + // = Specify how to select offers. + // Nanbor, please add comments to each of these enumerals. enum ACE_Selection_Criteria { NONE, @@ -36,9 +41,11 @@ public: ALL, INVALID_SELECTION }; - // Specify how to select offers. enum ACE_URL_Locator_Error + // Nanbor, I don't think that you need to use this enum. I + // recommend that you return -1 from methods that fail and set + // errno accordingly. { OK = 0, // everything's OK so far. OFFER_EXIST, // trying to register an offer. @@ -84,7 +91,9 @@ public: virtual char *error_status (void); // Provide a human readable error status. - + // Nanbor, please make sure that you explain who is responsible for + // the memory returned from this method. Also, I recommend that you + // make this return a *const* char *. }; #if defined (__ACE_INLINE__) diff --git a/apps/JAWS/clients/Caching/URL_Properties.cpp b/apps/JAWS/clients/Caching/URL_Properties.cpp index 24bf9932b4a..fa86934123e 100644 --- a/apps/JAWS/clients/Caching/URL_Properties.cpp +++ b/apps/JAWS/clients/Caching/URL_Properties.cpp @@ -23,6 +23,7 @@ ACE_WString_Helper::encode (void *buf, ACE_WString *wstr) for (i= 0; i <= wstr->length (); i++) wptr[i] = htons ((*wstr)[i]); + return i * sizeof (ACE_USHORT16); } @@ -34,6 +35,7 @@ ACE_WString_Helper::decode (void *buf) for (i = 0; wptr[i] != 0; i++) wptr[i] = ntohs (wptr[i]); + return (i + 1) * sizeof (ACE_USHORT16); } @@ -68,20 +70,19 @@ void ACE_URL_Property::dump (void) const { ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); + if (this->name_->length () > 0) - { - ACE_DEBUG ((LM_DEBUG, "\n name_: \"%s\"\n", - ACE_Auto_Basic_Array_Ptr<char> (this->name_->char_rep ()).get ())); - } + ACE_DEBUG ((LM_DEBUG, "\n name_: \"%s\"\n", + ACE_Auto_Basic_Array_Ptr<char> (this->name_->char_rep ()).get ())); else ACE_DEBUG ((LM_DEBUG, "\n name_: \"\"\n")); + if (this->value_->length () > 0) - { - ACE_DEBUG ((LM_DEBUG, " value_: \"%s\"\n", - ACE_Auto_Basic_Array_Ptr<char> (this->value_->char_rep ()).get ())); - } + ACE_DEBUG ((LM_DEBUG, " value_: \"%s\"\n", + ACE_Auto_Basic_Array_Ptr<char> (this->value_->char_rep ()).get ())); else ACE_DEBUG ((LM_DEBUG, " value_: \"\"\n")); + ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); } @@ -117,7 +118,7 @@ size_t ACE_URL_Offer::decode (void *buf) { size_t len = sizeof (ACE_UINT32); - size_t a_size = (size_t) ntohl (* (ACE_UINT32 *) buf); + size_t a_size = (size_t) ntohl (*(ACE_UINT32 *) buf); len += ACE_WString_Helper::decode ((void *) ((char *) buf + len)); this->url ((ACE_USHORT16 *) ((char *) buf + len)); @@ -133,15 +134,16 @@ void ACE_URL_Offer::dump (void) const { ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); + if (this->url_->length () > 0) - { - ACE_DEBUG ((LM_DEBUG, "\n url_: \"%s\"\n", - ACE_Auto_Basic_Array_Ptr<char> (this->url_->char_rep ()).get ())); - } + ACE_DEBUG ((LM_DEBUG, "\n url_: \"%s\"\n", + ACE_Auto_Basic_Array_Ptr<char> (this->url_->char_rep ()).get ())); else ACE_DEBUG ((LM_DEBUG, "\n url_: \"\"\n")); + for (size_t i = 0; i < this->prop_.size (); i++) this->prop_[i].dump (); + ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); } diff --git a/apps/JAWS/clients/Caching/URL_Properties.h b/apps/JAWS/clients/Caching/URL_Properties.h index 94b1129e53c..ec2f7f3a7de 100644 --- a/apps/JAWS/clients/Caching/URL_Properties.h +++ b/apps/JAWS/clients/Caching/URL_Properties.h @@ -32,6 +32,8 @@ class ACE_Export ACE_WString_Helper public: static size_t bsize (const ACE_WString *wstr); // Returns the actual size required to contain the ACE_WString. + // Nanbor, is there a reason you called this <bsize> rather than + // just <size>? I think I like <size> better! static size_t encode (void *buf, ACE_WString *wstr); // Encode <wstr> into <buf> for network communication. @@ -49,13 +51,18 @@ class ACE_Export ACE_URL_Property // // = DESCRIPTION // A property contains a <name> and a <value>. +// Nanbor, please add more description of what is typically *done* with a URL property. { public: - ACE_URL_Property (const char *name = 0, const char *value=0); + ACE_URL_Property (const char *name = 0, + const char *value=0); // Create a property. ACE_URL_Property (const ACE_USHORT16 *name, const ACE_USHORT16 *value); + // Nanbor, please make sure that you comment these interfaces. In + // particular, does this interface distinguish between UNICODE and + // non-UNICODE? ACE_URL_Property (const ACE_URL_Property &p); // Copy constructor. @@ -70,27 +77,28 @@ public: // Equals operator. int operator!= (const ACE_URL_Property &rhs) const; - // Not equals operator. + // Inequality operator. + // = Query property name. ACE_WString *name_rep (void); const ACE_WString *name (void) const; - // Query property name. + // = Set property name. void name (const ACE_USHORT16 *n); void name (const char *n); - // Set property name. + // = Query property value. ACE_WString *value_rep (void); const ACE_WString *value (void) const; - // Query property value. + // = Set property value. void value (const ACE_USHORT16 *v); void value (const char *v); - // Set property value. - // Some helper functions for encoding and decoding. + // = Helper functions for encoding and decoding. size_t bsize (void) const; // Returns memory size required to encode this object. + // Nanbor, can we make this <size> rather than <bsize>? size_t encode (void *buf) const; // Encodes this object into buf for network transmission. @@ -103,6 +111,10 @@ public: // Dump out this object for debug. protected: + // Nanbor, is there a particular reason that you're using dynamic + // memory allocation here? Can you just use instances of + // ACE_WString that aren't allocated dynamically or is there some + // reason why you need pointers? ACE_WString *name_; // Property name pointer. @@ -110,6 +122,7 @@ protected: // Property value. } ; +// Nanbor, please add a comment here. typedef ACE_Array<ACE_URL_Property> ACE_URL_Property_Seq; class ACE_Export ACE_URL_Offer @@ -119,6 +132,7 @@ class ACE_Export ACE_URL_Offer // = DESCRIPTION // A URL offer is defined by a <url> and an // <ACE_URL_Property_Seq>. +// Nanbor, please explain how an offer is typically *used*. { public: ACE_URL_Offer (const size_t size = 1, const char *url = 0); @@ -139,24 +153,25 @@ public: int operator!= (const ACE_URL_Offer &rhs) const; // Inequality operator. + // = Get URL string. ACE_WString *url_rep (void); const ACE_WString *url (void) const; - // Get URL string. + // = Set URL. void url (const char *url); void url (const ACE_USHORT16 *url); - // Set URL. ACE_URL_Property_Seq &url_properties (void); // Get properties of this offer. void url_properties (const ACE_URL_Property_Seq &prop); - // Set properties of this offer. This operation - // virtually get a copy of the passed in prop. + // Set properties of this offer. This operation virtually get a + // copy of the passed in prop. - // Some helper functions for encoding and decoding. + // = Helper functions for encoding and decoding. size_t bsize (void) const; // Returns memory size required to encode this object. + // Nanbor, can you please make this <size>? size_t encode (void *buf) const; // Encodes this object into buf for network transmission. @@ -176,6 +191,8 @@ protected: // Properties associate with this offer. }; +// Nanbor, please add a comment here. + typedef ACE_Array<ACE_URL_Offer> ACE_URL_Offer_Seq; #if defined (__ACE_INLINE__) diff --git a/apps/JAWS/clients/Caching/http_handler.h b/apps/JAWS/clients/Caching/http_handler.h index b0ea361c8d4..85a1b9338fe 100644 --- a/apps/JAWS/clients/Caching/http_handler.h +++ b/apps/JAWS/clients/Caching/http_handler.h @@ -18,15 +18,14 @@ #include "ace/Connector.h" #include "ace/SOCK_Connector.h" -class HTTP_Handler - : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> +class HTTP_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> // = TITLE // A simple HTTP protocol handler for clients. // // = DESCRIPTION - // Checks to see if the requested file is already cached. If so, - // it says so. If not, the request is issued to the connection. - // The fetched file is cached. + // Checks to see if the requested file is already cached. If + // so, it says so. If not, the request is issued to the + // connection. The fetched file is cached. { public: // = Initialization methods. @@ -34,6 +33,8 @@ public: HTTP_Handler (const char * path); virtual int open (void *); + // Open hook. + virtual int svc (void); // Entry points defined by the abstract Svc_Handler. @@ -53,8 +54,8 @@ class HTTP_Connector // A simple HTTP connector. // // = DESCRIPTION - // Creates an HTTP Handler based on the URL, and then delegates to - // to the SOCK_CONNECTOR. Adapter pattern. + // Creates an HTTP Handler based on the URL, and then delegates + // to to the SOCK_CONNECTOR. Adapter pattern. { public: int connect (const char * url); @@ -69,5 +70,7 @@ private: private: ACE_Connector<HTTP_Handler, ACE_SOCK_CONNECTOR> connector_; + // Factory that actively establishes a connection with an HTTP + // server. }; |