aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2018-05-21 12:06:47 +0200
committerPierre Ossman <ossman@cendio.se>2018-05-29 14:38:25 +0200
commitd7bbbbf07ffaca2573974ca5b2fbfd1faf22a08a (patch)
tree63d6bb6a1ca0b03ae2dc2e1c3f26439cada70444 /common
parent5d05546fe48512f8f2294b85aa09fa7c8cc1933c (diff)
downloadtigervnc-d7bbbbf07ffaca2573974ca5b2fbfd1faf22a08a.tar.gz
tigervnc-d7bbbbf07ffaca2573974ca5b2fbfd1faf22a08a.zip
Remove unused code from socket classes
Diffstat (limited to 'common')
-rw-r--r--common/network/Socket.h22
-rw-r--r--common/network/TcpSocket.cxx65
-rw-r--r--common/network/TcpSocket.h8
-rw-r--r--common/network/UnixSocket.cxx28
-rw-r--r--common/network/UnixSocket.h10
5 files changed, 24 insertions, 109 deletions
diff --git a/common/network/Socket.h b/common/network/Socket.h
index 382b2702..39ac39b4 100644
--- a/common/network/Socket.h
+++ b/common/network/Socket.h
@@ -35,13 +35,11 @@ namespace network {
Socket(int fd)
: instream(new rdr::FdInStream(fd)),
outstream(new rdr::FdOutStream(fd)),
- ownStreams(true), isShutdown_(false),
+ isShutdown_(false),
queryConnection(false) {}
virtual ~Socket() {
- if (ownStreams) {
- delete instream;
- delete outstream;
- }
+ delete instream;
+ delete outstream;
}
rdr::FdInStream &inStream() {return *instream;}
rdr::FdOutStream &outStream() {return *outstream;}
@@ -52,30 +50,22 @@ namespace network {
bool isShutdown() const {return isShutdown_;}
virtual bool cork(bool enable) = 0;
- // information about this end of the socket
- virtual int getMyPort() = 0;
-
// information about the remote end of the socket
virtual char* getPeerAddress() = 0; // a string e.g. "192.168.0.1"
- virtual int getPeerPort() = 0;
virtual char* getPeerEndpoint() = 0; // <address>::<port>
- // Is the remote end on the same machine?
- virtual bool sameMachine() = 0;
-
// Was there a "?" in the ConnectionFilter used to accept this Socket?
void setRequiresQuery() {queryConnection = true;}
bool requiresQuery() const {return queryConnection;}
protected:
- Socket() : instream(0), outstream(0), ownStreams(false),
+ Socket() : instream(0), outstream(0),
isShutdown_(false), queryConnection(false) {}
- Socket(rdr::FdInStream* i, rdr::FdOutStream* o, bool own)
- : instream(i), outstream(o), ownStreams(own),
+ Socket(rdr::FdInStream* i, rdr::FdOutStream* o)
+ : instream(i), outstream(o),
isShutdown_(false), queryConnection(false) {}
rdr::FdInStream* instream;
rdr::FdOutStream* outstream;
- bool ownStreams;
bool isShutdown_;
bool queryConnection;
};
diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx
index 4287132e..555ce215 100644
--- a/common/network/TcpSocket.cxx
+++ b/common/network/TcpSocket.cxx
@@ -28,21 +28,19 @@
#else
#define errorNumber errno
#define closesocket close
-#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <errno.h>
-#include <string.h>
#include <signal.h>
#include <fcntl.h>
#endif
#include <stdlib.h>
#include <unistd.h>
+
#include <network/TcpSocket.h>
-#include <rfb/util.h>
#include <rfb/LogWriter.h>
#include <rfb/Configuration.h>
@@ -120,13 +118,12 @@ static void initSockets() {
// -=- TcpSocket
-TcpSocket::TcpSocket(int sock, bool close)
- : Socket(new FdInStream(sock), new FdOutStream(sock), true), closeFd(close)
+TcpSocket::TcpSocket(int sock)
+ : Socket(new FdInStream(sock), new FdOutStream(sock))
{
}
TcpSocket::TcpSocket(const char *host, int port)
- : closeFd(true)
{
int sock, err, result;
struct addrinfo *ai, *current, hints;
@@ -225,16 +222,10 @@ TcpSocket::TcpSocket(const char *host, int port)
// Create the input and output streams
instream = new FdInStream(sock);
outstream = new FdOutStream(sock);
- ownStreams = true;
}
TcpSocket::~TcpSocket() {
- if (closeFd)
- closesocket(getFd());
-}
-
-int TcpSocket::getMyPort() {
- return getSockPort(getFd());
+ closesocket(getFd());
}
char* TcpSocket::getPeerAddress() {
@@ -281,25 +272,20 @@ char* TcpSocket::getPeerAddress() {
return rfb::strDup("");
}
-int TcpSocket::getPeerPort() {
+char* TcpSocket::getPeerEndpoint() {
+ rfb::CharArray address; address.buf = getPeerAddress();
vnc_sockaddr_t sa;
socklen_t sa_size = sizeof(sa);
+ int port;
getpeername(getFd(), &sa.u.sa, &sa_size);
- switch (sa.u.sa.sa_family) {
- case AF_INET6:
- return ntohs(sa.u.sin6.sin6_port);
- case AF_INET:
- return ntohs(sa.u.sin.sin_port);
- default:
- return 0;
- }
-}
-
-char* TcpSocket::getPeerEndpoint() {
- rfb::CharArray address; address.buf = getPeerAddress();
- int port = getPeerPort();
+ if (sa.u.sa.sa_family == AF_INET6)
+ port = ntohs(sa.u.sin6.sin6_port);
+ else if (sa.u.sa.sa_family == AF_INET)
+ port = ntohs(sa.u.sin.sin_port);
+ else
+ port = 0;
int buflen = strlen(address.buf) + 32;
char* buffer = new char[buflen];
@@ -307,31 +293,6 @@ char* TcpSocket::getPeerEndpoint() {
return buffer;
}
-bool TcpSocket::sameMachine() {
- vnc_sockaddr_t peeraddr, myaddr;
- socklen_t addrlen;
-
- addrlen = sizeof(peeraddr);
- if (getpeername(getFd(), &peeraddr.u.sa, &addrlen) < 0)
- throw SocketException ("unable to get peer address", errorNumber);
-
- addrlen = sizeof(myaddr); /* need to reset, since getpeername overwrote */
- if (getsockname(getFd(), &myaddr.u.sa, &addrlen) < 0)
- throw SocketException ("unable to get my address", errorNumber);
-
- if (peeraddr.u.sa.sa_family != myaddr.u.sa.sa_family)
- return false;
-
- if (peeraddr.u.sa.sa_family == AF_INET6)
- return IN6_ARE_ADDR_EQUAL(&peeraddr.u.sin6.sin6_addr,
- &myaddr.u.sin6.sin6_addr);
- if (peeraddr.u.sa.sa_family == AF_INET)
- return (peeraddr.u.sin.sin_addr.s_addr == myaddr.u.sin.sin_addr.s_addr);
-
- // No idea what this is. Assume we're on different machines.
- return false;
-}
-
void TcpSocket::shutdown()
{
Socket::shutdown();
diff --git a/common/network/TcpSocket.h b/common/network/TcpSocket.h
index 74ff4c50..87d8e695 100644
--- a/common/network/TcpSocket.h
+++ b/common/network/TcpSocket.h
@@ -50,16 +50,12 @@ namespace network {
class TcpSocket : public Socket {
public:
- TcpSocket(int sock, bool close=true);
+ TcpSocket(int sock);
TcpSocket(const char *name, int port);
virtual ~TcpSocket();
- virtual int getMyPort();
-
virtual char* getPeerAddress();
- virtual int getPeerPort();
virtual char* getPeerEndpoint();
- virtual bool sameMachine();
virtual void shutdown();
virtual bool cork(bool enable);
@@ -67,8 +63,6 @@ namespace network {
static bool enableNagles(int sock, bool enable);
static bool isListening(int sock);
static int getSockPort(int sock);
- private:
- bool closeFd;
};
class TcpListener : public SocketListener {
diff --git a/common/network/UnixSocket.cxx b/common/network/UnixSocket.cxx
index f464ac85..8a223e40 100644
--- a/common/network/UnixSocket.cxx
+++ b/common/network/UnixSocket.cxx
@@ -21,13 +21,11 @@
#include <config.h>
#endif
-#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <errno.h>
-#include <string.h>
#include <signal.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -53,13 +51,12 @@ static void initSockets() {
// -=- UnixSocket
-UnixSocket::UnixSocket(int sock, bool close)
- : Socket(new FdInStream(sock), new FdOutStream(sock), true), closeFd(close)
+UnixSocket::UnixSocket(int sock)
+ : Socket(new FdInStream(sock), new FdOutStream(sock))
{
}
UnixSocket::UnixSocket(const char *path)
- : closeFd(true)
{
int sock, err, result;
sockaddr_un addr;
@@ -94,16 +91,10 @@ UnixSocket::UnixSocket(const char *path)
// Create the input and output streams
instream = new FdInStream(sock);
outstream = new FdOutStream(sock);
- ownStreams = true;
}
UnixSocket::~UnixSocket() {
- if (closeFd)
- close(getFd());
-}
-
-int UnixSocket::getMyPort() {
- return 0;
+ close(getFd());
}
char* UnixSocket::getPeerAddress() {
@@ -137,18 +128,10 @@ char* UnixSocket::getPeerAddress() {
return rfb::strDup("(unnamed UNIX socket)");
}
-int UnixSocket::getPeerPort() {
- return 0;
-}
-
char* UnixSocket::getPeerEndpoint() {
return getPeerAddress();
}
-bool UnixSocket::sameMachine() {
- return true;
-}
-
void UnixSocket::shutdown()
{
Socket::shutdown();
@@ -208,11 +191,6 @@ UnixListener::UnixListener(const char *path, int mode)
}
}
-UnixListener::UnixListener(int sock)
-{
- fd = sock;
-}
-
UnixListener::~UnixListener()
{
struct sockaddr_un addr;
diff --git a/common/network/UnixSocket.h b/common/network/UnixSocket.h
index 30eda787..48c5b63f 100644
--- a/common/network/UnixSocket.h
+++ b/common/network/UnixSocket.h
@@ -35,28 +35,20 @@ namespace network {
class UnixSocket : public Socket {
public:
- UnixSocket(int sock, bool close=true);
+ UnixSocket(int sock);
UnixSocket(const char *name);
virtual ~UnixSocket();
- virtual int getMyPort();
-
virtual char* getPeerAddress();
- virtual int getPeerPort();
virtual char* getPeerEndpoint();
- virtual bool sameMachine();
virtual void shutdown();
virtual bool cork(bool enable);
-
- private:
- bool closeFd;
};
class UnixListener : public SocketListener {
public:
UnixListener(const char *listenaddr, int mode);
- UnixListener(int sock);
virtual ~UnixListener();
virtual void shutdown();