rfspace: Remove broken asio code

Asio sockets were replaced with native BSD sockets in
e1b699fda0, and the old code was placed
behind #ifdef USE_ASIO. Subsequent commits soon broke the asio code.
Since it's been broken for a long time, I doubt anyone is using it, so
it makes sense to remove it.

Signed-off-by: Eric Wild <ewild@sysmocom.de>
This commit is contained in:
Clayton Smith 2020-10-22 23:06:12 -04:00 committed by Eric Wild
parent e5bee0820f
commit 2d504bde50
2 changed files with 0 additions and 162 deletions

View File

@ -27,7 +27,6 @@
#include "config.h" #include "config.h"
#endif #endif
#ifndef USE_ASIO
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -35,7 +34,6 @@
#include <netinet/udp.h> #include <netinet/udp.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h> #include <netdb.h>
#endif
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
@ -54,9 +52,6 @@
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#ifdef USE_ASIO
#include <boost/asio/deadline_timer.hpp>
#endif
#include <gnuradio/io_signature.h> #include <gnuradio/io_signature.h>
@ -64,9 +59,6 @@
#include "rfspace_source_c.h" #include "rfspace_source_c.h"
using namespace boost::assign; using namespace boost::assign;
#ifdef USE_ASIO
using boost::asio::deadline_timer;
#endif
#define DEFAULT_HOST "127.0.0.1" /* We assume a running "siqs" from CuteSDR project */ #define DEFAULT_HOST "127.0.0.1" /* We assume a running "siqs" from CuteSDR project */
#define DEFAULT_PORT 50000 #define DEFAULT_PORT 50000
@ -102,15 +94,8 @@ rfspace_source_c::rfspace_source_c (const std::string &args)
gr::io_signature::make (MIN_IN, MAX_IN, sizeof (gr_complex)), gr::io_signature::make (MIN_IN, MAX_IN, sizeof (gr_complex)),
gr::io_signature::make (MIN_OUT, MAX_OUT, sizeof (gr_complex))), gr::io_signature::make (MIN_OUT, MAX_OUT, sizeof (gr_complex))),
_radio(RADIO_UNKNOWN), _radio(RADIO_UNKNOWN),
#ifdef USE_ASIO
_io_service(),
_resolver(_io_service),
_t(_io_service),
_u(_io_service),
#else
_tcp(-1), _tcp(-1),
_udp(-1), _udp(-1),
#endif
_usb(-1), _usb(-1),
_running(false), _running(false),
_keep_running(false), _keep_running(false),
@ -239,30 +224,6 @@ rfspace_source_c::rfspace_source_c (const std::string &args)
/* SDR-IP 4.4.4 Data Output UDP IP and Port Address */ /* SDR-IP 4.4.4 Data Output UDP IP and Port Address */
/* NETSDR 4.4.3 Data Output UDP IP and Port Address */ /* NETSDR 4.4.3 Data Output UDP IP and Port Address */
#ifdef USE_ASIO
tcp::resolver::query query(tcp::v4(), host.c_str(), port_str.c_str());
tcp::resolver::iterator iterator = _resolver.resolve(query);
boost::system::error_code ec;
boost::asio::connect(_t, iterator, ec);
if ( ec )
throw std::runtime_error(ec.message() + " (" + host + ":" + port_str + ")");
_u.open(udp::v4(), ec);
if ( ec )
throw std::runtime_error(ec.message());
_u.bind(udp::endpoint(udp::v4(), DEFAULT_PORT), ec);
if ( ec )
throw std::runtime_error(ec.message());
_u.set_option(udp::socket::reuse_address(true));
_t.set_option(udp::socket::reuse_address(true));
#else
if ( (_tcp = socket(AF_INET, SOCK_STREAM, 0) ) < 0) if ( (_tcp = socket(AF_INET, SOCK_STREAM, 0) ) < 0)
{ {
throw std::runtime_error("Could not create TCP socket"); throw std::runtime_error("Could not create TCP socket");
@ -339,8 +300,6 @@ rfspace_source_c::rfspace_source_c (const std::string &args)
throw std::runtime_error("Bind of UDP socket failed: " + std::string(strerror(errno))); throw std::runtime_error("Bind of UDP socket failed: " + std::string(strerror(errno)));
} }
#endif
} }
/* Wait 10 ms before sending queries to device (required for networked radios). */ /* Wait 10 ms before sending queries to device (required for networked radios). */
@ -506,10 +465,8 @@ rfspace_source_c::rfspace_source_c (const std::string &args)
*/ */
rfspace_source_c::~rfspace_source_c () rfspace_source_c::~rfspace_source_c ()
{ {
#ifndef USE_ASIO
close(_tcp); close(_tcp);
close(_udp); close(_udp);
#endif
if ( RFSPACE_SDR_IQ == _radio ) if ( RFSPACE_SDR_IQ == _radio )
{ {
@ -600,11 +557,6 @@ bool rfspace_source_c::transaction( const unsigned char *cmd, size_t size,
{ {
std::lock_guard<std::mutex> lock(_tcp_lock); std::lock_guard<std::mutex> lock(_tcp_lock);
#ifdef USE_ASIO
_t.write_some( boost::asio::buffer(cmd, size) );
rx_bytes = _t.read_some( boost::asio::buffer(data, sizeof(data)) );
#else
if ( write(_tcp, cmd, size) != (int)size ) if ( write(_tcp, cmd, size) != (int)size )
return false; return false;
@ -624,7 +576,6 @@ bool rfspace_source_c::transaction( const unsigned char *cmd, size_t size,
return false; return false;
rx_bytes = 2 + length; /* header + payload */ rx_bytes = 2 + length; /* header + payload */
#endif
} }
response.resize( rx_bytes ); response.resize( rx_bytes );
@ -852,10 +803,6 @@ int rfspace_source_c::work( int noutput_items,
return noutput_items; return noutput_items;
} }
#ifdef USE_ASIO
udp::endpoint ep;
size_t rx_bytes = _u.receive_from( boost::asio::buffer(data, sizeof(data)), ep );
#else
struct sockaddr_in sa_in; /* remote address */ struct sockaddr_in sa_in; /* remote address */
socklen_t addrlen = sizeof(sa_in); /* length of addresses */ socklen_t addrlen = sizeof(sa_in); /* length of addresses */
ssize_t rx_bytes = recvfrom(_udp, data, sizeof(data), 0, (struct sockaddr *)&sa_in, &addrlen); ssize_t rx_bytes = recvfrom(_udp, data, sizeof(data), 0, (struct sockaddr *)&sa_in, &addrlen);
@ -864,7 +811,6 @@ int rfspace_source_c::work( int noutput_items,
std::cerr << "recvfrom returned " << rx_bytes << std::endl; std::cerr << "recvfrom returned " << rx_bytes << std::endl;
return WORK_DONE; return WORK_DONE;
} }
#endif
#define HEADER_SIZE 2 #define HEADER_SIZE 2
#define SEQNUM_SIZE 2 #define SEQNUM_SIZE 2
@ -892,11 +838,7 @@ int rfspace_source_c::work( int noutput_items,
if ( diff > 1 ) if ( diff > 1 )
{ {
std::cerr << "Lost " << diff << " packets from " std::cerr << "Lost " << diff << " packets from "
#ifdef USE_ASIO
<< ep
#else
<< inet_ntoa(sa_in.sin_addr) << ":" << ntohs(sa_in.sin_port) << inet_ntoa(sa_in.sin_addr) << ":" << ntohs(sa_in.sin_port)
#endif
<< std::endl; << std::endl;
} }
@ -977,48 +919,11 @@ typedef struct
uint16_t port; uint16_t port;
} unit_t; } unit_t;
#ifdef USE_ASIO
static void handle_receive( const boost::system::error_code& ec,
std::size_t length,
boost::system::error_code* out_ec,
std::size_t* out_length )
{
*out_ec = ec;
*out_length = length;
}
static void handle_timer( const boost::system::error_code& ec,
boost::system::error_code* out_ec )
{
*out_ec = boost::asio::error::timed_out;
}
#endif
static std::vector < unit_t > discover_netsdr() static std::vector < unit_t > discover_netsdr()
{ {
std::vector < unit_t > units; std::vector < unit_t > units;
#ifdef USE_ASIO
boost::system::error_code ec;
boost::asio::io_service ios;
udp::socket socket(ios);
deadline_timer timer(ios);
timer.expires_at(boost::posix_time::pos_infin);
socket.open(udp::v4(), ec);
if ( ec )
return units;
socket.bind(udp::endpoint(udp::v4(), DISCOVER_CLIENT_PORT), ec);
if ( ec )
return units;
socket.set_option(udp::socket::reuse_address(true));
socket.set_option(boost::asio::socket_base::broadcast(true));
#else
int sock; int sock;
if ( (sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) if ( (sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0 )
@ -1058,7 +963,6 @@ static std::vector < unit_t > discover_netsdr()
close(sock); close(sock);
return units; return units;
} }
#endif
discover_common_msg_t tx_msg; discover_common_msg_t tx_msg;
memset( (void *)&tx_msg, 0, sizeof(discover_common_msg_t) ); memset( (void *)&tx_msg, 0, sizeof(discover_common_msg_t) );
@ -1067,64 +971,18 @@ static std::vector < unit_t > discover_netsdr()
tx_msg.key[0] = KEY0; tx_msg.key[0] = KEY0;
tx_msg.key[1] = KEY1; tx_msg.key[1] = KEY1;
tx_msg.op = MSG_REQ; tx_msg.op = MSG_REQ;
#ifdef USE_ASIO
udp::endpoint ep(boost::asio::ip::address_v4::broadcast(), DISCOVER_SERVER_PORT);
socket.send_to(boost::asio::buffer(&tx_msg, sizeof(tx_msg)), ep);
#else
sendto(sock, &tx_msg, sizeof(tx_msg), 0, (struct sockaddr *)&peer_sa, sizeof(peer_sa)); sendto(sock, &tx_msg, sizeof(tx_msg), 0, (struct sockaddr *)&peer_sa, sizeof(peer_sa));
#endif
while ( true ) while ( true )
{ {
std::size_t rx_bytes = 0; std::size_t rx_bytes = 0;
unsigned char data[1024*2]; unsigned char data[1024*2];
#ifdef USE_ASIO
// Set up the variables that receive the result of the asynchronous
// operation. The error code is set to would_block to signal that the
// operation is incomplete. Asio guarantees that its asynchronous
// operations will never fail with would_block, so any other value in
// ec indicates completion.
ec = boost::asio::error::would_block;
// Start the asynchronous receive operation. The handle_receive function
// used as a callback will update the ec and rx_bytes variables.
socket.async_receive( boost::asio::buffer(data, sizeof(data)),
boost::bind(handle_receive, _1, _2, &ec, &rx_bytes) );
// Set a deadline for the asynchronous operation.
timer.expires_from_now( boost::posix_time::milliseconds(10) );
// Start an asynchronous wait on the timer. The handle_timer function
// used as a callback will update the ec variable.
timer.async_wait( boost::bind(handle_timer, _1, &ec) );
// Reset the io_service in preparation for a subsequent run_one() invocation.
ios.reset();
// Block until at least one asynchronous operation has completed.
do ios.run_one(); while ( ec == boost::asio::error::would_block );
if ( boost::asio::error::timed_out == ec ) /* timer was first to complete */
{
// Please note that cancel() has portability issues on some versions of
// Microsoft Windows, and it may be necessary to use close() instead.
// Consult the documentation for cancel() for further information.
socket.cancel();
break;
}
else /* socket was first to complete */
{
timer.cancel();
}
#else
socklen_t addrlen = sizeof(peer_sa); /* length of addresses */ socklen_t addrlen = sizeof(peer_sa); /* length of addresses */
int nbytes = recvfrom(sock, data, sizeof(data), 0, (struct sockaddr *)&peer_sa, &addrlen); int nbytes = recvfrom(sock, data, sizeof(data), 0, (struct sockaddr *)&peer_sa, &addrlen);
if ( nbytes <= 0 ) if ( nbytes <= 0 )
break; break;
rx_bytes = nbytes; rx_bytes = nbytes;
#endif
if ( rx_bytes >= sizeof(discover_common_msg_t) ) if ( rx_bytes >= sizeof(discover_common_msg_t) )
{ {
@ -1151,11 +1009,7 @@ static std::vector < unit_t > discover_netsdr()
} }
} }
} }
#ifdef USE_ASIO
socket.close(ec);
#else
close(sock); close(sock);
#endif
return units; return units;
} }

View File

@ -20,11 +20,6 @@
#ifndef INCLUDED_RFSPACE_SOURCE_C_H #ifndef INCLUDED_RFSPACE_SOURCE_C_H
#define INCLUDED_RFSPACE_SOURCE_C_H #define INCLUDED_RFSPACE_SOURCE_C_H
//#define USE_ASIO
#ifdef USE_ASIO
#include <boost/asio.hpp>
#endif
#include <gnuradio/thread/thread.h> #include <gnuradio/thread/thread.h>
#include <gnuradio/block.h> #include <gnuradio/block.h>
#include <gnuradio/sync_block.h> #include <gnuradio/sync_block.h>
@ -36,10 +31,6 @@
#include "osmosdr/ranges.h" #include "osmosdr/ranges.h"
#include "source_iface.h" #include "source_iface.h"
#ifdef USE_ASIO
using boost::asio::ip::tcp;
using boost::asio::ip::udp;
#endif
class rfspace_source_c; class rfspace_source_c;
#ifndef SOCKET #ifndef SOCKET
@ -144,15 +135,8 @@ private: /* members */
radio_type _radio; radio_type _radio;
#ifdef USE_ASIO
boost::asio::io_service _io_service;
tcp::resolver _resolver;
tcp::socket _t;
udp::socket _u;
#else
SOCKET _tcp; SOCKET _tcp;
SOCKET _udp; SOCKET _udp;
#endif
int _usb; int _usb;
bool _running; bool _running;
bool _keep_running; bool _keep_running;