Commit aa34d39f authored by Davis King's avatar Davis King

Added some overloads of the create_connection() and create_listener()

functions that use scoped_ptr objects instead of just plain pointers.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402496
parent ea261db8
...@@ -526,8 +526,23 @@ namespace dlib ...@@ -526,8 +526,23 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
int int create_listener (
create_listener ( scoped_ptr<listener>& new_listener,
unsigned short port,
const std::string& ip
)
{
new_listener.reset();
listener* temp;
int status = create_listener(temp,port,ip);
if (status == 0)
new_listener.reset(temp);
return status;
}
int create_listener (
listener*& new_listener, listener*& new_listener,
unsigned short port, unsigned short port,
const std::string& ip const std::string& ip
...@@ -626,8 +641,25 @@ namespace dlib ...@@ -626,8 +641,25 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
int int create_connection (
create_connection ( scoped_ptr<connection>& new_connection,
unsigned short foreign_port,
const std::string& foreign_ip,
unsigned short local_port,
const std::string& local_ip
)
{
new_connection.reset();
connection* temp;
int status = create_connection(temp,foreign_port, foreign_ip, local_port, local_ip);
if (status == 0)
new_connection.reset(temp);
return status;
}
int create_connection (
connection*& new_connection, connection*& new_connection,
unsigned short foreign_port, unsigned short foreign_port,
const std::string& foreign_ip, const std::string& foreign_ip,
......
...@@ -287,6 +287,20 @@ namespace dlib ...@@ -287,6 +287,20 @@ namespace dlib
const std::string& local_ip const std::string& local_ip
); );
int create_listener (
scoped_ptr<listener>& new_listener,
unsigned short port,
const std::string& ip = ""
);
int create_connection (
scoped_ptr<connection>& new_connection,
unsigned short foreign_port,
const std::string& foreign_ip,
unsigned short local_port = 0,
const std::string& local_ip = ""
);
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -676,8 +676,23 @@ namespace dlib ...@@ -676,8 +676,23 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
int int create_listener (
create_listener ( scoped_ptr<listener>& new_listener,
unsigned short port,
const std::string& ip
)
{
new_listener.reset();
listener* temp;
int status = create_listener(temp,port,ip);
if (status == 0)
new_listener.reset(temp);
return status;
}
int create_listener (
listener*& new_listener, listener*& new_listener,
unsigned short port, unsigned short port,
const std::string& ip const std::string& ip
...@@ -780,6 +795,24 @@ namespace dlib ...@@ -780,6 +795,24 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
int create_connection (
scoped_ptr<connection>& new_connection,
unsigned short foreign_port,
const std::string& foreign_ip,
unsigned short local_port,
const std::string& local_ip
)
{
new_connection.reset();
connection* temp;
int status = create_connection(temp,foreign_port, foreign_ip, local_port, local_ip);
if (status == 0)
new_connection.reset(temp);
return status;
}
int int
create_connection ( create_connection (
connection*& new_connection, connection*& new_connection,
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "../threads.h" #include "../threads.h"
#include "../algs.h" #include "../algs.h"
#include "../smart_pointers.h"
...@@ -336,6 +337,20 @@ namespace dlib ...@@ -336,6 +337,20 @@ namespace dlib
const std::string& local_ip const std::string& local_ip
); );
int create_listener (
scoped_ptr<listener>& new_listener,
unsigned short port,
const std::string& ip = ""
);
int create_connection (
scoped_ptr<connection>& new_connection,
unsigned short foreign_port,
const std::string& foreign_ip,
unsigned short local_port = 0,
const std::string& local_ip = ""
);
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
...@@ -110,6 +110,16 @@ namespace dlib ...@@ -110,6 +110,16 @@ namespace dlib
- returns OTHER_ERROR if some other error occurred - returns OTHER_ERROR if some other error occurred
!*/ !*/
int create_listener (
scoped_ptr<listener>& new_listener,
unsigned short port,
const std::string& ip = ""
);
/*!
This function is just an overload of the above function but it gives you a
scoped_ptr smart pointer instead of a C pointer.
!*/
int create_connection ( int create_connection (
connection*& new_connection, connection*& new_connection,
unsigned short foreign_port, unsigned short foreign_port,
...@@ -137,6 +147,18 @@ namespace dlib ...@@ -137,6 +147,18 @@ namespace dlib
- returns OTHER_ERROR if some other error occurred - returns OTHER_ERROR if some other error occurred
!*/ !*/
int create_connection (
scoped_ptr<connection>& new_connection,
unsigned short foreign_port,
const std::string& foreign_ip,
unsigned short local_port = 0,
const std::string& local_ip = ""
);
/*!
This function is just an overload of the above function but it gives you a
scoped_ptr smart pointer instead of a C pointer.
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// connection object // connection object
...@@ -200,7 +222,7 @@ namespace dlib ...@@ -200,7 +222,7 @@ namespace dlib
void* user_data; void* user_data;
/*! /*!
This pointer is provided so that the client programmer may easily assocaite This pointer is provided so that the client programmer may easily associate
some data with a connection object. You can really do whatever you want some data with a connection object. You can really do whatever you want
with it. Initially user_data is 0. with it. Initially user_data is 0.
!*/ !*/
...@@ -372,7 +394,7 @@ namespace dlib ...@@ -372,7 +394,7 @@ namespace dlib
- returns 0 if accept() was successful - returns 0 if accept() was successful
- returns TIMEOUT if timeout milliseconds have elapsed - returns TIMEOUT if timeout milliseconds have elapsed
- returns OTHER_ERROR if an error has occured - returns OTHER_ERROR if an error has occurred
!*/ !*/
unsigned short get_listening_port ( unsigned short get_listening_port (
......
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