Skip to content

Commit

Permalink
libshell|Refactor|AbstractLink: Made virtual connection and disconnec…
Browse files Browse the repository at this point in the history
…tion methods
  • Loading branch information
skyjake committed Feb 21, 2013
1 parent 2e19178 commit 16280db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions doomsday/libshell/include/de/shell/abstractlink.h
Expand Up @@ -57,26 +57,26 @@ class LIBSHELL_PUBLIC AbstractLink : public QObject, public Transmitter
* @param domain Domain/IP address of the server.
* @param timeout Keep trying until this much time has passed.
*/
void connect(String const &domain, TimeDelta const &timeout = 0);
virtual void connectDomain(String const &domain, TimeDelta const &timeout = 0);

/**
* Opens a connection to a server over the network.
*
* @param address Address of the server.
*/
void connect(Address const &address);
virtual void connectHost(Address const &address);

/**
* Takes over an existing socket.
*
* @param openSocket Socket. AbstractLink takes ownership.
*/
void takeOver(Socket *openSocket);
virtual void takeOver(Socket *openSocket);

/**
* Closes the connection.
*/
void disconnect();
virtual void disconnect();

/**
* Peer address of the link. The address may be a null address if the IP
Expand Down
22 changes: 11 additions & 11 deletions doomsday/libshell/src/abstractlink.cpp
Expand Up @@ -51,16 +51,16 @@ AbstractLink::~AbstractLink()
delete d;
}

void AbstractLink::connect(String const &domain, TimeDelta const &timeout)
void AbstractLink::connectDomain(String const &domain, TimeDelta const &timeout)
{
disconnect();

d->socket.reset(new Socket);

QObject::connect(d->socket.get(), SIGNAL(addressResolved()), this, SIGNAL(addressResolved()));
QObject::connect(d->socket.get(), SIGNAL(connected()), this, SLOT(socketConnected()));
QObject::connect(d->socket.get(), SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
QObject::connect(d->socket.get(), SIGNAL(messagesReady()), this, SIGNAL(packetsReady()));
connect(d->socket.get(), SIGNAL(addressResolved()), this, SIGNAL(addressResolved()));
connect(d->socket.get(), SIGNAL(connected()), this, SLOT(socketConnected()));
connect(d->socket.get(), SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
connect(d->socket.get(), SIGNAL(messagesReady()), this, SIGNAL(packetsReady()));

// Fallback to default port.
d->tryingToConnectToHost = domain;
Expand All @@ -72,16 +72,16 @@ void AbstractLink::connect(String const &domain, TimeDelta const &timeout)
d->timeout = timeout;
}

void AbstractLink::connect(Address const &address)
void AbstractLink::connectHost(Address const &address)
{
disconnect();

d->peerAddress = address;
d->socket.reset(new Socket);

QObject::connect(d->socket.get(), SIGNAL(connected()), this, SLOT(socketConnected()));
QObject::connect(d->socket.get(), SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
QObject::connect(d->socket.get(), SIGNAL(messagesReady()), this, SIGNAL(packetsReady()));
connect(d->socket.get(), SIGNAL(connected()), this, SLOT(socketConnected()));
connect(d->socket.get(), SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
connect(d->socket.get(), SIGNAL(messagesReady()), this, SIGNAL(packetsReady()));

// Fallback to default port.
if(!d->peerAddress.port()) d->peerAddress.setPort(13209);
Expand All @@ -101,8 +101,8 @@ void AbstractLink::takeOver(Socket *openSocket)
d->socket.reset(openSocket);

// Note: socketConnected() not used because the socket is already open.
QObject::connect(d->socket.get(), SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
QObject::connect(d->socket.get(), SIGNAL(messagesReady()), this, SIGNAL(packetsReady()));
connect(d->socket.get(), SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
connect(d->socket.get(), SIGNAL(messagesReady()), this, SIGNAL(packetsReady()));

d->status = Connected;
d->connectedAt = Time();
Expand Down
4 changes: 2 additions & 2 deletions doomsday/libshell/src/link.cpp
Expand Up @@ -38,12 +38,12 @@ DENG2_PIMPL(Link)

Link::Link(String const &domain, TimeDelta const &timeout) : d(new Instance(this))
{
connect(domain, timeout);
connectDomain(domain, timeout);
}

Link::Link(Address const &address) : d(new Instance(this))
{
connect(address);
connectHost(address);
}

Link::Link(Socket *openSocket) : d(new Instance(this))
Expand Down

0 comments on commit 16280db

Please sign in to comment.