38 #include <boost/bind.hpp>
41 #include <boost/asio.hpp>
43 #include <boost/asio.hpp>
46 #include <boost/shared_ptr.hpp>
49 using namespace boost;
50 using namespace boost::asio;
51 using namespace boost::asio::ip;
55 using namespace boost;
57 using namespace asio::ip;
61 using namespace boost;
63 using namespace asio::ip;
67 class moBoostHandleFunctions {
75 virtual ~moBoostHandleFunctions() {
82 void HandleRead(
const system::error_code& e,
83 std::size_t bytes_transferred ) {
91 pConnection->
HandleRead( (
long)bytes_transferred );
106 void HandleWrite(
const boost::system::error_code& e) {
129 void HandleAccept(
const boost::system::error_code& e ) {
180 asio::io_service *p_io_service = (asio::io_service *) pIOS;
182 tcp::socket* p_socket =
new tcp::socket( (*p_io_service) );
185 m_Socket = (
void*)p_socket;
187 tcp::resolver *p_resolver =
new tcp::resolver( (*p_io_service) );
190 m_Resolver = (
void*)p_resolver;
257 tcp::socket* p_socket = (tcp::socket*) m_Socket;
276 bytesbuf = 0 + bytesbuf;
344 m_Connections.Add( p_new_connection );
345 p_new_connection->
Start();
349 for(
int i=0; i<(int)m_Connections.Count(); i++) {
350 if (m_Connections[i]==p_connection) {
351 m_Connections.Remove(i);
352 p_connection->
Stop();
360 for(
int i=0; i<(int)m_Connections.Count(); i++) {
361 if (m_Connections[i]) {
362 m_Connections[i]->Stop();
366 m_Connections.Empty();
378 m_ConnectionManager.Start( m_pNewConnection );
382 tcp::acceptor *p_acceptor = (tcp::acceptor *) m_pAcceptor;
413 if ( p_directory==
moText(
"") ) p_directory =
"";
415 io_service* p_io_service =
new io_service();
416 m_pIOService = (
void*) p_io_service;
424 tcp::resolver resolver( *p_io_service );
426 tcp::resolver::query query( (
char*)p_address, (
char*)p_port);
428 tcp::endpoint endpoint = *resolver.resolve(query);
430 tcp::acceptor *p_acceptor =
new tcp::acceptor( *p_io_service );
431 m_pAcceptor = (
void*) p_acceptor;
434 p_acceptor->open( endpoint.protocol() );
435 p_acceptor->set_option( tcp::acceptor::reuse_address(
true) );
436 p_acceptor->bind( endpoint );
437 p_acceptor->listen();
447 moBoostHandleFunctions* pFunctions =
new moBoostHandleFunctions( (
void*)
this,
MO_NET_SERVER );
448 m_pHandleFunctions = (
void*) pFunctions;
468 io_service* p_io_service = NULL;
470 p_io_service = (io_service*) m_pIOService;
479 io_service* p_io_service = NULL;
481 p_io_service = (io_service*) m_pIOService;
483 p_io_service->post( boost::bind( &moNetServer::HandleStop,
this) );
492 moNetServer::HandleStop() {
497 tcp::acceptor* p_acceptor = NULL;
498 p_acceptor = (tcp::acceptor*) m_pAcceptor;
502 m_ConnectionManager.StopAll();
517 SetName(
"netmanager");
518 SetLabelName(
"netmanager");
526 m_NetObjects.Init(0,NULL);
535 m_NetObjects.Finish();
moDefineDynamicArray(moNetObjects) moDefineDynamicArray(moNetConnections) class moBoostHandleFunctions
moNetServer(moAddress p_address, moPort p_port, moText p_directory)
void Start(moNetConnection *p_new_connection)
virtual ~moNetConnectionManager()
virtual MOboolean Finish()
void HandleRead(long bytesbuf)
clase de para manejar textos
Dispositivo de entrada/salida, típicamente, interfaces humanas de IO y datos ( teclado, mouse, tableta, tcp, udp, serial )
void HandleWrite()
Handle completion of a write operation.
void * moBoostIOService
Boost.Asio specific classes type definitions.
moNetConnection(moBoostIOService pIOS)
clase para crear y mantener una conección basada en el protocolo tcp
void Stop(moNetConnection *p_connection)
virtual ~moNetConnection()