summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/Exceptions.h6
-rw-r--r--src/BStream.cc4
-rw-r--r--src/Handle.cc2
-rw-r--r--src/Input.cc8
-rw-r--r--src/Output.cc8
-rw-r--r--src/Socket.cc32
6 files changed, 33 insertions, 27 deletions
diff --git a/includes/Exceptions.h b/includes/Exceptions.h
index 1f65b12..829a5d1 100644
--- a/includes/Exceptions.h
+++ b/includes/Exceptions.h
@@ -136,6 +136,12 @@ ClassName::ClassName(T * ptr) {
Balau::ExitHelper(msg, __VA_ARGS__); \
}
+#define EAssert(c, ...) if (!__builtin_expect(!!(c), 0)) { \
+ Balau::String msg; \
+ msg.set("Execution Assertion " #c " failed at %s:%i", __FILE__, __LINE__); \
+ Balau::AssertHelper(msg, __VA_ARGS__); \
+}
+
#define TAssert(c) if (!__builtin_expect(!!(c), 0)) { \
Balau::String msg; \
msg.set("UnitTest Assert " #c " failed at %s:%i", __FILE__, __LINE__); \
diff --git a/src/BStream.cc b/src/BStream.cc
index cd7a121..9420459 100644
--- a/src/BStream.cc
+++ b/src/BStream.cc
@@ -52,7 +52,7 @@ ssize_t Balau::BStream::read(void * _buf, size_t count) throw (Balau::GeneralExc
m_cursor = 0;
IAssert(m_availBytes == 0, "At this point, our internal buffer should be empty, but it's not: %lu", m_availBytes);
ssize_t r = m_h->read(m_buffer, s_blockSize);
- RAssert(r >= 0, "BStream got an error while reading: %li", r);
+ EAssert(r >= 0, "BStream got an error while reading: %li", r);
m_availBytes = r;
if (toCopy > m_availBytes)
@@ -74,7 +74,7 @@ int Balau::BStream::peekNextByte() {
ssize_t r = read(&b, 1);
if (!r)
return -1;
- RAssert(r == 1, "We asked for one byte, yet we got %li", r);
+ EAssert(r == 1, "We asked for one byte, yet we got %li", r);
IAssert(m_cursor > 0, "m_cursor is %li", m_cursor);
IAssert(m_availBytes < s_blockSize, "m_availBytes = %li; s_blockSize = %i", m_availBytes, s_blockSize);
m_cursor--;
diff --git a/src/Handle.cc b/src/Handle.cc
index f3444d6..dacd30d 100644
--- a/src/Handle.cc
+++ b/src/Handle.cc
@@ -241,7 +241,7 @@ static int eioDone(eio_req * req) {
int Balau::FileSystem::mkdir(const char * path) throw (GeneralException) {
cbResults_t cbResults;
eio_req * r = eio_mkdir(path, 0755, 0, eioDone, &cbResults);
- RAssert(r != NULL, "eio_mkdir returned a NULL eio_req");
+ EAssert(r != NULL, "eio_mkdir returned a NULL eio_req");
Task::yield(&cbResults.evt);
char str[4096];
diff --git a/src/Input.cc b/src/Input.cc
index 48b32ea..14aed91 100644
--- a/src/Input.cc
+++ b/src/Input.cc
@@ -55,7 +55,7 @@ Balau::Input::Input(const char * fname) throw (GeneralException) : m_fd(-1), m_s
cbResults_t cbResults;
eio_req * r = eio_open(fname, O_RDONLY, 0, 0, eioDone, &cbResults);
- RAssert(r != NULL, "eio_open returned a NULL eio_req");
+ EAssert(r != NULL, "eio_open returned a NULL eio_req");
Task::yield(&cbResults.evt);
if (cbResults.result < 0) {
char str[4096];
@@ -70,7 +70,7 @@ Balau::Input::Input(const char * fname) throw (GeneralException) : m_fd(-1), m_s
cbStatsResults_t cbStatsResults;
r = eio_fstat(m_fd, 0, eioStatsDone, &cbStatsResults);
- RAssert(r != NULL, "eio_fstat returned a NULL eio_req");
+ EAssert(r != NULL, "eio_fstat returned a NULL eio_req");
Task::yield(&cbStatsResults.evt);
if (cbStatsResults.result == 0) {
m_size = cbStatsResults.statdata.st_size;
@@ -83,7 +83,7 @@ void Balau::Input::close() throw (GeneralException) {
return;
cbResults_t cbResults;
eio_req * r = eio_close(m_fd, 0, eioDone, &cbResults);
- RAssert(r != NULL, "eio_close returned a NULL eio_req");
+ EAssert(r != NULL, "eio_close returned a NULL eio_req");
m_fd = -1;
Task::yield(&cbResults.evt);
if (cbResults.result < 0) {
@@ -98,7 +98,7 @@ void Balau::Input::close() throw (GeneralException) {
ssize_t Balau::Input::read(void * buf, size_t count) throw (GeneralException) {
cbResults_t cbResults;
eio_req * r = eio_read(m_fd, buf, count, getROffset(), 0, eioDone, &cbResults);
- RAssert(r != NULL, "eio_read returned a NULL eio_req");
+ EAssert(r != NULL, "eio_read returned a NULL eio_req");
Task::yield(&cbResults.evt);
if (cbResults.result > 0) {
rseek(cbResults.result, SEEK_CUR);
diff --git a/src/Output.cc b/src/Output.cc
index f147a78..6de404e 100644
--- a/src/Output.cc
+++ b/src/Output.cc
@@ -55,7 +55,7 @@ Balau::Output::Output(const char * fname, bool truncate) throw (GeneralException
cbResults_t cbResults;
eio_req * r = eio_open(fname, O_WRONLY | O_CREAT | (truncate ? O_TRUNC : 0), 0755, 0, eioDone, &cbResults);
- RAssert(r != NULL, "eio_open returned a NULL eio_req");
+ EAssert(r != NULL, "eio_open returned a NULL eio_req");
Task::yield(&cbResults.evt);
if (cbResults.result < 0) {
char str[4096];
@@ -70,7 +70,7 @@ Balau::Output::Output(const char * fname, bool truncate) throw (GeneralException
cbStatsResults_t cbStatsResults;
r = eio_fstat(m_fd, 0, eioStatsDone, &cbStatsResults);
- RAssert(r != NULL, "eio_fstat returned a NULL eio_req");
+ EAssert(r != NULL, "eio_fstat returned a NULL eio_req");
Task::yield(&cbStatsResults.evt);
if (cbStatsResults.result == 0) {
m_size = cbStatsResults.statdata.st_size;
@@ -83,7 +83,7 @@ void Balau::Output::close() throw (GeneralException) {
return;
cbResults_t cbResults;
eio_req * r = eio_close(m_fd, 0, eioDone, &cbResults);
- RAssert(r != NULL, "eio_close returned a NULL eio_req");
+ EAssert(r != NULL, "eio_close returned a NULL eio_req");
m_fd = -1;
Task::yield(&cbResults.evt);
if (cbResults.result < 0) {
@@ -98,7 +98,7 @@ void Balau::Output::close() throw (GeneralException) {
ssize_t Balau::Output::write(const void * buf, size_t count) throw (GeneralException) {
cbResults_t cbResults;
eio_req * r = eio_write(m_fd, const_cast<void *>(buf), count, getWOffset(), 0, eioDone, &cbResults);
- RAssert(r != NULL, "eio_write returned a NULL eio_req");
+ EAssert(r != NULL, "eio_write returned a NULL eio_req");
Task::yield(&cbResults.evt);
if (cbResults.result > 0) {
wseek(cbResults.result, SEEK_CUR);
diff --git a/src/Socket.cc b/src/Socket.cc
index 56e2dfb..3bcf840 100644
--- a/src/Socket.cc
+++ b/src/Socket.cc
@@ -244,7 +244,7 @@ Balau::Socket::Socket() throw (GeneralException) : m_fd(socket(AF_INET6, SOCK_ST
int on = 0;
int r = setsockopt(m_fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &on, sizeof(on));
- RAssert(r == 0, "setsockopt returned %i", r);
+ EAssert(r == 0, "setsockopt returned %i", r);
memset(&m_localAddr, 0, sizeof(m_localAddr));
memset(&m_remoteAddr, 0, sizeof(m_remoteAddr));
@@ -267,8 +267,8 @@ Balau::Socket::Socket(int fd) : m_fd(fd), m_connected(true), m_connecting(false)
rLocal = inet_ntop(AF_INET6, &m_localAddr.sin6_addr, prtLocal, len);
rRemote = inet_ntop(AF_INET6, &m_remoteAddr.sin6_addr, prtRemote, len);
- RAssert(rLocal, "inet_ntop returned NULL");
- RAssert(rRemote, "inet_ntop returned NULL");
+ EAssert(rLocal, "inet_ntop returned NULL");
+ EAssert(rRemote, "inet_ntop returned NULL");
m_evtR = new SocketEvent(m_fd, ev::READ);
m_evtW = new SocketEvent(m_fd, ev::WRITE);
@@ -329,9 +329,9 @@ bool Balau::Socket::setLocal(const char * hostname, int port) {
freeaddrinfo(res);
return false;
}
- RAssert(res->ai_family == AF_INET6, "getaddrinfo returned a familiy which isn't AF_INET6; %i", res->ai_family);
- RAssert(res->ai_protocol == IPPROTO_TCP, "getaddrinfo returned a protocol which isn't IPPROTO_TCP; %i", res->ai_protocol);
- RAssert(res->ai_addrlen == sizeof(sockaddr_in6), "getaddrinfo returned an addrlen which isn't that of sizeof(sockaddr_in6); %i", res->ai_addrlen);
+ EAssert(res->ai_family == AF_INET6, "getaddrinfo returned a familiy which isn't AF_INET6; %i", res->ai_family);
+ EAssert(res->ai_protocol == IPPROTO_TCP, "getaddrinfo returned a protocol which isn't IPPROTO_TCP; %i", res->ai_protocol);
+ EAssert(res->ai_addrlen == sizeof(sockaddr_in6), "getaddrinfo returned an addrlen which isn't that of sizeof(sockaddr_in6); %i", res->ai_addrlen);
memcpy(&m_localAddr.sin6_addr, &((sockaddr_in6 *) res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
freeaddrinfo(res);
} else {
@@ -381,9 +381,9 @@ bool Balau::Socket::connect(const char * hostname, int port) {
return false;
}
Printer::elog(E_SOCKET, "Got a resolution answer");
- RAssert(res->ai_family == AF_INET6, "getaddrinfo returned a familiy which isn't AF_INET6; %i", res->ai_family);
- RAssert(res->ai_protocol == IPPROTO_TCP, "getaddrinfo returned a protocol which isn't IPPROTO_TCP; %i", res->ai_protocol);
- RAssert(res->ai_addrlen == sizeof(sockaddr_in6), "getaddrinfo returned an addrlen which isn't that of sizeof(sockaddr_in6); %i", res->ai_addrlen);
+ EAssert(res->ai_family == AF_INET6, "getaddrinfo returned a familiy which isn't AF_INET6; %i", res->ai_family);
+ EAssert(res->ai_protocol == IPPROTO_TCP, "getaddrinfo returned a protocol which isn't IPPROTO_TCP; %i", res->ai_protocol);
+ EAssert(res->ai_addrlen == sizeof(sockaddr_in6), "getaddrinfo returned an addrlen which isn't that of sizeof(sockaddr_in6); %i", res->ai_addrlen);
memcpy(&m_remoteAddr.sin6_addr, &((sockaddr_in6 *) res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
m_remoteAddr.sin6_port = htons(port);
@@ -413,7 +413,7 @@ bool Balau::Socket::connect(const char * hostname, int port) {
} else {
socklen_t sLen = sizeof(err);
int g = getsockopt(m_fd, SOL_SOCKET, SO_ERROR, (char *) &err, &sLen);
- RAssert(g == 0, "getsockopt failed; g = %i", g);
+ EAssert(g == 0, "getsockopt failed; g = %i", g);
r = err != 0 ? -1 : 0;
}
if ((r == 0) || ((r < 0) && (err == EISCONN))) {
@@ -435,8 +435,8 @@ bool Balau::Socket::connect(const char * hostname, int port) {
rLocal = inet_ntop(AF_INET6, &m_localAddr.sin6_addr, prtLocal, len);
rRemote = inet_ntop(AF_INET6, &m_remoteAddr.sin6_addr, prtRemote, len);
- RAssert(rLocal, "inet_ntop returned NULL");
- RAssert(rRemote, "inet_ntop returned NULL");
+ EAssert(rLocal, "inet_ntop returned NULL");
+ EAssert(rRemote, "inet_ntop returned NULL");
m_name.set("Socket(Connected - [%s]:%i -> [%s]:%i)", rLocal, ntohs(m_localAddr.sin6_port), rRemote, ntohs(m_remoteAddr.sin6_port));
Printer::elog(E_SOCKET, "Connected; %s", m_name.to_charp());
@@ -485,7 +485,7 @@ bool Balau::Socket::listen() {
len = sizeof(m_localAddr);
rLocal = inet_ntop(AF_INET6, &m_localAddr.sin6_addr, prtLocal, len);
- RAssert(rLocal, "inet_ntop() returned NULL");
+ EAssert(rLocal, "inet_ntop() returned NULL");
m_name.set("Socket(Listener - [%s]:%i)", rLocal, ntohs(m_localAddr.sin6_port));
Printer::elog(E_SOCKET, "Socket %i started to listen: %s", m_fd, m_name.to_charp());
@@ -569,7 +569,7 @@ ssize_t Balau::Socket::write(const void * buf, size_t count) throw (GeneralExcep
do {
ssize_t r = ::send(m_fd, (const char *) buf, count, 0);
- RAssert(r != 0, "send() returned 0 (broken pipe ?)");
+ EAssert(r != 0, "send() returned 0 (broken pipe ?)");
if (r > 0)
return r;
@@ -602,9 +602,9 @@ void Balau::ListenerBase::stop() {
void Balau::ListenerBase::Do() {
bool r = m_listener->setLocal(m_local.to_charp(), m_port);
- RAssert(r, "Couldn't set the local IP/port to listen to");
+ EAssert(r, "Couldn't set the local IP/port to listen to");
r = m_listener->listen();
- RAssert(r, "Couldn't listen on the given IP/port");
+ EAssert(r, "Couldn't listen on the given IP/port");
setName();
setOkayToEAgain(true);
waitFor(&m_evt);