~ubuntu-branches/ubuntu/oneiric/libtorrent-rasterbar/oneiric

« back to all changes in this revision

Viewing changes to src/broadcast_socket.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2010-08-10 12:57:25 UTC
  • mfrom: (1.3.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125725-i2o9iblow20w7qde
Tags: 0.15.1-0ubuntu1
* New upstream point release.

* New package libtorrent-rasterbar6 (bump up library soname). (LP: #615950)
 - Must Conflict/Replace libtorrent-rasterbar5 (= 0.15.0-0ubuntu1) or it will
   fail to install trying to overwrite '/usr/lib/libtorrent-rasterbar.so.6.0.0'

* Sync on git.debian.org/collab-maint/libtorrent-rasterbar.git:
 - debian/{control,rules}: Bump debhelper build-dep to (>= 7.4.10)
   and pass to dh in order to enable parallel build support.
 - debian/watch: Use googlecode.debian.net redirector.

Show diffs side-by-side

added added

removed removed

Lines of Context:
194
194
                , bool loopback)
195
195
                : m_multicast_endpoint(multicast_endpoint)
196
196
                , m_on_receive(handler)
 
197
                , m_ip_broadcast(false)
197
198
        {
198
199
                TORRENT_ASSERT(is_multicast(m_multicast_endpoint.address()));
199
200
 
225
226
//                              , print_address(multicast_endpoint.address()).c_str()
226
227
//                              , ec.message().c_str());
227
228
#endif
228
 
                        open_unicast_socket(ios, i->interface_address);
 
229
                        open_unicast_socket(ios, i->interface_address
 
230
                                , i->netmask.is_v4() ? i->netmask.to_v4() : address_v4());
 
231
                }
 
232
        }
 
233
 
 
234
        void broadcast_socket::enable_ip_broadcast(bool e)
 
235
        {
 
236
                if (e == m_ip_broadcast) return;
 
237
                m_ip_broadcast = e;
 
238
 
 
239
                asio::socket_base::broadcast option(m_ip_broadcast);
 
240
                for (std::list<socket_entry>::iterator i = m_unicast_sockets.begin()
 
241
                        , end(m_unicast_sockets.end()); i != end; ++i)
 
242
                {
 
243
                        if (i->socket) continue;
 
244
                        i->socket->set_option(option);
229
245
                }
230
246
        }
231
247
 
250
266
                m_sockets.push_back(socket_entry(s));
251
267
                socket_entry& se = m_sockets.back();
252
268
                s->async_receive_from(asio::buffer(se.buffer, sizeof(se.buffer))
253
 
                        , se.remote, bind(&broadcast_socket::on_receive, this, &se, _1, _2));
 
269
                        , se.remote, boost::bind(&broadcast_socket::on_receive, this, &se, _1, _2));
254
270
        }
255
271
 
256
 
        void broadcast_socket::open_unicast_socket(io_service& ios, address const& addr)
 
272
        void broadcast_socket::open_unicast_socket(io_service& ios, address const& addr
 
273
                , address_v4 const& mask)
257
274
        {
258
275
                using namespace asio::ip::multicast;
259
276
                error_code ec;
262
279
                if (ec) return;
263
280
                s->bind(udp::endpoint(addr, 0), ec);
264
281
                if (ec) return;
265
 
                m_unicast_sockets.push_back(socket_entry(s));
 
282
                m_unicast_sockets.push_back(socket_entry(s, mask));
266
283
                socket_entry& se = m_unicast_sockets.back();
267
284
                s->async_receive_from(asio::buffer(se.buffer, sizeof(se.buffer))
268
 
                        , se.remote, bind(&broadcast_socket::on_receive, this, &se, _1, _2));
 
285
                        , se.remote, boost::bind(&broadcast_socket::on_receive, this, &se, _1, _2));
269
286
        }
270
287
 
271
288
        void broadcast_socket::send(char const* buffer, int size, error_code& ec)
296
313
                        if (!i->socket) continue;
297
314
                        error_code e;
298
315
                        i->socket->send_to(asio::buffer(buffer, size), m_multicast_endpoint, 0, e);
 
316
                        if (m_ip_broadcast && i->socket->local_endpoint(e).address().is_v4())
 
317
                                i->socket->send_to(asio::buffer(buffer, size)
 
318
                                        , udp::endpoint(i->broadcast_address(), m_multicast_endpoint.port()), 0, e);
299
319
#ifndef NDEBUG
300
320
//                      extern std::string print_address(address const& addr);
301
321
//                      extern std::string print_endpoint(udp::endpoint const& ep);
320
340
                m_on_receive(s->remote, s->buffer, bytes_transferred);
321
341
                if (!s->socket) return;
322
342
                s->socket->async_receive_from(asio::buffer(s->buffer, sizeof(s->buffer))
323
 
                        , s->remote, bind(&broadcast_socket::on_receive, this, s, _1, _2));
 
343
                        , s->remote, boost::bind(&broadcast_socket::on_receive, this, s, _1, _2));
324
344
        }
325
345
 
326
346
        void broadcast_socket::close()
327
347
        {
328
 
                std::for_each(m_sockets.begin(), m_sockets.end(), bind(&socket_entry::close, _1));
329
 
                std::for_each(m_unicast_sockets.begin(), m_unicast_sockets.end(), bind(&socket_entry::close, _1));
 
348
                std::for_each(m_sockets.begin(), m_sockets.end(), boost::bind(&socket_entry::close, _1));
 
349
                std::for_each(m_unicast_sockets.begin(), m_unicast_sockets.end(), boost::bind(&socket_entry::close, _1));
330
350
 
331
351
                m_on_receive.clear();
332
352
        }