summaryrefslogtreecommitdiff
path: root/server.cpp
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2014-01-21 00:41:55 +0100
committerTreeki <treeki@gmail.com>2014-01-21 00:41:55 +0100
commit8b32f42df825a03284f5c340499394b93dc1a65d (patch)
tree88481b62ea3d9609d352857127d13ce3624fd9a2 /server.cpp
parent84e469bef68f67cd56c4a643dcfc9d050c5cd398 (diff)
downloadbounce4-8b32f42df825a03284f5c340499394b93dc1a65d.tar.gz
bounce4-8b32f42df825a03284f5c340499394b93dc1a65d.zip
refactoring: add basic implementation of the IRCServer class
Diffstat (limited to '')
-rw-r--r--server.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/server.cpp b/server.cpp
index 5739159..e892aa9 100644
--- a/server.cpp
+++ b/server.cpp
@@ -3,7 +3,6 @@
Server::Server(NetCore *_netCore) : SocketRWCommon(_netCore) {
dnsQueryId = -1;
- ircUseTls = false;
}
Server::~Server() {
if (dnsQueryId != -1)
@@ -46,10 +45,13 @@ void Server::processReadBuffer() {
-void Server::beginConnect() {
+void Server::connect(const char *hostname, int _port, bool _useTls) {
if (state == CS_DISCONNECTED) {
+ port = _port;
+ useTls = _useTls;
+
DNS::closeQuery(dnsQueryId); // just in case
- dnsQueryId = DNS::makeQuery(ircHostname);
+ dnsQueryId = DNS::makeQuery(hostname);
if (dnsQueryId == -1) {
// TODO: better error reporting
@@ -91,10 +93,10 @@ void Server::tryConnectPhase() {
// We have our non-blocking socket, let's try connecting!
sockaddr_in outAddr;
outAddr.sin_family = AF_INET;
- outAddr.sin_port = htons(ircPort);
+ outAddr.sin_port = htons(port);
outAddr.sin_addr.s_addr = result.s_addr;
- if (connect(sock, (sockaddr *)&outAddr, sizeof(outAddr)) == -1) {
+ if (::connect(sock, (sockaddr *)&outAddr, sizeof(outAddr)) == -1) {
if (errno == EINPROGRESS) {
state = CS_WAITING_CONNECT;
} else {
@@ -117,7 +119,7 @@ void Server::connectionSuccessful() {
outputBuf.clear();
// Do we need to do any TLS junk?
- if (ircUseTls) {
+ if (useTls) {
int initRet = gnutls_init(&tls, GNUTLS_CLIENT);
if (initRet != GNUTLS_E_SUCCESS) {
printf("[Server::connectionSuccessful] gnutls_init borked\n");
@@ -147,3 +149,5 @@ void Server::close() {
dnsQueryId = -1;
}
}
+
+