Browse Source

android fixes

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
b7aac66551
  1. 1558
      libtorrent/build-aux/config.guess
  2. 1793
      libtorrent/build-aux/config.sub
  3. 15
      libtorrent/include/libtorrent/config.hpp
  4. 8
      libtorrent/src/file.cpp
  5. 5
      libtorrent/src/utp_stream.cpp
  6. 2
      src/compat.h
  7. 170
      src/net.cpp

1558
libtorrent/build-aux/config.guess vendored

File diff suppressed because it is too large Load Diff

1793
libtorrent/build-aux/config.sub vendored

File diff suppressed because it is too large Load Diff

15
libtorrent/include/libtorrent/config.hpp

@ -215,11 +215,22 @@ POSSIBILITY OF SUCH DAMAGE. @@ -215,11 +215,22 @@ POSSIBILITY OF SUCH DAMAGE.
// ==== LINUX ===
#elif defined __linux__
#define TORRENT_LINUX
#define TORRENT_USE_IFADDRS 1
#ifdef __ANDROID__
#define TORRENT_USE_IFADDRS 0
#else
#define TORRENT_USE_IFADDRS 1
#endif
#define TORRENT_USE_NETLINK 1
#define TORRENT_USE_IFCONF 1
#define TORRENT_HAS_SALEN 0
#define TORRENT_USE_POSIX_MEMALIGN 1
#ifdef __ANDROID__
#define TORRENT_USE_POSIX_MEMALIGN 0
#define TORRENT_USE_MEMALIGN 1
#define TORRENT_USE_ICONV 0
#define TORRENT_HAS_FALLOCATE 0
#else
#define TORRENT_USE_POSIX_MEMALIGN 1
#endif
#if __amd64__ || __i386__
#define TORRENT_USE_EXECINFO 1
#endif

8
libtorrent/src/file.cpp

@ -72,7 +72,13 @@ POSSIBILITY OF SUCH DAMAGE. @@ -72,7 +72,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include <unistd.h>
#include <fcntl.h> // for F_LOG2PHYS
#include <sys/types.h>
#ifndef __ANDROID__
#include <sys/statvfs.h>
#else
#define statvfs statfs
#define fstatvfs fstatfs
#include <sys/vfs.h>
#endif
#include <errno.h>
#include <dirent.h>
@ -112,12 +118,14 @@ static int my_fallocate(int fd, int mode, loff_t offset, loff_t len) @@ -112,12 +118,14 @@ static int my_fallocate(int fd, int mode, loff_t offset, loff_t len)
#undef _FILE_OFFSET_BITS
#ifndef __ANDROID__
// make sure the _FILE_OFFSET_BITS define worked
// on this platform. It's supposed to make file
// related functions support 64-bit offsets.
// this test makes sure lseek() returns a type
// at least 64 bits wide
BOOST_STATIC_ASSERT(sizeof(lseek(0, 0, 0)) >= 8);
#endif
#endif // posix part

5
libtorrent/src/utp_stream.cpp

