aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/conn.cpp19
-rw-r--r--src/util.cpp7
2 files changed, 15 insertions, 11 deletions
diff --git a/src/conn.cpp b/src/conn.cpp
index 51a5346..4ab3040 100644
--- a/src/conn.cpp
+++ b/src/conn.cpp
@@ -54,7 +54,7 @@ ConnPool::Conn::operator std::string() const {
/* the following two functions are executed by exactly one worker per Conn object */
void ConnPool::Conn::send_data(int fd, int events) {
- if (events & Event::ERROR)
+ if (events & FdEvent::ERROR)
{
worker_terminate();
return;
@@ -93,13 +93,13 @@ void ConnPool::Conn::send_data(int fd, int events) {
}
}
ev_socket.del();
- ev_socket.add(Event::READ);
+ ev_socket.add(FdEvent::READ);
/* consumed the buffer but endpoint still seems to be writable */
ready_send = true;
}
void ConnPool::Conn::recv_data(int fd, int events) {
- if (events & Event::ERROR)
+ if (events & FdEvent::ERROR)
{
worker_terminate();
return;
@@ -172,7 +172,8 @@ void ConnPool::accept_client(int fd, int) {
struct sockaddr client_addr;
socklen_t addr_size = sizeof(struct sockaddr_in);
if ((client_fd = accept(fd, &client_addr, &addr_size)) < 0)
- SALTICIDAE_LOG_ERROR("error while accepting the connection");
+ SALTICIDAE_LOG_ERROR("error while accepting the connection: %s",
+ strerror(errno));
else
{
int one = 1;
@@ -213,7 +214,7 @@ void ConnPool::Conn::conn_server(int fd, int events) {
}
else
{
- if (events & Event::TIMEOUT)
+ if (events & TimedFdEvent::TIMEOUT)
SALTICIDAE_LOG_INFO("%s connect timeout", std::string(*this).c_str());
conn->disp_terminate();
return;
@@ -245,9 +246,9 @@ void ConnPool::_listen(NetAddr listen_addr) {
throw ConnPoolError(std::string("binding error"));
if (::listen(listen_fd, max_listen_backlog) < 0)
throw ConnPoolError(std::string("listen error"));
- ev_listen = Event(disp_ec, listen_fd,
+ ev_listen = FdEvent(disp_ec, listen_fd,
std::bind(&ConnPool::accept_client, this, _1, _2));
- ev_listen.add(Event::READ);
+ ev_listen.add(FdEvent::READ);
SALTICIDAE_LOG_INFO("listening to %u", ntohs(listen_addr.port));
}
@@ -283,8 +284,8 @@ ConnPool::conn_t ConnPool::_connect(const NetAddr &addr) {
}
else
{
- conn->ev_connect = Event(disp_ec, conn->fd, std::bind(&Conn::conn_server, conn.get(), _1, _2));
- conn->ev_connect.add_with_timeout(conn_server_timeout, Event::WRITE);
+ conn->ev_connect = TimedFdEvent(disp_ec, conn->fd, std::bind(&Conn::conn_server, conn.get(), _1, _2));
+ conn->ev_connect.add(FdEvent::WRITE, conn_server_timeout);
add_conn(conn);
SALTICIDAE_LOG_INFO("created %s", std::string(*conn).c_str());
}
diff --git a/src/util.cpp b/src/util.cpp
index c51e191..6a8c652 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -51,11 +51,13 @@ double gen_rand_timeout(double base_timeout, double alpha) {
return base_timeout + rand() / (double)RAND_MAX * alpha * base_timeout;
}
-std::string vstringprintf(const char *fmt, va_list ap) {
+std::string vstringprintf(const char *fmt, va_list _ap) {
int guessed_size = 1024;
std::string buff;
+ va_list ap;
+ va_copy(ap, _ap);
buff.resize(guessed_size);
- int nwrote = vsnprintf(&buff[0], guessed_size, fmt, ap);
+ int nwrote = vsnprintf(&buff[0], guessed_size, fmt, _ap);
if (nwrote < 0) buff = "";
else
{
@@ -66,6 +68,7 @@ std::string vstringprintf(const char *fmt, va_list ap) {
buff = "";
}
}
+ va_end(ap);
return std::move(buff);
}