summaryrefslogtreecommitdiff
path: root/docs/tutorials
diff options
context:
space:
mode:
Diffstat (limited to 'docs/tutorials')
-rw-r--r--docs/tutorials/001/logger.h10
-rw-r--r--docs/tutorials/001/page04.html10
2 files changed, 12 insertions, 8 deletions
diff --git a/docs/tutorials/001/logger.h b/docs/tutorials/001/logger.h
index 46ed9fa2d02..32546dd5ffb 100644
--- a/docs/tutorials/001/logger.h
+++ b/docs/tutorials/001/logger.h
@@ -92,10 +92,10 @@ protected:
virtual int handle_input (ACE_HANDLE)
{
/*
- Create and initialize a small receive buffer.
+ Create and initialize a small receive buffer. The extra byte is
+ there to allow us to have a null-terminated string when it's over.
*/
- char buf[128];
- memset(buf,0,sizeof(buf));
+ char buf[128+1];
/*
Invoke the recv() method of the ACE_SOCK_Stream to get some data. It will
@@ -120,7 +120,8 @@ protected:
passed directly to the underlying OS recv() call. See the man page recv(2)
and the header sys/socket.h for the gory details.
*/
- switch( this->cli_stream_.recv(buf,sizeof buf) )
+ ssize_t retval;
+ switch( retval = this->cli_stream_.recv(buf,sizeof(buf)-1) )
{
case -1:
ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p bad read\n", "client logger"), -1);
@@ -128,6 +129,7 @@ protected:
ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) closing log daemon (fd = %d)\n",
this->get_handle ()), -1);
default:
+ buf[retval] = '\0';
ACE_DEBUG ((LM_DEBUG, "(%P|%t) from client: %s",buf));
}
diff --git a/docs/tutorials/001/page04.html b/docs/tutorials/001/page04.html
index 079947a3b3a..18950902db8 100644
--- a/docs/tutorials/001/page04.html
+++ b/docs/tutorials/001/page04.html
@@ -113,10 +113,10 @@ protected:
virtual int handle_input (ACE_HANDLE)
{
<font color=red>/*
- Create and initialize a small receive buffer.
+ Create and initialize a small receive buffer. The extra byte is
+ there to allow us to have a null-terminated string when it's over.
*/</font>
- char buf[128];
- memset(buf,0,sizeof(buf));
+ char buf[128+1];
<font color=red>/*
Invoke the recv() method of the ACE_SOCK_Stream to get some data. It will
@@ -141,7 +141,8 @@ protected:
passed directly to the underlying OS recv() call. See the man page recv(2)
and the header sys/socket.h for the gory details.
*/</font>
- switch( this->cli_stream_.recv(buf,sizeof buf) )
+ ssize_t retval;
+ switch( retval = this->cli_stream_.recv(buf,sizeof(buf)-1) )
{
case -1:
ACE_ERROR_RETURN ((LM_ERROR, "<font color=green>(%P|%t) %p bad read\n</font>", "<font color=green>client logger</font>"), -1);
@@ -149,6 +150,7 @@ protected:
ACE_ERROR_RETURN ((LM_ERROR, "<font color=green>(%P|%t) closing log daemon (fd = %d)\n</font>",
this->get_handle ()), -1);
default:
+ buf[retval] = '\0';
ACE_DEBUG ((LM_DEBUG, "<font color=green>(%P|%t) from client: %s</font>",buf));
}