@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. @@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/random.hpp"
#include "libtorrent/invariant_check.hpp"
#include <boost/cstdint.hpp>
#include <limits>
#define TORRENT_UTP_LOG 0
#define TORRENT_VERBOSE_UTP_LOG 0
@ -3098,8 +3099,8 @@ void utp_socket_impl::do_ledbat(int acked_bytes, int delay, int in_flight, ptime @@ -3098,8 +3099,8 @@ void utp_socket_impl::do_ledbat(int acked_bytes, int delay, int in_flight, ptime
}
// make sure we don't wrap the cwnd
if (scaled_gain >= INT64_MAX - m_cwnd)
scaled_gain = INT64_MAX - m_cwnd - 1;
if (scaled_gain >= std::numeric_limits<boost::int64_t>::max() - m_cwnd)
scaled_gain = std::numeric_limits<boost::int64_t>::max() - m_cwnd - 1;
if (scaled_gain > 0 && !m_cwnd_full
&& m_last_cwnd_hit + milliseconds(50) < now)

2
src/compat.h

@ -23,8 +23,10 @@ @@ -23,8 +23,10 @@
#include <netdb.h>
#include <net/if.h>
#include <netinet/in.h>
#ifndef __ANDROID__
#include <ifaddrs.h>
#endif
#endif
typedef u_int SOCKET;
#ifdef WIN32

170
src/net.cpp

@ -1637,6 +1637,176 @@ bool BindListenPort(const CService &addrBind, string& strError) @@ -1637,6 +1637,176 @@ bool BindListenPort(const CService &addrBind, string& strError)
return true;
}
#ifdef __ANDROID__
#include <sys/socket.h>
struct ifaddrs {
struct ifaddrs *ifa_next;
char *ifa_name;
unsigned int ifa_flags;
struct sockaddr *ifa_addr;
struct sockaddr *ifa_netmask;
union {
struct sockaddr *ifu_broadaddr;
struct sockaddr *ifu_dstaddr;
} ifa_ifu;
#define ifa_broadaddr ifa_ifu.ifu_broadaddr
#define ifa_dstaddr ifa_ifu.ifu_dstaddr
void *ifa_data;
};
extern int getifaddrs(struct ifaddrs **ifap);
extern void freeifaddrs(struct ifaddrs *ifa);
/* external/dhcpcd/ifaddrs.c
**
** Copyright 2011, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");.
** you may not use this file except in compliance with the License..
** You may obtain a copy of the License at.
**
** http://www.apache.org/licenses/LICENSE-2.0.
**
** Unless required by applicable law or agreed to in writing, software.
** distributed under the License is distributed on an "AS IS" BASIS,.
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied..
** See the License for the specific language governing permissions and.
** limitations under the License.
*/
#include <arpa/inet.h>
#include <sys/socket.h>
#include "ifaddrs.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <netinet/ether.h>
#include <netdb.h>
#include <linux/if_packet.h>
#include <netinet/if_ether.h>
#include <linux/if_arp.h>
#include <netutils/ifc.h>
struct ifaddrs *get_interface(const char *name, sa_family_t family)
{
unsigned addr, mask, flags;
struct ifaddrs *ifa;
struct sockaddr_in *saddr = NULL;
struct sockaddr_in *smask = NULL;
struct sockaddr_ll *hwaddr = NULL;
unsigned char hwbuf[ETH_ALEN];
if(ifc_get_info(name, &addr, &mask, &flags))
return NULL;
if ((family == AF_INET) && (addr == 0))
return NULL;
ifa = malloc(sizeof(struct ifaddrs));
if (!ifa)
return NULL;
memset(ifa, 0, sizeof(struct ifaddrs));
ifa->ifa_name = malloc(strlen(name)+1);
if (!ifa->ifa_name) {
free(ifa);
return NULL;
}
strcpy(ifa->ifa_name, name);
ifa->ifa_flags = flags;
if (family == AF_INET) {
saddr = malloc(sizeof(struct sockaddr_in));
if (saddr) {
saddr->sin_addr.s_addr = addr;
saddr->sin_family = family;
}
ifa->ifa_addr = (struct sockaddr *)saddr;
if (mask != 0) {
smask = malloc(sizeof(struct sockaddr_in));
if (smask) {
smask->sin_addr.s_addr = mask;
smask->sin_family = family;
}
}
ifa->ifa_netmask = (struct sockaddr *)smask;
} else if (family == AF_PACKET) {
if (!ifc_get_hwaddr(name, hwbuf)) {
hwaddr = malloc(sizeof(struct sockaddr_ll));
if (hwaddr) {
memset(hwaddr, 0, sizeof(struct sockaddr_ll));
hwaddr->sll_family = family;
/* hwaddr->sll_protocol = ETHERTYPE_IP; */
hwaddr->sll_hatype = ARPHRD_ETHER;
hwaddr->sll_halen = ETH_ALEN;
memcpy(hwaddr->sll_addr, hwbuf, ETH_ALEN);
}
}
ifa->ifa_addr = (struct sockaddr *)hwaddr;
ifa->ifa_netmask = (struct sockaddr *)smask;
}
return ifa;
}
int getifaddrs(struct ifaddrs **ifap)
{
DIR *d;
struct dirent *de;
struct ifaddrs *ifa;
struct ifaddrs *ifah = NULL;
if (!ifap)
return -1;
*ifap = NULL;
if (ifc_init())
return -1;
d = opendir("/sys/class/net");
if (d == 0)
return -1;
while ((de = readdir(d))) {
if (de->d_name[0] == '.')
continue;
ifa = get_interface(de->d_name, AF_INET);
if (ifa != NULL) {
ifa->ifa_next = ifah;
ifah = ifa;
}
ifa = get_interface(de->d_name, AF_PACKET);
if (ifa != NULL) {
ifa->ifa_next = ifah;
ifah = ifa;
}
}
*ifap = ifah;
closedir(d);
ifc_close();
return 0;
}
void freeifaddrs(struct ifaddrs *ifa)
{
struct ifaddrs *ifp;
while (ifa) {
ifp = ifa;
free(ifp->ifa_name);
if (ifp->ifa_addr)
free(ifp->ifa_addr);
if (ifp->ifa_netmask)
free(ifp->ifa_netmask);
ifa = ifa->ifa_next;
free(ifp);
}
}
#endif
void static Discover()
{
if (!fDiscover)

Loading…
Cancel
Save