diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2013-12-24 07:45:39 +0100 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2013-12-24 07:45:39 +0100 |
commit | c60645d3effc7ec04b4e7a413e0a2b552e3fa90e (patch) | |
tree | 150216073ce542817721d6ea20aa6e1d32b848aa | |
parent | d2938865f2421e160adc18e86dd7813278035c70 (diff) | |
parent | 61202b565e7c440cae443d71f78b6c506ab60f38 (diff) |
Merge branch 'master' of /pub/repo.git/Balau
-rw-r--r-- | includes/BString.h | 18 | ||||
-rw-r--r-- | includes/Selectable.h | 2 | ||||
-rw-r--r-- | src/BString.cc | 18 | ||||
-rw-r--r-- | src/HelperTasks.cc | 4 | ||||
-rw-r--r-- | src/HttpServer.cc | 7 |
5 files changed, 37 insertions, 12 deletions
diff --git a/includes/BString.h b/includes/BString.h index e783935..392f720 100644 --- a/includes/BString.h +++ b/includes/BString.h @@ -13,11 +13,11 @@ #include <vector> #ifdef _MSC_VER -#ifdef _WIN64
-typedef __int64 ssize_t;
-#else /* _WIN64 */
-typedef _W64 int ssize_t;
-#endif /* _WIN64 */
+#ifdef _WIN64 +typedef __int64 ssize_t; +#else /* _WIN64 */ +typedef _W64 int ssize_t; +#endif /* _WIN64 */ #define printfwarning(a, b) #else #define printfwarning(a, b) __attribute__((format(printf, a, b))) @@ -50,6 +50,10 @@ class String : private std::string { String & set(const char * fmt, ...) printfwarning(2, 3) { va_list ap; va_start(ap, fmt); set(fmt, ap); va_end(ap); return *this; } String & set(const String & fmt, ...) { va_list ap; va_start(ap, fmt); set(fmt.to_charp(), ap); va_end(ap); return *this; } + String & append(const char * fmt, va_list) printfwarning(2, 0); + String & append(const char * fmt, ...) printfwarning(2, 3) { va_list ap; va_start(ap, fmt); append(fmt, ap); va_end(ap); return *this; } + String & append(const String & fmt, ...) { va_list ap; va_start(ap, fmt); append(fmt.to_charp(), ap); va_end(ap); return *this; } + int scanf(const char * fmt, va_list ap) const { return ::vsscanf(c_str(), fmt, ap); } int scanf(const char * fmt, ...) const printfwarning(2, 3) { va_list ap; va_start(ap, fmt); int r = scanf(fmt, ap); va_end(ap); return r; } int scanf(const String & fmt, ...) const { va_list ap; va_start(ap, fmt); int r = scanf(fmt.to_charp(), ap); va_end(ap); return r; } @@ -96,8 +100,8 @@ class String : private std::string { String operator+(const String & v) const { String r = *this; r += v; return r; } String operator+(const char * v) const { String r = *this; r += v; return r; } - String & operator+=(const String & v) { *this = append(v); return *this; } - String & operator+=(const char * v) { *this = append(v); return *this; } + String & operator+=(const String & v) { *this = std::string::append(v); return *this; } + String & operator+=(const char * v) { *this = std::string::append(v); return *this; } int compare(const String & v) const { return std::string::compare(v); } int compare(const char * v) const { return std::string::compare(v); } diff --git a/includes/Selectable.h b/includes/Selectable.h index 8667415..5dab7cb 100644 --- a/includes/Selectable.h +++ b/includes/Selectable.h @@ -26,7 +26,7 @@ class Selectable : public Handle { public: SelectableEvent(int fd, int evt = ev::READ | ev::WRITE) : m_task(NULL), m_evtType(evt), m_fd(fd) { Printer::elog(E_SELECT, "Got a new SelectableEvent at %p", this); m_evt.set<SelectableEvent, &SelectableEvent::evt_cb>(this); m_evt.set(fd, evt); } virtual ~SelectableEvent() { Printer::elog(E_SELECT, "Destroying a SelectableEvent at %p", this); m_evt.stop(); } - void stop() { Printer::elog(E_SELECT, "Stopping a SelectableEvent at %p", this); reset(); m_evt.stop(); } + void stop() { Printer::elog(E_SELECT, "Stopping a SelectableEvent at %p", this); resetMaybe(); m_evt.stop(); } private: void evt_cb(ev::io & w, int revents) { Printer::elog(E_SELECT, "Got a libev callback on a SelectableEvent at %p", this); doSignal(); } virtual void gotOwner(Task * task); diff --git a/src/BString.cc b/src/BString.cc index 57febcd..d14280c 100644 --- a/src/BString.cc +++ b/src/BString.cc @@ -22,6 +22,24 @@ Balau::String & Balau::String::set(const char * fmt, va_list ap) { return *this; } +Balau::String & Balau::String::append(const char * fmt, va_list ap) { + unsigned int l; +#ifdef _WIN32 + // Microsoft is stupid. + char tt[65536]; + l = _vsnprintf(tt, sizeof(tt)-1, fmt, ap); + tt[65535] = 0; + std::string::append(tt, l); +#else + char * t; + l = vasprintf(&t, fmt, ap); + std::string::append(t, l); + free(t); +#endif + + return *this; +} + int Balau::String::strchrcnt(char c) const { unsigned int l = length(); int r = 0; diff --git a/src/HelperTasks.cc b/src/HelperTasks.cc index ab1c2a9..074aa8d 100644 --- a/src/HelperTasks.cc +++ b/src/HelperTasks.cc @@ -21,7 +21,7 @@ void Balau::CopyTask::Do() { toread = std::min(toread, (ssize_t) COPY_BUFSIZE); m_read = m_s->read(m_buffer, toread); AAssert(m_read >= 0, "Error while reading"); - if (m_s->isEOF() || !m_read) + if (!m_read) return; m_written = 0; m_state = 1; @@ -33,6 +33,8 @@ void Balau::CopyTask::Do() { } while (m_read != m_written); m_state = 0; m_current += m_read; + if (m_s->isEOF()) + return; } } } diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 8eea5bb..43594e9 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -436,15 +436,15 @@ bool Balau::HttpWorker::handleClient() { bool gotOne = false; for (auto j = connVals.begin(); j != connVals.end(); j++) { String t = j->trim(); - if ((t == "close") && (!gotOne)) { + if ((t.lower() == "close") && (!gotOne)) { gotOne = true; persistent = false; - } else if ((t == "keep-alive") && (!gotOne)) { + } else if ((t.lower() == "keep-alive") && (!gotOne)) { gotOne = true; persistent = true; } else if (t == "TE") { Printer::elog(E_HTTPSERVER, "%s got the 'TE' connection marker (which is still unknown)", m_name.to_charp()); - } else if (t == "Upgrade") { + } else if (t.lower() == "upgrade") { upgrade = true; persistent = true; } else { @@ -559,6 +559,7 @@ bool Balau::HttpWorker::handleClient() { auto f = m_server->findAction(uri.to_charp(), host.to_charp()); if (f.action) { + setOkayToEAgain(false); m_strm->detach(); IO<OutputCheck> out(new OutputCheck(m_socket)); Http::Request req; |