summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-13 06:50:21 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-13 06:50:21 +0200
commit60589fcd0c7afc4f4cf0d832fd603ae75bc9c71a (patch)
treed7595339d4470c2580e413a6867ab9272254e833
parent735604976485ab69cd813d13ef53505bc454c201 (diff)
Cleaning up the Handle API a bit.
-rw-r--r--includes/Handle.h17
-rw-r--r--src/HttpServer.cc6
-rw-r--r--src/SimpleMustache.cc12
3 files changed, 17 insertions, 18 deletions
diff --git a/includes/Handle.h b/includes/Handle.h
index fdadef5..b167256 100644
--- a/includes/Handle.h
+++ b/includes/Handle.h
@@ -44,9 +44,8 @@ class Handle {
virtual bool canSeek();
virtual bool canRead();
virtual bool canWrite();
- virtual ssize_t read(void * buf, size_t count) throw (GeneralException);
- virtual ssize_t write(const void * buf, size_t count) throw (GeneralException);
- template <size_t L> void writeString(const char (&str)[L]) { writeString(str, L - 1); }
+ virtual ssize_t read(void * buf, size_t count) throw (GeneralException) __attribute__((warn_unused_result));
+ virtual ssize_t write(const void * buf, size_t count) throw (GeneralException) __attribute__((warn_unused_result));
virtual void rseek(off_t offset, int whence = SEEK_SET) throw (GeneralException);
virtual void wseek(off_t offset, int whence = SEEK_SET) throw (GeneralException);
virtual off_t rtell() throw (GeneralException);
@@ -77,12 +76,12 @@ class Handle {
Future<void> writeI64(int64_t);
// these need to be changed into Future<>s
- ssize_t write(const String & str) { return write(str.to_charp(), str.strlen()); }
- void writeString(const char * str, ssize_t len) { if (len < 0) len = strlen(str); forceWrite(str, len); }
- void writeString(const String & str) { forceWrite(str.to_charp(), str.strlen()); }
- ssize_t forceRead(void * buf, size_t count, Events::BaseEvent * evt = NULL) throw (GeneralException);
- ssize_t forceWrite(const void * buf, size_t count, Events::BaseEvent * evt = NULL) throw (GeneralException);
- ssize_t forceWrite(const String & str) { return forceWrite(str.to_charp(), str.strlen()); }
+ template <size_t L>
+ ssize_t writeString(const char (&str)[L]) { return writeString(str, L - 1); }
+ ssize_t writeString(const String & str) __attribute__((warn_unused_result)) { return forceWrite(str.to_charp(), str.strlen()); }
+ ssize_t writeString(const char * str, ssize_t len) __attribute__((warn_unused_result)) { return forceWrite(str, len); }
+ ssize_t forceRead(void * buf, size_t count, Events::BaseEvent * evt = NULL) throw (GeneralException) __attribute__((warn_unused_result));
+ ssize_t forceWrite(const void * buf, size_t count, Events::BaseEvent * evt = NULL) throw (GeneralException) __attribute__((warn_unused_result));
protected:
Handle() { }
diff --git a/src/HttpServer.cc b/src/HttpServer.cc
index 140fe78..53e3da0 100644
--- a/src/HttpServer.cc
+++ b/src/HttpServer.cc
@@ -213,7 +213,7 @@ void Balau::HttpWorker::sendError(int error, const char * msg, const char * deta
for (String & str : extraHeaders)
headers += str + "\r\n";
headers += "\r\n";
- m_socket->forceWrite(headers);
+ m_socket->writeString(headers);
if (m_socket->isClosed()) return;
tpl->render(m_socket, &ctx);
} else {
@@ -231,7 +231,7 @@ void Balau::HttpWorker::sendError(int error, const char * msg, const char * deta
for (String & str : extraHeaders)
headers += str + "\r\n";
headers += "\r\n";
- m_socket->forceWrite(headers);
+ m_socket->writeString(headers);
if (m_socket->isClosed()) return;
m_socket->forceWrite(errorText->getBuffer(), length);
}
@@ -676,7 +676,7 @@ void Balau::HttpServer::Response::Flush() {
String response(m_responseCode);
headers->writeString(response);
headers->writeString(" ");
- headers->writeString(Http::getStatusMsg(m_responseCode), -1);
+ headers->writeString(Http::getStatusMsg(m_responseCode));
headers->writeString("\r\nContent-Type: ");
headers->writeString(m_type);
headers->writeString("\r\nContent-Length: ");
diff --git a/src/SimpleMustache.cc b/src/SimpleMustache.cc
index eef4b01..557a183 100644
--- a/src/SimpleMustache.cc
+++ b/src/SimpleMustache.cc
@@ -376,7 +376,7 @@ Balau::SimpleMustache::Fragments::const_iterator Balau::SimpleMustache::render_r
for (cur = begin; cur != end; cur++) {
Fragment * fr = *cur;
if(fr->type == Fragment::STRING)
- h->write(fr->str);
+ h->writeString(fr->str);
}
return end;
}
@@ -395,16 +395,16 @@ Balau::SimpleMustache::Fragments::const_iterator Balau::SimpleMustache::render_r
IAssert(fr->type != Fragment::END_SECTION, "Processing an end section tag... ?");
switch (fr->type) {
case Fragment::STRING:
- h->write(fr->str);
+ h->writeString(fr->str);
break;
case Fragment::VARIABLE:
f = sCtx->find(fr->str);
if (f != sCtx->end()) {
Context * var = f->second;
if (var->m_type == Context::STRING)
- h->write(escape(var->m_str));
+ h->writeString(escape(var->m_str));
else if (var->m_type == Context::BOOLSEC)
- h->write(var->m_bool ? "true" : "false");
+ h->writeString(var->m_bool ? "true" : "false");
}
break;
case Fragment::NOESCAPE:
@@ -412,9 +412,9 @@ Balau::SimpleMustache::Fragments::const_iterator Balau::SimpleMustache::render_r
if (f != sCtx->end()) {
Context * var = f->second;
if (var->m_type == Context::STRING)
- h->write(var->m_str);
+ h->writeString(var->m_str);
else if (var->m_type == Context::BOOLSEC)
- h->write(var->m_bool ? "true" : "false");
+ h->writeString(var->m_bool ? "true" : "false");
}
break;
case Fragment::SECTION: