Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
2c1332b3
Commit
2c1332b3
authored
Aug 31, 2012
by
Davis King
Browse files
Updated examples to use the simpler start_async() to start the servers.
parent
6503f874
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
77 deletions
+6
-77
examples/server_http_ex.cpp
examples/server_http_ex.cpp
+2
-25
examples/sockets_ex.cpp
examples/sockets_ex.cpp
+2
-26
examples/sockstreambuf_ex.cpp
examples/sockstreambuf_ex.cpp
+2
-26
No files found.
examples/server_http_ex.cpp
View file @
2c1332b3
...
@@ -13,7 +13,6 @@
...
@@ -13,7 +13,6 @@
#include <sstream>
#include <sstream>
#include <string>
#include <string>
#include "dlib/server.h"
#include "dlib/server.h"
#include "dlib/ref.h" // for ref()
using
namespace
dlib
;
using
namespace
dlib
;
using
namespace
std
;
using
namespace
std
;
...
@@ -92,24 +91,6 @@ class web_server : public server::http_1a_c
...
@@ -92,24 +91,6 @@ class web_server : public server::http_1a_c
};
};
void
thread
(
web_server
&
the_server
)
{
try
{
// Start the server. start() blocks until the server is shutdown
// by a call to clear()
the_server
.
start
();
}
catch
(
socket_error
&
e
)
{
cout
<<
"Socket error while starting server: "
<<
e
.
what
()
<<
endl
;
}
catch
(
exception
&
e
)
{
cout
<<
"Error while starting server: "
<<
e
.
what
()
<<
endl
;
}
}
int
main
()
int
main
()
{
{
try
try
...
@@ -119,15 +100,11 @@ int main()
...
@@ -119,15 +100,11 @@ int main()
// make it listen on port 5000
// make it listen on port 5000
our_web_server
.
set_listening_port
(
5000
);
our_web_server
.
set_listening_port
(
5000
);
// Tell the server to begin accepting connections.
// create a thread that will start the server. The ref() here allows us to pass
our_web_server
.
start_async
();
// our_web_server into the threaded function by reference.
thread_function
t
(
thread
,
dlib
::
ref
(
our_web_server
));
cout
<<
"Press enter to end this program"
<<
endl
;
cout
<<
"Press enter to end this program"
<<
endl
;
cin
.
get
();
cin
.
get
();
// this will cause the server to shut down
our_web_server
.
clear
();
}
}
catch
(
exception
&
e
)
catch
(
exception
&
e
)
{
{
...
...
examples/sockets_ex.cpp
View file @
2c1332b3
...
@@ -14,7 +14,6 @@
...
@@ -14,7 +14,6 @@
#include "dlib/sockets.h"
#include "dlib/sockets.h"
#include "dlib/server.h"
#include "dlib/server.h"
#include "dlib/ref.h" // for ref()
#include <iostream>
#include <iostream>
using
namespace
dlib
;
using
namespace
dlib
;
...
@@ -43,25 +42,6 @@ class serv : public server::kernel_1a_c
...
@@ -43,25 +42,6 @@ class serv : public server::kernel_1a_c
};
};
void
thread
(
serv
&
our_server
)
{
try
{
// Start the server. start() blocks until the server is shutdown
// by a call to clear()
our_server
.
start
();
}
catch
(
socket_error
&
e
)
{
cout
<<
"Socket error while starting server: "
<<
e
.
what
()
<<
endl
;
}
catch
(
exception
&
e
)
{
cout
<<
"Error while starting server: "
<<
e
.
what
()
<<
endl
;
}
}
int
main
()
int
main
()
{
{
try
try
...
@@ -71,15 +51,11 @@ int main()
...
@@ -71,15 +51,11 @@ int main()
// set up the server object we have made
// set up the server object we have made
our_server
.
set_listening_port
(
1234
);
our_server
.
set_listening_port
(
1234
);
our_server
.
set_max_connections
(
1000
);
our_server
.
set_max_connections
(
1000
);
// Tell the server to begin accepting connections.
// create a thread that will start the server. The ref() here allows us to pass
our_server
.
start_async
();
// our_server into the threaded function by reference.
thread_function
t
(
thread
,
dlib
::
ref
(
our_server
));
cout
<<
"Press enter to end this program"
<<
endl
;
cout
<<
"Press enter to end this program"
<<
endl
;
cin
.
get
();
cin
.
get
();
// this will cause the server to shut down
our_server
.
clear
();
}
}
catch
(
exception
&
e
)
catch
(
exception
&
e
)
{
{
...
...
examples/sockstreambuf_ex.cpp
View file @
2c1332b3
...
@@ -25,7 +25,6 @@
...
@@ -25,7 +25,6 @@
#include "dlib/sockets.h"
#include "dlib/sockets.h"
#include "dlib/server.h"
#include "dlib/server.h"
#include "dlib/sockstreambuf.h"
#include "dlib/sockstreambuf.h"
#include "dlib/ref.h"
#include <iostream>
#include <iostream>
using
namespace
dlib
;
using
namespace
dlib
;
...
@@ -70,25 +69,6 @@ class serv : public server::kernel_1a_c
...
@@ -70,25 +69,6 @@ class serv : public server::kernel_1a_c
};
};
void
thread
(
serv
&
our_server
)
{
try
{
// Start the server. start() blocks until the server is shutdown
// by a call to clear()
our_server
.
start
();
}
catch
(
socket_error
&
e
)
{
cout
<<
"Socket error while starting server: "
<<
e
.
what
()
<<
endl
;
}
catch
(
exception
&
e
)
{
cout
<<
"Error while starting server: "
<<
e
.
what
()
<<
endl
;
}
}
int
main
()
int
main
()
{
{
try
try
...
@@ -98,15 +78,11 @@ int main()
...
@@ -98,15 +78,11 @@ int main()
// set up the server object we have made
// set up the server object we have made
our_server
.
set_listening_port
(
1234
);
our_server
.
set_listening_port
(
1234
);
our_server
.
set_max_connections
(
1000
);
our_server
.
set_max_connections
(
1000
);
// Tell the server to begin accepting connections.
// create a thread that will start the server. The ref() here allows us to pass
our_server
.
start_async
();
// our_server into the threaded function by reference.
thread_function
t
(
thread
,
dlib
::
ref
(
our_server
));
cout
<<
"Press enter to end this program"
<<
endl
;
cout
<<
"Press enter to end this program"
<<
endl
;
cin
.
get
();
cin
.
get
();
// this will cause the server to shut down
our_server
.
clear
();
}
}
catch
(
exception
&
e
)
catch
(
exception
&
e
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment