components/libtorrent/patches/rlibtorrent-02-event-ports.patch
changeset 6932 ae9e3811b2ec
parent 6931 f6f7269f85a9
child 6933 e1fa2aa7bad7
equal deleted inserted replaced
6931:f6f7269f85a9 6932:ae9e3811b2ec
     1 # replaced -fvisibility=hidden with -template=no%extdef in CXXFLAGS.
       
     2 diff -x configure -x aclocal.m4 -ru libtorrent-0.11.9/configure.ac libtorrent-0.11.9-new/configure.ac
       
     3 --- libtorrent-0.11.9/configure.ac	2007-10-25 09:48:32.000000000 +0000
       
     4 +++ libtorrent-0.11.9-new/configure.ac	2008-01-13 17:13:30.892756466 +0000
       
     5 @@ -43,6 +43,7 @@
       
     6  
       
     7  dnl TORRENT_WITH_XFS
       
     8  TORRENT_WITH_KQUEUE
       
     9 +TORRENT_WITH_PORTS
       
    10  TORRENT_WITHOUT_EPOLL
       
    11  TORRENT_WITH_POSIX_FALLOCATE
       
    12  TORRENT_WITH_ADDRESS_SPACE
       
    13 diff -x configure -x aclocal.m4 -ru libtorrent-0.11.9/scripts/checks.m4 libtorrent-0.11.9-new/scripts/checks.m4
       
    14 --- libtorrent-0.11.9/scripts/checks.m4	2007-10-09 01:41:07.000000000 +0000
       
    15 +++ libtorrent-0.11.9-new/scripts/checks.m4	2008-01-13 17:04:39.692325909 +0000
       
    16 @@ -85,6 +85,15 @@
       
    17      ])
       
    18  ])
       
    19  
       
    20 +AC_DEFUN([TORRENT_WITH_PORTS], [
       
    21 +  AC_ARG_WITH(ports,
       
    22 +    [  --with-ports            enable Solaris event ports. [[default=no]]],
       
    23 +    [
       
    24 +        if test "$withval" = "yes"; then
       
    25 +            AC_DEFINE(USE_PORTS, 1, Enable event ports.)
       
    26 +        fi
       
    27 +    ])
       
    28 +])
       
    29  
       
    30  AC_DEFUN([TORRENT_WITHOUT_VARIABLE_FDSET], [
       
    31    AC_ARG_WITH(variable-fdset,
       
    32 diff -x configure -x aclocal.m4 -ru libtorrent-0.11.9/src/torrent/Makefile.am libtorrent-0.11.9-new/src/torrent/Makefile.am
       
    33 --- libtorrent-0.11.9/src/torrent/Makefile.am	2007-02-02 11:09:56.000000000 +0000
       
    34 +++ libtorrent-0.11.9-new/src/torrent/Makefile.am	2008-01-13 17:51:02.471766611 +0000
       
    35 @@ -33,6 +33,8 @@
       
    36  	poll_epoll.h \
       
    37  	poll_kqueue.h \
       
    38  	poll_kqueue.cc \
       
    39 +	poll_ports.h \
       
    40 +	poll_ports.cc \
       
    41  	poll_select.h \
       
    42  	poll_select.cc \
       
    43  	rate.cc \
       
    44 @@ -65,6 +67,7 @@
       
    45  	path.h \
       
    46  	poll.h \
       
    47  	poll_epoll.h \
       
    48 +	poll_ports.h \
       
    49  	poll_kqueue.h \
       
    50  	poll_select.h \
       
    51  	rate.h \
       
    52 diff -urN libtorrent.orig/src/torrent/poll_ports.h libtorrent/src/torrent/poll_ports.h
       
    53 --- libtorrent.orig/src/torrent/poll_ports.h	1969-12-31 19:00:00.000000000 -0500
       
    54 +++ libtorrent/src/torrent/poll_ports.h	2008-05-12 00:42:15.000000000 -0400
       
    55 @@ -0,0 +1,104 @@
       
    56 +// libTorrent - BitTorrent library
       
    57 +// Copyright (C) 2005-2007, Jari Sundell
       
    58 +//
       
    59 +// This program is free software; you can redistribute it and/or modify
       
    60 +// it under the terms of the GNU General Public License as published by
       
    61 +// the Free Software Foundation; either version 2 of the License, or
       
    62 +// (at your option) any later version.
       
    63 +// 
       
    64 +// This program is distributed in the hope that it will be useful,
       
    65 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    66 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    67 +// GNU General Public License for more details.
       
    68 +// 
       
    69 +// You should have received a copy of the GNU General Public License
       
    70 +// along with this program; if not, write to the Free Software
       
    71 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    72 +//
       
    73 +// In addition, as a special exception, the copyright holders give
       
    74 +// permission to link the code of portions of this program with the
       
    75 +// OpenSSL library under certain conditions as described in each
       
    76 +// individual source file, and distribute linked combinations
       
    77 +// including the two.
       
    78 +//
       
    79 +// You must obey the GNU General Public License in all respects for
       
    80 +// all of the code used other than OpenSSL.  If you modify file(s)
       
    81 +// with this exception, you may extend this exception to your version
       
    82 +// of the file(s), but you are not obligated to do so.  If you do not
       
    83 +// wish to do so, delete this exception statement from your version.
       
    84 +// If you delete this exception statement from all source files in the
       
    85 +// program, then also delete it here.
       
    86 +//
       
    87 +// Contact:  Jari Sundell <[email protected]>
       
    88 +//
       
    89 +//           Skomakerveien 33
       
    90 +//           3185 Skoppum, NORWAY
       
    91 +
       
    92 +#ifndef LIBTORRENT_TORRENT_POLL_PORTS_H
       
    93 +#define LIBTORRENT_TORRENT_POLL_PORTS_H
       
    94 +
       
    95 +#include <vector>
       
    96 +#include <map>
       
    97 +#include <torrent/poll.h>
       
    98 +
       
    99 +struct port_event;
       
   100 +
       
   101 +namespace torrent {
       
   102 +
       
   103 +class LIBTORRENT_EXPORT PollPorts : public torrent::Poll {
       
   104 +public:
       
   105 +  typedef std::pair<Event*,int> ObjectMask;
       
   106 +  typedef std::vector<ObjectMask> Table;
       
   107 +
       
   108 +  static PollPorts*   create(int maxOpenSockets);
       
   109 +  virtual ~PollPorts();
       
   110 +
       
   111 +  int                 poll(int msec);
       
   112 +  void                perform();
       
   113 +
       
   114 +  int                 file_descriptor() { return m_fd; }
       
   115 +
       
   116 +  virtual uint32_t    open_max() const { return m_table.size(); }
       
   117 +
       
   118 +  // torrent::Event::get_fd() is guaranteed to be valid and remain constant
       
   119 +  // from open(...) is called to close(...) returns.
       
   120 +  virtual void        open(torrent::Event* event);
       
   121 +  virtual void        close(torrent::Event* event);
       
   122 +
       
   123 +  // Functions for checking whetever the torrent::Event is listening to r/w/e?
       
   124 +  virtual bool        in_read(torrent::Event* event);
       
   125 +  virtual bool        in_write(torrent::Event* event);
       
   126 +  virtual bool        in_error(torrent::Event* event);
       
   127 +
       
   128 +  // These functions may be called on 'event's that might, or might
       
   129 +  // not, already be in the set.
       
   130 +  virtual void        insert_read(torrent::Event* event);
       
   131 +  virtual void        insert_write(torrent::Event* event);
       
   132 +  virtual void        insert_error(torrent::Event* event);
       
   133 +
       
   134 +  virtual void        remove_read(torrent::Event* event);
       
   135 +  virtual void        remove_write(torrent::Event* event);
       
   136 +  virtual void        remove_error(torrent::Event* event);
       
   137 +
       
   138 +private:
       
   139 +  PollPorts(int fd, int maxEvents, int maxOpenSockets);
       
   140 +
       
   141 +  inline Event*       event_object(Event* e);
       
   142 +  inline int          event_mask(Event* e);
       
   143 +  inline void         set_event_object(Event* e);
       
   144 +  inline void         set_event_mask(Event* e, int m);
       
   145 +
       
   146 +  inline void         modify(torrent::Event* event, int mask);
       
   147 +
       
   148 +  int                 m_fd;
       
   149 +
       
   150 +  int                 m_maxEvents;
       
   151 +  int                 m_waitingEvents;
       
   152 +
       
   153 +  Table               m_table;
       
   154 +  port_event*         m_events;
       
   155 +};
       
   156 +
       
   157 +}
       
   158 +
       
   159 +#endif
       
   160 diff -urN libtorrent.orig/src/torrent/poll_ports.cc libtorrent/src/torrent/poll_ports.cc
       
   161 --- libtorrent.orig/src/torrent/poll_ports.cc	1969-12-31 19:00:00.000000000 -0500
       
   162 +++ libtorrent/src/torrent/poll_ports.cc	2008-06-10 14:48:05.000000000 -0400
       
   163 @@ -0,0 +1,338 @@
       
   164 +// libTorrent - BitTorrent library
       
   165 +// Copyright (C) 2005-2007, Jari Sundell
       
   166 +//
       
   167 +// This program is free software; you can redistribute it and/or modify
       
   168 +// it under the terms of the GNU General Public License as published by
       
   169 +// the Free Software Foundation; either version 2 of the License, or
       
   170 +// (at your option) any later version.
       
   171 +// 
       
   172 +// This program is distributed in the hope that it will be useful,
       
   173 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
       
   174 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
   175 +// GNU General Public License for more details.
       
   176 +// 
       
   177 +// You should have received a copy of the GNU General Public License
       
   178 +// along with this program; if not, write to the Free Software
       
   179 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
   180 +//
       
   181 +// In addition, as a special exception, the copyright holders give
       
   182 +// permission to link the code of portions of this program with the
       
   183 +// OpenSSL library under certain conditions as described in each
       
   184 +// individual source file, and distribute linked combinations
       
   185 +// including the two.
       
   186 +//
       
   187 +// You must obey the GNU General Public License in all respects for
       
   188 +// all of the code used other than OpenSSL.  If you modify file(s)
       
   189 +// with this exception, you may extend this exception to your version
       
   190 +// of the file(s), but you are not obligated to do so.  If you do not
       
   191 +// wish to do so, delete this exception statement from your version.
       
   192 +// If you delete this exception statement from all source files in the
       
   193 +// program, then also delete it here.
       
   194 +//
       
   195 +// Contact:  Jari Sundell <[email protected]>
       
   196 +//
       
   197 +//           Skomakerveien 33
       
   198 +//           3185 Skoppum, NORWAY
       
   199 +
       
   200 +#include "config.h"
       
   201 +
       
   202 +#include <cerrno>
       
   203 +#include <cstring>
       
   204 +#include <iostream>
       
   205 +
       
   206 +#include <unistd.h>
       
   207 +#include <torrent/exceptions.h>
       
   208 +#include <torrent/event.h>
       
   209 +
       
   210 +#include "poll_ports.h"
       
   211 +
       
   212 +#ifdef USE_PORTS
       
   213 +/*
       
   214 + * We should use <poll.h> here, but it seems to conflict with the
       
   215 + * <torrent/poll.h> header, so use <sys/poll.h> instead.  Since all
       
   216 + * poll.h does is include sys/poll.h, this shouldn't cause any
       
   217 + * problems.
       
   218 + */
       
   219 +# include <sys/poll.h>
       
   220 +# include <port.h>
       
   221 +#endif
       
   222 +
       
   223 +namespace torrent {
       
   224 +
       
   225 +#ifdef USE_PORTS
       
   226 +inline Event*
       
   227 +PollPorts::event_object(Event* e) {
       
   228 +  return m_table[e->file_descriptor()].first;
       
   229 +}
       
   230 +
       
   231 +inline int
       
   232 +PollPorts::event_mask(Event* e) {
       
   233 +  if (event_object(e) != e)
       
   234 +    return 0;
       
   235 +  return m_table[e->file_descriptor()].second;
       
   236 +}
       
   237 +
       
   238 +inline void
       
   239 +PollPorts::set_event_object(Event* e) {
       
   240 +  m_table[e->file_descriptor()] = std::pair<Event*,int>(e, 0);
       
   241 +}
       
   242 +
       
   243 +inline void
       
   244 +PollPorts::set_event_mask(Event* e, int m) {
       
   245 +  m_table[e->file_descriptor()].second = m;
       
   246 +}
       
   247 +
       
   248 +inline void
       
   249 +PollPorts::modify(Event* event, int mask) {
       
   250 +  if (event_object(event) != event)
       
   251 +    return;
       
   252 +
       
   253 +  if (event_mask(event) == mask)
       
   254 +    return;
       
   255 +
       
   256 +  set_event_mask(event, mask);
       
   257 +
       
   258 +  if (mask == 0) {
       
   259 +    port_dissociate(m_fd, PORT_SOURCE_FD, event->file_descriptor());
       
   260 +    return;
       
   261 +  }
       
   262 +
       
   263 +  if (port_associate(m_fd, PORT_SOURCE_FD, event->file_descriptor(),
       
   264 +		  mask, event) == -1)
       
   265 +	  throw internal_error("PollPorts::modify(...) port_associate failed");
       
   266 +}
       
   267 +
       
   268 +PollPorts*
       
   269 +PollPorts::create(int maxOpenSockets) {
       
   270 +  int fd = port_create();
       
   271 +
       
   272 +  if (fd == -1)
       
   273 +    return NULL;
       
   274 +
       
   275 +  return new PollPorts(fd, 1024, maxOpenSockets);
       
   276 +}
       
   277 +
       
   278 +PollPorts::PollPorts(int fd, int maxEvents, int maxOpenSockets) :
       
   279 +  m_fd(fd),
       
   280 +  m_maxEvents(maxEvents),
       
   281 +  m_waitingEvents(0),
       
   282 +  m_events(new port_event_t[maxEvents]) {
       
   283 +  m_table.resize(maxOpenSockets);
       
   284 +}
       
   285 +
       
   286 +PollPorts::~PollPorts() {
       
   287 +  m_table.clear();
       
   288 +  delete [] m_events;
       
   289 +
       
   290 +  ::close(m_fd);
       
   291 +}
       
   292 +
       
   293 +int
       
   294 +PollPorts::poll(int msec) {
       
   295 +  timespec_t timeout;
       
   296 +  timeout.tv_sec = msec / 1000;
       
   297 +  timeout.tv_nsec = (msec * 1000000L) % 1000000000L;
       
   298 +
       
   299 +  uint_t nfds = 1;
       
   300 +
       
   301 +  int ret = port_getn(m_fd, m_events, m_maxEvents, &nfds, &timeout);
       
   302 +
       
   303 +  if (ret == -1 && errno != ETIME) {
       
   304 +	  std::cerr << "error from ports, maxevents="<<m_maxEvents<<", nfds="<<nfds<<" msec="<<msec<<"\n";
       
   305 +    return -1;
       
   306 +  }
       
   307 +
       
   308 +  return m_waitingEvents = nfds;
       
   309 +}
       
   310 +
       
   311 +// We check m_table to make sure the Event is still listening to the
       
   312 +// event, so it is safe to remove Event's while in working.
       
   313 +//
       
   314 +// TODO: Do we want to guarantee if the Event has been removed from
       
   315 +// some event but not closed, it won't call that event? Think so...
       
   316 +void
       
   317 +PollPorts::perform() {
       
   318 +  for (port_event_t *itr = m_events, *last = m_events + m_waitingEvents; itr != last; ++itr) {
       
   319 +
       
   320 +    // Each branch must check for data.ptr != NULL to allow the socket
       
   321 +    // to remove itself between the calls.
       
   322 +    //
       
   323 +    // TODO: Make it so that it checks that read/write is wanted, that
       
   324 +    // it wasn't removed from one of them but not closed.
       
   325 +
       
   326 +    Event *e = static_cast<Event*>(itr->portev_user);
       
   327 +    if (e == NULL)
       
   328 +      continue;
       
   329 +
       
   330 +    if (itr->portev_events & POLLERR 
       
   331 +        && event_mask(e) & POLLERR)
       
   332 +      e->event_error();
       
   333 +
       
   334 +    if (itr->portev_user != e)
       
   335 +      continue;
       
   336 +
       
   337 +    if (itr->portev_events & POLLIN
       
   338 +        && event_mask(e) & POLLIN)
       
   339 +      e->event_read();
       
   340 +
       
   341 +    if (itr->portev_user != e)
       
   342 +      continue;
       
   343 +
       
   344 +    if (itr->portev_events & POLLOUT
       
   345 +        && event_mask(e) & POLLOUT)
       
   346 +      e->event_write();
       
   347 +
       
   348 +    if (itr->portev_user != e)
       
   349 +      continue;
       
   350 +
       
   351 +    // Since port events are one-shot, re-add the fd after we process
       
   352 +    // its events.
       
   353 +
       
   354 +    port_associate(m_fd, PORT_SOURCE_FD, itr->portev_object,
       
   355 +        event_mask(e), e);
       
   356 +  }
       
   357 +
       
   358 +  m_waitingEvents = 0;
       
   359 +}
       
   360 +
       
   361 +void
       
   362 +PollPorts::open(Event* event) {
       
   363 +  if (event_object(event) == event && event_mask(event) != 0)
       
   364 +    throw internal_error("PollPorts::open(...) called but the file descriptor is active");
       
   365 +  set_event_object(event);
       
   366 +}
       
   367 +
       
   368 +void
       
   369 +PollPorts::close(Event* event) {
       
   370 +  if (event_mask(event) != 0)
       
   371 +    throw internal_error("PollPorts::close(...) called but the file descriptor is active");
       
   372 +
       
   373 +  for (port_event_t *itr = m_events, *last = m_events + m_waitingEvents; itr != last; ++itr)
       
   374 +    if (itr->portev_user == event)
       
   375 +      itr->portev_user = NULL;
       
   376 +}
       
   377 +
       
   378 +bool
       
   379 +PollPorts::in_read(Event* event) {
       
   380 +  return event_mask(event) & POLLIN;
       
   381 +}
       
   382 +
       
   383 +bool
       
   384 +PollPorts::in_write(Event* event) {
       
   385 +  return event_mask(event) & POLLOUT;
       
   386 +}
       
   387 +
       
   388 +bool
       
   389 +PollPorts::in_error(Event* event) {
       
   390 +  return event_mask(event) & POLLERR;
       
   391 +}
       
   392 +
       
   393 +void
       
   394 +PollPorts::insert_read(Event* event) {
       
   395 +  modify(event, event_mask(event) | POLLIN);
       
   396 +}
       
   397 +
       
   398 +void
       
   399 +PollPorts::insert_write(Event* event) {
       
   400 +  modify(event, event_mask(event) | POLLOUT);
       
   401 +}
       
   402 +
       
   403 +void
       
   404 +PollPorts::insert_error(Event* event) {
       
   405 +  modify(event, event_mask(event) | POLLERR);
       
   406 +}
       
   407 +
       
   408 +void
       
   409 +PollPorts::remove_read(Event* event) {
       
   410 +  modify(event, event_mask(event) & ~POLLIN);
       
   411 +}
       
   412 +
       
   413 +void
       
   414 +PollPorts::remove_write(Event* event) {
       
   415 +  modify(event, event_mask(event) & ~POLLOUT);
       
   416 +}
       
   417 +
       
   418 +void
       
   419 +PollPorts::remove_error(Event* event) {
       
   420 +  modify(event, event_mask(event) & ~POLLERR);
       
   421 +}
       
   422 +
       
   423 +#else // USE_PORTS
       
   424 +
       
   425 +PollPorts*
       
   426 +PollPorts::create(int maxOpenSockets) {
       
   427 +  return NULL;
       
   428 +}
       
   429 +
       
   430 +PollPorts::~PollPorts() {
       
   431 +}
       
   432 +
       
   433 +int
       
   434 +PollPorts::poll(int msec) {
       
   435 +  throw internal_error("An PollPorts function was called, but it is disabled.");
       
   436 +}
       
   437 +
       
   438 +void
       
   439 +PollPorts::perform() {
       
   440 +  throw internal_error("An PollPorts function was called, but it is disabled.");
       
   441 +}
       
   442 +
       
   443 +uint32_t
       
   444 +PollPorts::open_max() const {
       
   445 +  throw internal_error("An PollPorts function was called, but it is disabled.");
       
   446 +}
       
   447 +
       
   448 +void
       
   449 +PollPorts::open(torrent::Event* event) {
       
   450 +}
       
   451 +
       
   452 +void
       
   453 +PollPorts::close(torrent::Event* event) {
       
   454 +}
       
   455 +
       
   456 +bool
       
   457 +PollPorts::in_read(torrent::Event* event) {
       
   458 +  throw internal_error("An PollPorts function was called, but it is disabled.");
       
   459 +}
       
   460 +
       
   461 +bool
       
   462 +PollPorts::in_write(torrent::Event* event) {
       
   463 +  throw internal_error("An PollPorts function was called, but it is disabled.");
       
   464 +}
       
   465 +
       
   466 +bool
       
   467 +PollPorts::in_error(torrent::Event* event) {
       
   468 +  throw internal_error("An PollPorts function was called, but it is disabled.");
       
   469 +}
       
   470 +
       
   471 +void
       
   472 +PollPorts::insert_read(torrent::Event* event) {
       
   473 +}
       
   474 +
       
   475 +void
       
   476 +PollPorts::insert_write(torrent::Event* event) {
       
   477 +}
       
   478 +
       
   479 +void
       
   480 +PollPorts::insert_error(torrent::Event* event) {
       
   481 +}
       
   482 +
       
   483 +void
       
   484 +PollPorts::remove_read(torrent::Event* event) {
       
   485 +}
       
   486 +
       
   487 +void
       
   488 +PollPorts::remove_write(torrent::Event* event) {
       
   489 +}
       
   490 +
       
   491 +void
       
   492 +PollPorts::remove_error(torrent::Event* event) {
       
   493 +}
       
   494 +
       
   495 +PollPorts::PollPorts(int fd, int maxEvents, int maxOpenSockets) {
       
   496 +  throw internal_error("An PollPorts function was called, but it is disabled.");
       
   497 +}
       
   498 +
       
   499 +#endif // USE_PORTS
       
   500 +
       
   501 +}
       
   502 --- libtorrent-0.12.2/scripts/attributes.m4	2008-05-07 05:19:12.000000000 -0700
       
   503 +++ libtorrent-0.12.2/scripts/attributes.m4	2015-01-29 08:45:29.333056494 -0800
       
   504 @@ -62,7 +62,7 @@
       
   505          AC_LANG_PUSH(C++)
       
   506  
       
   507          tmp_CXXFLAGS=$CXXFLAGS
       
   508 -        CXXFLAGS="$CXXFLAGS -fvisibility=hidden"
       
   509 +        CXXFLAGS="$CXXFLAGS -template=no%extdef"
       
   510  
       
   511  	AC_CACHE_CHECK([if compiler supports __attribute__((visibility("default")))],
       
   512  		[cc_cv_attribute_visibility],
       
   513 @@ -78,7 +78,7 @@
       
   514  
       
   515  	if test "x$cc_cv_attribute_visibility" = "xyes"; then
       
   516  		AC_DEFINE([SUPPORT_ATTRIBUTE_VISIBILITY], 1, [Define this if the compiler supports the visibility attributes.])
       
   517 -                CXXFLAGS="$CXXFLAGS -fvisibility=hidden"
       
   518 +                CXXFLAGS="$CXXFLAGS -template=no%extdef"
       
   519  		$1
       
   520  	else
       
   521                  true