diff options
Diffstat (limited to 'apps/JAWS/server')
-rw-r--r-- | apps/JAWS/server/HTTP_Helpers.cpp | 40 | ||||
-rw-r--r-- | apps/JAWS/server/HTTP_Helpers.h | 13 | ||||
-rw-r--r-- | apps/JAWS/server/HTTP_Response.cpp | 4 |
3 files changed, 30 insertions, 27 deletions
diff --git a/apps/JAWS/server/HTTP_Helpers.cpp b/apps/JAWS/server/HTTP_Helpers.cpp index d23a13348e3..3725a29c25d 100644 --- a/apps/JAWS/server/HTTP_Helpers.cpp +++ b/apps/JAWS/server/HTTP_Helpers.cpp @@ -14,11 +14,8 @@ HTTP_Helper::months_[12]= char const *HTTP_Helper::alphabet_ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -#if !defined (ACE_HAS_REENTRANT_LIBC) -#if defined (ACE_HAS_THREADS) +char * HTTP_Helper::date_string_ = 0; ACE_Thread_Mutex HTTP_Helper::mutex_; -#endif /* ACE_HAS_THREADS */ -#endif /* NOT ACE_HAS_REENTRANT_LIBC */ ACE_SYNCH_MUTEX HTTP_Status_Code::lock_; int HTTP_Status_Code::instance_ = 0; @@ -108,22 +105,33 @@ HTTP_Helper::HTTP_mktime (const char *httpdate) } const char * -HTTP_Helper::HTTP_date (char * const date_string, int date_length) +HTTP_Helper::HTTP_date (void) { - time_t tloc; - struct tm tms; - - if (date_string != 0) + if (HTTP_Helper::date_string_ == 0) { - if (ACE_OS::time (&tloc) != (time_t) -1 - && ACE_OS::gmtime_r (&tloc, &tms) != NULL) - ACE_OS::strftime (date_string, date_length, - "%a, %d %b %Y %T GMT", &tms); - else - return 0; + ACE_Guard<ACE_Thread_Mutex> m (HTTP_Helper::mutex_); + + time_t tloc; + struct tm tms; + + if (HTTP_Helper::date_string_ == 0) + { + // 40 bytes is all I need. + HTTP_Helper::date_string_ = new char[40]; + + if (ACE_OS::time (&tloc) != (time_t) -1 + && ACE_OS::gmtime_r (&tloc, &tms) != NULL) + ACE_OS::strftime (HTTP_Helper::date_string_, 40, + "%a, %d %b %Y %T GMT", &tms); + else + { + delete [] HTTP_Helper::date_string_; + HTTP_Helper::date_string_ = 0; + } + } } - return date_string; + return HTTP_Helper::date_string_; } int diff --git a/apps/JAWS/server/HTTP_Helpers.h b/apps/JAWS/server/HTTP_Helpers.h index c5c30f226a3..18df7d49d84 100644 --- a/apps/JAWS/server/HTTP_Helpers.h +++ b/apps/JAWS/server/HTTP_Helpers.h @@ -11,7 +11,7 @@ // HTTP_Helpers.h // // = AUTHOR -// James, please add the appropriate attribution here. +// James Hu // // ============================================================================ @@ -29,7 +29,7 @@ public: static time_t HTTP_mktime (const char *httpdate); // Create today's date - static const char *HTTP_date (char *const date_string, int date_length); + static const char *HTTP_date (void); static int HTTP_month (const char *month); static const char *HTTP_month (int month); @@ -47,12 +47,9 @@ private: static const char *const months_[12]; static char const *alphabet_; -#if !defined (ACE_HAS_REENTRANT_LIBC) -#if defined (ACE_HAS_THREADS) + static char *date_string_; static ACE_Thread_Mutex mutex_; -#endif /* ACE_HAS_THREADS */ -#endif /* NOT ACE_HAS_REENTRANT_LIBC */ - + // Use this sometimes (e.g. HTTP_date) }; // Design around the Singleton pattern @@ -96,7 +93,7 @@ public: }; private: - // James, please add comments. + // Singleton pattern is afoot here. static const char *Reason[MAX_STATUS_CODE + 1]; static int instance_; static ACE_SYNCH_MUTEX lock_; diff --git a/apps/JAWS/server/HTTP_Response.cpp b/apps/JAWS/server/HTTP_Response.cpp index e9f83451014..a29e6878c76 100644 --- a/apps/JAWS/server/HTTP_Response.cpp +++ b/apps/JAWS/server/HTTP_Response.cpp @@ -331,9 +331,7 @@ HTTP_Response::build_headers (void) this->request_.status (), this->request_.status_string ()); - // James, please document where the 40 comes from. - char date[40]; - const char *date_ptr = HTTP_Helper::HTTP_date (date, sizeof(date)-1); + const char *date_ptr = HTTP_Helper::HTTP_date (); if (date_ptr != 0) HTTP_HEADER_LENGTH += |