Commit a35dd6da authored by Davis King's avatar Davis King

Added some stuff to encourage the use of scoped_ptr with the connection

objects.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402467
parent f2cd116f
......@@ -200,11 +200,22 @@ namespace dlib
connection* con,
unsigned long timeout
)
{
scoped_ptr<connection> ptr(con);
close_gracefully(ptr,timeout);
}
// ----------------------------------------------------------------------------------------
void close_gracefully (
scoped_ptr<connection>& con,
unsigned long timeout
)
{
if(con->shutdown_outgoing())
{
// there was an error so just close it now and return
delete con;
con.reset();
return;
}
......@@ -218,11 +229,11 @@ namespace dlib
}
catch (...)
{
delete con;
con.reset();
throw;
}
delete con;
con.reset();
}
// ----------------------------------------------------------------------------------------
......
......@@ -6,6 +6,7 @@
#include <string>
#include "../sockets.h"
#include "sockets_extensions_abstract.h"
#include "../smart_pointers.h"
namespace dlib
{
......@@ -38,6 +39,13 @@ namespace dlib
unsigned long timeout = 500
);
// ----------------------------------------------------------------------------------------
void close_gracefully (
scoped_ptr<connection>& con,
unsigned long timeout = 500
);
// ----------------------------------------------------------------------------------------
}
......
......@@ -44,6 +44,14 @@ namespace dlib
lastread_next(false)
{}
sockstreambuf_kernel_1 (
const scoped_ptr<connection>& con_
) :
con(*con_),
peek(EOF),
lastread_next(false)
{}
connection* get_connection (
) { return &con; }
......
......@@ -35,20 +35,17 @@ namespace dlib
out_buffer(0),
in_buffer(0)
{
try
{
out_buffer = new char[out_buffer_size];
in_buffer = new char[in_buffer_size];
}
catch (...)
{
if (out_buffer) delete [] out_buffer;
throw;
}
setp(out_buffer, out_buffer + (out_buffer_size-1));
setg(in_buffer+max_putback,
in_buffer+max_putback,
in_buffer+max_putback);
init();
}
sockstreambuf_kernel_2 (
const scoped_ptr<connection>& con_
) :
con(*con_),
out_buffer(0),
in_buffer(0)
{
init();
}
virtual ~sockstreambuf_kernel_2 (
......@@ -65,6 +62,25 @@ namespace dlib
protected:
void init (
)
{
try
{
out_buffer = new char[out_buffer_size];
in_buffer = new char[in_buffer_size];
}
catch (...)
{
if (out_buffer) delete [] out_buffer;
throw;
}
setp(out_buffer, out_buffer + (out_buffer_size-1));
setg(in_buffer+max_putback,
in_buffer+max_putback,
in_buffer+max_putback);
}
int flush_out_buffer (
)
{
......
......@@ -57,6 +57,18 @@ namespace dlib
- std::bad_alloc
!*/
sockstreambuf (
const scoped_ptr<connection>& con
);
/*!
requires
- con == a valid connection object
ensures
- *this will read from and write to con
throws
- std::bad_alloc
!*/
~sockstreambuf (
);
/*!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment