mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-07 18:52:30 +00:00
Remove deprecated rak::socket_address.
This commit is contained in:
+15
-121
@@ -1,37 +1,3 @@
|
||||
// libTorrent - BitTorrent library
|
||||
// Copyright (C) 2005-2011, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <sundell.software@gmail.com>
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <errno.h>
|
||||
@@ -44,9 +10,9 @@
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <rak/socket_address.h>
|
||||
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/net/socket_address.h>
|
||||
|
||||
#include "socket_fd.h"
|
||||
|
||||
namespace utils {
|
||||
@@ -131,11 +97,11 @@ SocketFd::get_error() const {
|
||||
|
||||
bool
|
||||
SocketFd::open_stream() {
|
||||
m_fd = socket(rak::socket_address::pf_inet6, SOCK_STREAM, IPPROTO_TCP);
|
||||
m_fd = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
if (m_fd == -1) {
|
||||
m_ipv6_socket = false;
|
||||
return (m_fd = socket(rak::socket_address::pf_inet, SOCK_STREAM, IPPROTO_TCP)) != -1;
|
||||
return (m_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) != -1;
|
||||
}
|
||||
|
||||
m_ipv6_socket = true;
|
||||
@@ -146,10 +112,10 @@ SocketFd::open_stream() {
|
||||
|
||||
bool
|
||||
SocketFd::open_datagram() {
|
||||
m_fd = socket(rak::socket_address::pf_inet6, SOCK_DGRAM, 0);
|
||||
m_fd = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
if (m_fd == -1) {
|
||||
m_ipv6_socket = false;
|
||||
return (m_fd = socket(rak::socket_address::pf_inet, SOCK_DGRAM, 0)) != -1;
|
||||
return (m_fd = socket(AF_INET, SOCK_DGRAM, 0)) != -1;
|
||||
}
|
||||
m_ipv6_socket = true;
|
||||
|
||||
@@ -159,7 +125,7 @@ SocketFd::open_datagram() {
|
||||
|
||||
bool
|
||||
SocketFd::open_local() {
|
||||
return (m_fd = socket(rak::socket_address::pf_local, SOCK_STREAM, 0)) != -1;
|
||||
return (m_fd = socket(AF_LOCAL, SOCK_STREAM, 0)) != -1;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -169,55 +135,18 @@ SocketFd::close() {
|
||||
}
|
||||
|
||||
bool
|
||||
SocketFd::bind(const rak::socket_address& sa) {
|
||||
SocketFd::bind_sa(const sockaddr* sa, unsigned int length) {
|
||||
check_valid();
|
||||
|
||||
if (m_ipv6_socket && sa.family() == rak::socket_address::pf_inet) {
|
||||
rak::socket_address_inet6 sa_mapped = sa.sa_inet()->to_mapped_address();
|
||||
return !::bind(m_fd, sa_mapped.c_sockaddr(), sizeof(sa_mapped));
|
||||
if (m_ipv6_socket && sa->sa_family == AF_INET) {
|
||||
if (length < sizeof(sockaddr_in))
|
||||
throw torrent::input_error("SocketFd::bind_sa: invalid sockaddr length for AF_INET");
|
||||
|
||||
auto mapped_sa = torrent::sin6_to_v4mapped_in(reinterpret_cast<const sockaddr_in*>(sa));
|
||||
return !::bind(m_fd, reinterpret_cast<const sockaddr*>(mapped_sa.get()), sizeof(sockaddr_in6));
|
||||
}
|
||||
|
||||
return !::bind(m_fd, sa.c_sockaddr(), sa.length());
|
||||
}
|
||||
|
||||
bool
|
||||
SocketFd::bind(const rak::socket_address& sa, unsigned int length) {
|
||||
check_valid();
|
||||
|
||||
if (m_ipv6_socket && sa.family() == rak::socket_address::pf_inet) {
|
||||
rak::socket_address_inet6 sa_mapped = sa.sa_inet()->to_mapped_address();
|
||||
return !::bind(m_fd, sa_mapped.c_sockaddr(), sizeof(sa_mapped));
|
||||
}
|
||||
|
||||
return !::bind(m_fd, sa.c_sockaddr(), length);
|
||||
}
|
||||
|
||||
bool
|
||||
SocketFd::connect(const rak::socket_address& sa) {
|
||||
check_valid();
|
||||
|
||||
if (m_ipv6_socket && sa.family() == rak::socket_address::pf_inet) {
|
||||
rak::socket_address_inet6 sa_mapped = sa.sa_inet()->to_mapped_address();
|
||||
return !::connect(m_fd, sa_mapped.c_sockaddr(), sizeof(sa_mapped)) || errno == EINPROGRESS;
|
||||
}
|
||||
|
||||
return !::connect(m_fd, sa.c_sockaddr(), sa.length()) || errno == EINPROGRESS;
|
||||
}
|
||||
|
||||
bool
|
||||
SocketFd::getsockname(rak::socket_address *sa) {
|
||||
check_valid();
|
||||
|
||||
socklen_t len = sizeof(rak::socket_address);
|
||||
if (::getsockname(m_fd, sa->c_sockaddr(), &len)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_ipv6_socket && sa->family() == rak::socket_address::af_inet6) {
|
||||
*sa = sa->sa_inet6()->normalize_address();
|
||||
}
|
||||
|
||||
return true;
|
||||
return !::bind(m_fd, sa, length);
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -227,39 +156,4 @@ SocketFd::listen(int size) {
|
||||
return !::listen(m_fd, size);
|
||||
}
|
||||
|
||||
SocketFd
|
||||
SocketFd::accept(rak::socket_address* sa) {
|
||||
check_valid();
|
||||
socklen_t len = sizeof(rak::socket_address);
|
||||
|
||||
if (sa == NULL) {
|
||||
return SocketFd(::accept(m_fd, NULL, &len));
|
||||
}
|
||||
int fd = ::accept(m_fd, sa->c_sockaddr(), &len);
|
||||
if (fd != -1 && m_ipv6_socket && sa->family() == rak::socket_address::af_inet6) {
|
||||
*sa = sa->sa_inet6()->normalize_address();
|
||||
}
|
||||
return SocketFd(fd);
|
||||
}
|
||||
|
||||
// unsigned int
|
||||
// SocketFd::get_read_queue_size() const {
|
||||
// unsigned int v;
|
||||
|
||||
// if (!is_valid() || ioctl(m_fd, SIOCINQ, &v) < 0)
|
||||
// throw internal_error("SocketFd::get_read_queue_size() could not be performed");
|
||||
|
||||
// return v;
|
||||
// }
|
||||
|
||||
// unsigned int
|
||||
// SocketFd::get_write_queue_size() const {
|
||||
// unsigned int v;
|
||||
|
||||
// if (!is_valid() || ioctl(m_fd, SIOCOUTQ, &v) < 0)
|
||||
// throw internal_error("SocketFd::get_write_queue_size() could not be performed");
|
||||
|
||||
// return v;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user