Various Cleanups (realmd/)

This commit is contained in:
Schmoozerd 2012-07-19 21:59:38 +02:00
parent ed3220dbf2
commit a4cbed3199
10 changed files with 206 additions and 204 deletions

View file

@ -40,14 +40,14 @@ BufferedSocket::BufferedSocket(void):
{
}
/*virtual*/ int BufferedSocket::open(void * arg)
/*virtual*/ int BufferedSocket::open(void* arg)
{
if(Base::open(arg) == -1)
if (Base::open(arg) == -1)
return -1;
ACE_INET_Addr addr;
if(peer().get_remote_addr(addr) == -1)
if (peer().get_remote_addr(addr) == -1)
return -1;
char address[1024];
@ -71,9 +71,9 @@ size_t BufferedSocket::recv_len(void) const
return this->input_buffer_.length();
}
bool BufferedSocket::recv_soft(char *buf, size_t len)
bool BufferedSocket::recv_soft(char* buf, size_t len)
{
if(this->input_buffer_.length() < len)
if (this->input_buffer_.length() < len)
return false;
ACE_OS::memcpy(buf, this->input_buffer_.rd_ptr(), len);
@ -81,11 +81,11 @@ bool BufferedSocket::recv_soft(char *buf, size_t len)
return true;
}
bool BufferedSocket::recv(char *buf, size_t len)
bool BufferedSocket::recv(char* buf, size_t len)
{
bool ret = this->recv_soft(buf, len);
if(ret)
if (ret)
this->recv_skip(len);
return ret;
@ -96,26 +96,26 @@ void BufferedSocket::recv_skip(size_t len)
this->input_buffer_.rd_ptr(len);
}
ssize_t BufferedSocket::noblk_send(ACE_Message_Block &message_block)
ssize_t BufferedSocket::noblk_send(ACE_Message_Block& message_block)
{
const size_t len = message_block.length();
if(len == 0)
if (len == 0)
return -1;
// Try to send the message directly.
ssize_t n = this->peer().send(message_block.rd_ptr(), len, MSG_NOSIGNAL);
if(n < 0)
if (n < 0)
{
if(errno == EWOULDBLOCK)
if (errno == EWOULDBLOCK)
// Blocking signal
return 0;
else
// Error
return -1;
}
else if(n == 0)
else if (n == 0)
{
// Can this happen ?
return -1;
@ -125,35 +125,35 @@ ssize_t BufferedSocket::noblk_send(ACE_Message_Block &message_block)
return n;
}
bool BufferedSocket::send(const char *buf, size_t len)
bool BufferedSocket::send(const char* buf, size_t len)
{
if(buf == NULL || len == 0)
if (buf == NULL || len == 0)
return true;
ACE_Data_Block db(
len,
ACE_Message_Block::MB_DATA,
(const char*)buf,
0,
0,
ACE_Message_Block::DONT_DELETE,
0);
len,
ACE_Message_Block::MB_DATA,
(const char*)buf,
0,
0,
ACE_Message_Block::DONT_DELETE,
0);
ACE_Message_Block message_block(
&db,
ACE_Message_Block::DONT_DELETE,
0);
&db,
ACE_Message_Block::DONT_DELETE,
0);
message_block.wr_ptr(len);
if(this->msg_queue()->is_empty())
if (this->msg_queue()->is_empty())
{
// Try to send it directly.
ssize_t n = this->noblk_send(message_block);
if(n < 0)
if (n < 0)
return false;
else if(n == len)
else if (n == len)
return true;
// adjust how much bytes we sent
@ -163,16 +163,16 @@ bool BufferedSocket::send(const char *buf, size_t len)
}
// enqueue the message, note: clone is needed cause we cant enqueue stuff on the stack
ACE_Message_Block *mb = message_block.clone();
ACE_Message_Block* mb = message_block.clone();
if(this->msg_queue()->enqueue_tail(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
if (this->msg_queue()->enqueue_tail(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
{
mb->release();
return false;
}
// tell reactor to call handle_output() when we can send more data
if(this->reactor()->schedule_wakeup(this, ACE_Event_Handler::WRITE_MASK) == -1)
if (this->reactor()->schedule_wakeup(this, ACE_Event_Handler::WRITE_MASK) == -1)
return false;
return true;
@ -180,26 +180,26 @@ bool BufferedSocket::send(const char *buf, size_t len)
/*virtual*/ int BufferedSocket::handle_output(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
{
ACE_Message_Block *mb = 0;
ACE_Message_Block* mb = 0;
if(this->msg_queue()->is_empty())
if (this->msg_queue()->is_empty())
{
// if no more data to send, then cancel notification
this->reactor()->cancel_wakeup(this, ACE_Event_Handler::WRITE_MASK);
return 0;
}
if(this->msg_queue()->dequeue_head(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
if (this->msg_queue()->dequeue_head(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
return -1;
ssize_t n = this->noblk_send(*mb);
if(n < 0)
if (n < 0)
{
mb->release();
return -1;
}
else if(n == mb->length())
else if (n == mb->length())
{
mb->release();
return 1;
@ -208,7 +208,7 @@ bool BufferedSocket::send(const char *buf, size_t len)
{
mb->rd_ptr(n);
if(this->msg_queue()->enqueue_head(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
if (this->msg_queue()->enqueue_head(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
{
mb->release();
return -1;
@ -226,12 +226,12 @@ bool BufferedSocket::send(const char *buf, size_t len)
ssize_t n = this->peer().recv(this->input_buffer_.wr_ptr(), space);
if(n < 0)
if (n < 0)
{
// blocking signal or error
return errno == EWOULDBLOCK ? 0 : -1;
}
else if(n == 0)
else if (n == 0)
{
// EOF
return -1;