refactored ISocket into IDataSocket. the latter and IListenSocket

now derive from ISocket.
This commit is contained in:
crs 2002-06-17 12:02:26 +00:00
parent e3dcf7febf
commit 57fb87ad10
14 changed files with 78 additions and 59 deletions

View File

@ -197,7 +197,7 @@ CClient::runSession(void*)
{
log((CLOG_DEBUG "starting client \"%s\"", m_name.c_str()));
std::auto_ptr<ISocket> socket;
std::auto_ptr<IDataSocket> socket;
std::auto_ptr<IInputStream> input;
std::auto_ptr<IOutputStream> output;
try {
@ -209,7 +209,7 @@ CClient::runSession(void*)
// create socket and attempt to connect to server
log((CLOG_DEBUG1 "connecting to server"));
assign(socket, new CTCPSocket(), ISocket); // FIXME -- use factory
assign(socket, new CTCPSocket(), IDataSocket); // FIXME -- use factory
socket->connect(*m_serverAddress);
log((CLOG_INFO "connected to server"));
break;

View File

@ -43,7 +43,7 @@ CTCPListenSocket::bind(
}
}
ISocket*
IDataSocket*
CTCPListenSocket::accept()
{
CNetwork::PollEntry pfds[1];

View File

@ -13,11 +13,13 @@ public:
// accessors
// IListenSocket overrides
// ISocket overrides
virtual void bind(const CNetworkAddress&);
virtual ISocket* accept();
virtual void close();
// IListenSocket overrides
virtual IDataSocket* accept();
private:
CNetwork::Socket m_fd;
};

View File

@ -67,23 +67,6 @@ CTCPSocket::bind(
}
}
void
CTCPSocket::connect(
const CNetworkAddress& addr)
{
CThread::testCancel();
if (CNetwork::connect(m_fd, addr.getAddress(),
addr.getAddressLength()) == CNetwork::Error) {
CThread::testCancel();
throw XSocketConnect();
}
// start servicing the socket
m_connected = kReadWrite;
m_thread = new CThread(new TMethodJob<CTCPSocket>(
this, &CTCPSocket::ioThread));
}
void
CTCPSocket::close()
{
@ -124,6 +107,23 @@ CTCPSocket::close()
}
}
void
CTCPSocket::connect(
const CNetworkAddress& addr)
{
CThread::testCancel();
if (CNetwork::connect(m_fd, addr.getAddress(),
addr.getAddressLength()) == CNetwork::Error) {
CThread::testCancel();
throw XSocketConnect();
}
// start servicing the socket
m_connected = kReadWrite;
m_thread = new CThread(new TMethodJob<CTCPSocket>(
this, &CTCPSocket::ioThread));
}
IInputStream*
CTCPSocket::getInputStream()
{

View File

@ -1,7 +1,7 @@
#ifndef CTCPSOCKET_H
#define CTCPSOCKET_H
#include "ISocket.h"
#include "IDataSocket.h"
#include "CNetwork.h"
class CMutex;
@ -11,7 +11,7 @@ class CThread;
class CBufferedInputStream;
class CBufferedOutputStream;
class CTCPSocket : public ISocket {
class CTCPSocket : public IDataSocket {
public:
CTCPSocket();
CTCPSocket(CNetwork::Socket);
@ -23,8 +23,10 @@ public:
// ISocket overrides
virtual void bind(const CNetworkAddress&);
virtual void connect(const CNetworkAddress&);
virtual void close();
// IDataSocket overrides
virtual void connect(const CNetworkAddress&);
virtual IInputStream* getInputStream();
virtual IOutputStream* getOutputStream();

28
net/IDataSocket.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef IDATASOCKET_H
#define IDATASOCKET_H
#include "ISocket.h"
class IInputStream;
class IOutputStream;
class IDataSocket : public ISocket {
public:
// manipulators
// connect the socket
virtual void connect(const CNetworkAddress&) = 0;
// get the input and output streams for the socket. closing
// these streams closes the appropriate half of the socket.
virtual IInputStream* getInputStream() = 0;
virtual IOutputStream* getOutputStream() = 0;
// accessors
// ISocket overrides
virtual void bind(const CNetworkAddress&) = 0;
virtual void close() = 0;
};
#endif

View File

@ -1,25 +1,22 @@
#ifndef ILISTENSOCKET_H
#define ILISTENSOCKET_H
#include "IInterface.h"
#include "ISocket.h"
class CNetworkAddress;
class ISocket;
class IDataSocket;
class IListenSocket : public IInterface {
class IListenSocket : public ISocket {
public:
// manipulators
// bind the socket to a particular address
virtual void bind(const CNetworkAddress&) = 0;
// wait for a connection
virtual ISocket* accept() = 0;
virtual IDataSocket* accept() = 0;
// close the socket
virtual void close() = 0;
// accessors
// ISocket overrides
virtual void bind(const CNetworkAddress&) = 0;
virtual void close() = 0;
};
#endif

View File

@ -4,8 +4,6 @@
#include "IInterface.h"
class CNetworkAddress;
class IInputStream;
class IOutputStream;
class ISocket : public IInterface {
public:
@ -14,18 +12,10 @@ public:
// bind the socket to a particular address
virtual void bind(const CNetworkAddress&) = 0;
// connect the socket
virtual void connect(const CNetworkAddress&) = 0;
// close the socket. this will flush the output stream if it
// hasn't been closed yet.
virtual void close() = 0;
// get the input and output streams for the socket. closing
// these streams closes the appropriate half of the socket.
virtual IInputStream* getInputStream() = 0;
virtual IOutputStream* getOutputStream() = 0;
// accessors
};

View File

@ -3,7 +3,7 @@
#include "CHTTPProtocol.h"
#include "CServer.h"
#include "XHTTP.h"
#include "ISocket.h"
#include "IDataSocket.h"
#include "XThread.h"
#include "CLog.h"
#include "stdset.h"
@ -32,7 +32,7 @@ CHTTPServer::~CHTTPServer()
void
CHTTPServer::processRequest(
ISocket* socket)
IDataSocket* socket)
{
assert(socket != NULL);

View File

@ -9,7 +9,7 @@ class CServer;
class CConfig;
class CHTTPRequest;
class CHTTPReply;
class ISocket;
class IDataSocket;
class CHTTPServer {
public:
@ -19,7 +19,7 @@ public:
// manipulators
// synchronously process an HTTP request on the given socket
void processRequest(ISocket*);
void processRequest(IDataSocket*);
// accessors

View File

@ -9,8 +9,8 @@
#include "XScreen.h"
#include "XSynergy.h"
#include "CNetworkAddress.h"
#include "IDataSocket.h"
#include "IListenSocket.h"
#include "ISocket.h"
#include "ISocketFactory.h"
#include "XSocket.h"
#include "CLock.h"
@ -1088,7 +1088,7 @@ CServer::acceptClients(void*)
for (;;) {
// accept connection
CThread::testCancel();
ISocket* socket = listen->accept();
IDataSocket* socket = listen->accept();
log((CLOG_NOTE "accepted client connection"));
CThread::testCancel();
@ -1111,7 +1111,7 @@ CServer::handshakeClient(
// get the socket pointer from the argument
assert(vsocket != NULL);
std::auto_ptr<ISocket> socket(reinterpret_cast<ISocket*>(vsocket));
std::auto_ptr<IDataSocket> socket(reinterpret_cast<IDataSocket*>(vsocket));
// add this thread to the list of threads to cancel. remove from
// list in d'tor.
@ -1289,7 +1289,7 @@ CServer::acceptHTTPClients(void*)
// accept connection
CThread::testCancel();
ISocket* socket = listen->accept();
IDataSocket* socket = listen->accept();
log((CLOG_NOTE "accepted HTTP connection"));
CThread::testCancel();
@ -1313,7 +1313,7 @@ CServer::processHTTPRequest(
// list in d'tor.
CCleanupNote cleanupNote(this);
ISocket* socket = reinterpret_cast<ISocket*>(vsocket);
IDataSocket* socket = reinterpret_cast<IDataSocket*>(vsocket);
try {
// process the request and force delivery
m_httpServer->processRequest(socket);

View File

@ -16,7 +16,7 @@ CTCPSocketFactory::~CTCPSocketFactory()
// do nothing
}
ISocket*
IDataSocket*
CTCPSocketFactory::create() const
{
return new CTCPSocket;

View File

@ -13,7 +13,7 @@ public:
// accessors
// ISocketFactory overrides
virtual ISocket* create() const;
virtual IDataSocket* create() const;
virtual IListenSocket* createListen() const;
};

View File

@ -3,7 +3,7 @@
#include "IInterface.h"
class ISocket;
class IDataSocket;
class IListenSocket;
class ISocketFactory : public IInterface {
@ -13,7 +13,7 @@ public:
// accessors
// create sockets
virtual ISocket* create() const = 0;
virtual IDataSocket* create() const = 0;
virtual IListenSocket* createListen() const = 0;
};