Changeset 5424 for source


Ignore:
Timestamp:
Jul 29, 2009, 3:30:42 PM (15 years ago)
Author:
mies
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/utility/transport/rfcomm/rfcomm.cpp

    r5423 r5424  
    3333public:
    3434        link_info(io_service& io ) :
    35                 up(false), local(), remote(), socket(io), connect_retries(0),
     35                io(io), up(false), local(), remote(), socket(new bluetooth::rfcomm::socket(io)), connect_retries(0),
    3636                size(0), buffer(NULL), sending(false) {
    3737        }
     38
     39        ~link_info() {
     40                delete socket;
     41        }
     42
     43        void reinit() {
     44                delete socket;
     45                socket = new bluetooth::rfcomm::socket(io);
     46                up = false;
     47        }
     48
     49        io_service& io;
    3850
    3951        // state
    4052        bool up;
    4153        rfcomm_endpoint local, remote;
    42         bluetooth::rfcomm::socket socket;
     54        bluetooth::rfcomm::socket* socket;
    4355        int connect_retries;
    4456
     
    5769        if (info != NULL && info->up) {
    5870                info->up = false;
    59                 info->socket.shutdown( bluetooth::rfcomm::socket::shutdown_both );
     71                info->socket->shutdown( bluetooth::rfcomm::socket::shutdown_both );
    6072        }
    6173}
     
    124136
    125137        // not found, or not up? ->try to (re-)connect
    126         if (info==NULL || !info->up || info->socket.is_open() ) {
     138        if (info==NULL || !info->up || info->socket->is_open() ) {
    127139                logging_debug( "Connecting to " << endpoint.to_string() );
    128                 if (info != NULL && (!info->up || !info->socket.is_open())) {
     140                if (info != NULL && (!info->up || !info->socket->is_open())) {
    129141                        logging_debug("Old link is down. Trying to re-establish link.");
     142                        info->reinit();
    130143                } else {
    131144                        info = new link_info(io);
     
    133146                info->connect_retries = 0;
    134147                info->remote = endpoint;
    135                 info->socket.async_connect( convert(endpoint), boost::bind(
     148                info->socket->async_connect( convert(endpoint), boost::bind(
    136149                        &rfcomm::handle_connect, this,
    137150                        boost::asio::placeholders::error, info
     
    192205        // start accepting a connection
    193206        link_info* info = new link_info(io);
    194         acceptor->async_accept(info->socket, boost::bind(
     207        acceptor->async_accept(*info->socket, boost::bind(
    195208                // bind parameters
    196209                &rfcomm::handle_accept, this,
     
    221234        // convert endpoints
    222235        info->up = true;
    223         info->local  = convert( info->socket.local_endpoint()  );
    224         info->remote = convert( info->socket.remote_endpoint() );
     236        info->local  = convert( info->socket->local_endpoint()  );
     237        info->remote = convert( info->socket->remote_endpoint() );
    225238
    226239        logging_debug("Accepted incoming connection from "
     
    249262                        // increase counter
    250263                        info->connect_retries++;
     264                        info->reinit();
    251265
    252266                        // retry connection attempt
    253                         info->socket.async_connect( convert(info->remote), boost::bind(
     267                        info->socket->async_connect( convert(info->remote), boost::bind(
    254268                                &rfcomm::handle_connect, this,
    255269                                boost::asio::placeholders::error, info
     
    263277        // convert endpoints
    264278        info->up = true;
    265         info->local  = convert( info->socket.local_endpoint()  );
    266         info->remote = convert( info->socket.remote_endpoint() );
     279        info->local  = convert( info->socket->local_endpoint()  );
     280        info->remote = convert( info->socket->remote_endpoint() );
    267281
    268282        logging_debug( "Connected to " << info->remote.to_string() );
     
    280294void rfcomm::start_read(link_info* info) {
    281295        // start read
    282         boost::asio::async_read(info->socket,
     296        boost::asio::async_read(*info->socket,
    283297
    284298                // read size of packet
     
    321335
    322336        // start read
    323         boost::asio::async_read(info->socket,
     337        boost::asio::async_read(*info->socket,
    324338                // read size of packet
    325339                boost::asio::buffer(info->buffer, info->size),
     
    378392
    379393        // start writing
    380         boost::asio::async_write(info->socket,
     394        boost::asio::async_write(*info->socket,
    381395                // read size of packet
    382396                buffer,
Note: See TracChangeset for help on using the changeset viewer.