Browse Source

Renamed Socket::acceptConnection() to Socket::accept().

Socket::accept() now assigns an incoming connection's IP address to hostname, as well as its port to port.
Explicitly labeled some functions in SecureSocket as "override".
release/0.19
JustinAJ 10 years ago
parent
commit
4e318425f1
  1. 2
      Jupiter/SecureSocket.cpp
  2. 14
      Jupiter/SecureSocket.h
  3. 17
      Jupiter/Socket.cpp
  4. 2
      Jupiter/Socket.h
  5. BIN
      Release/Jupiter.lib

2
Jupiter/SecureSocket.cpp

@ -67,7 +67,7 @@ Jupiter::SecureSocket::~SecureSocket()
if (Jupiter::SecureSocket::SSLdata_ != nullptr) delete Jupiter::SecureSocket::SSLdata_;
}
Jupiter::SecureSocket *Jupiter::SecureSocket::acceptConnection()
Jupiter::SecureSocket *Jupiter::SecureSocket::accept()
{
int tSock = SSL_accept(Jupiter::SecureSocket::SSLdata_->handle);
if (tSock > 0)

14
Jupiter/SecureSocket.h

@ -96,7 +96,7 @@ namespace Jupiter
* @param Address for client to bind to.
* @return True on success, false otherwise.
*/
virtual bool connectToHost(const char *hostname, unsigned short iPort, const char *clientAddress = nullptr, unsigned short clientPort = 0);
virtual bool connectToHost(const char *hostname, unsigned short iPort, const char *clientAddress = nullptr, unsigned short clientPort = 0) override;
/**
* @brief Interface to provide simple binding to ports.
@ -106,19 +106,19 @@ namespace Jupiter
* @param andListen True if listen() should be called, false otherwise.
* @return True on success, false otherwise.
*/
virtual bool bindToPort(const char *hostname, unsigned short iPort, bool andListen = true);
virtual bool bindToPort(const char *hostname, unsigned short iPort, bool andListen = true) override;
/**
* @brief Accepts an incoming connection for the port bound to.
*
* @return A valid SecureSocket on success, nullptr otherwise.
*/
virtual SecureSocket *acceptConnection();
virtual SecureSocket *accept() override;
/**
* @brief Closes the socket.
*/
virtual void closeSocket();
virtual void closeSocket() override;
/**
* @brief Writes new data from the socket to the buffer, without removing it from the socket queue.
@ -127,7 +127,7 @@ namespace Jupiter
* @return Number of bytes received on success, less than or equal to 0 otherwise.
* Note: Refer to SSL_read() for detailed return values.
*/
virtual int peek();
virtual int peek() override;
/**
* @brief Writes new data from the socket to the buffer.
@ -136,7 +136,7 @@ namespace Jupiter
* @return Number of bytes received on success, less than or equal to 0 otherwise.
* Note: Refer to SSL_read() for detailed return values.
*/
virtual int recv();
virtual int recv() override;
/**
* @brief Sends data across the socket.
@ -146,7 +146,7 @@ namespace Jupiter
* @return Number of bytes sent on success, less than or equal to 0 otherwise.
* Note: Refer to SSL_write() for detailed return values.
*/
virtual int send(const char *data, size_t datalen);
virtual int send(const char *data, size_t datalen) override;
/**
* @brief Initializes SSL on the socket.

17
Jupiter/Socket.cpp

@ -352,15 +352,28 @@ Jupiter::StringS Jupiter::Socket::ntop(void *ip, size_t size)
}
}
Jupiter::Socket *Jupiter::Socket::acceptConnection()
Jupiter::Socket *Jupiter::Socket::accept()
{
SOCKET tSock = accept(Socket::data_->rawSock, 0, 0);
sockaddr addr;
int size = sizeof(addr);
SOCKET tSock = ::accept(Socket::data_->rawSock, &addr, &size);
if (tSock != INVALID_SOCKET)
{
char resolved[NI_MAXHOST];
getnameinfo(&addr, size, resolved, NI_MAXHOST, 0, 0, NI_NUMERICHOST);
Socket *r = new Socket(Jupiter::Socket::data_->bufflen);
r->data_->rawSock = tSock;
r->data_->sockType = Jupiter::Socket::data_->sockType;
r->data_->sockProto = Jupiter::Socket::data_->sockProto;
r->data_->host.set(resolved);
char *end = resolved + r->data_->host.size();
while (end != resolved)
{
if (*--end == ':')
break;
r->data_->port *= 10;
r->data_->port += static_cast<unsigned char>(Jupiter_getBase(*end, 10));
}
return r;
}
return nullptr;

2
Jupiter/Socket.h

@ -243,7 +243,7 @@ namespace Jupiter
*
* @return A valid Socket on success, nullptr otherwise.
*/
virtual Socket *acceptConnection();
virtual Socket *accept();
/**
* @brief Sets the timeout for recv() in milliseconds.

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save