Browse Source

Added Socket::SocketType; adjusted sockets as necessary

release/0.19
Jessica James 8 years ago
parent
commit
9463099cc2
  1. 4
      Jupiter/SecureSocket.cpp
  2. 17
      Jupiter/Socket.cpp
  3. 10
      Jupiter/Socket.h

4
Jupiter/SecureSocket.cpp

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2013-2015 Jessica James. * Copyright (C) 2013-2016 Jessica James.
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -79,7 +79,7 @@ Jupiter::SecureSocket::~SecureSocket()
Jupiter::SecureSocket *Jupiter::SecureSocket::accept() Jupiter::SecureSocket *Jupiter::SecureSocket::accept()
{ {
int tSock = SSL_accept(Jupiter::SecureSocket::SSLdata_->handle); SocketType tSock = SSL_accept(Jupiter::SecureSocket::SSLdata_->handle);
if (tSock > 0) if (tSock > 0)
{ {
SecureSocket *r = new SecureSocket(Jupiter::SecureSocket::getBufferSize()); SecureSocket *r = new SecureSocket(Jupiter::SecureSocket::getBufferSize());

17
Jupiter/Socket.cpp

@ -32,9 +32,8 @@ bool socketInit = false;
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
typedef int SOCKET; #define INVALID_SOCKET (Jupiter::Socket::SocketType)(~0)
#define INVALID_SOCKET (SOCKET)(~0) #define SOCKET_ERROR (-1)
#define SOCKET_ERROR (-1)
#endif // _WIN32 #endif // _WIN32
#include "Socket.h" #include "Socket.h"
@ -54,7 +53,7 @@ char *Jupiter::Socket::Buffer::get_str() const
struct Jupiter::Socket::Data struct Jupiter::Socket::Data
{ {
Jupiter::Socket::Buffer buffer; Jupiter::Socket::Buffer buffer;
SOCKET rawSock = INVALID_SOCKET; SocketType rawSock = INVALID_SOCKET;
unsigned short remote_port = 0; unsigned short remote_port = 0;
unsigned short bound_port = 0; unsigned short bound_port = 0;
Jupiter::CStringS remote_host; Jupiter::CStringS remote_host;
@ -418,7 +417,7 @@ Jupiter::Socket *Jupiter::Socket::accept()
{ {
sockaddr addr; sockaddr addr;
int size = sizeof(addr); int size = sizeof(addr);
SOCKET tSock = ::accept(Socket::data_->rawSock, &addr, &size); SocketType tSock = ::accept(Socket::data_->rawSock, &addr, &size);
if (tSock != INVALID_SOCKET) if (tSock != INVALID_SOCKET)
{ {
char resolved[NI_MAXHOST]; char resolved[NI_MAXHOST];
@ -438,7 +437,7 @@ Jupiter::Socket *Jupiter::Socket::accept()
bool Jupiter::Socket::setReadTimeout(unsigned long milliseconds) bool Jupiter::Socket::setReadTimeout(unsigned long milliseconds)
{ {
#if defined _WIN32 #if defined _WIN32
return setsockopt(Jupiter::Socket::data_->rawSock, SOL_SOCKET, SO_RCVTIMEO, (const char *)milliseconds, sizeof(milliseconds)) == 0; return setsockopt(Jupiter::Socket::data_->rawSock, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast<const char *>(&milliseconds), sizeof(milliseconds)) == 0;
#else // _WIN32 #else // _WIN32
timeval time; timeval time;
time.tv_sec = milliseconds / 1000; time.tv_sec = milliseconds / 1000;
@ -450,7 +449,7 @@ bool Jupiter::Socket::setReadTimeout(unsigned long milliseconds)
bool Jupiter::Socket::setSendTimeout(unsigned long milliseconds) bool Jupiter::Socket::setSendTimeout(unsigned long milliseconds)
{ {
#if defined _WIN32 #if defined _WIN32
return setsockopt(Jupiter::Socket::data_->rawSock, SOL_SOCKET, SO_SNDTIMEO, (const char *)milliseconds, sizeof(milliseconds)) == 0; return setsockopt(Jupiter::Socket::data_->rawSock, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast<const char *>(&milliseconds), sizeof(milliseconds)) == 0;
#else // _WIN32 #else // _WIN32
timeval time; timeval time;
time.tv_sec = milliseconds / 1000; time.tv_sec = milliseconds / 1000;
@ -681,12 +680,12 @@ bool Jupiter::Socket::cleanup() // static
return true; return true;
} }
int Jupiter::Socket::getDescriptor() const Jupiter::Socket::SocketType Jupiter::Socket::getDescriptor() const
{ {
return Jupiter::Socket::data_->rawSock; return Jupiter::Socket::data_->rawSock;
} }
void Jupiter::Socket::setDescriptor(int descriptor) void Jupiter::Socket::setDescriptor(SocketType descriptor)
{ {
Jupiter::Socket::data_->rawSock = descriptor; Jupiter::Socket::data_->rawSock = descriptor;
} }

10
Jupiter/Socket.h

@ -527,6 +527,12 @@ namespace Jupiter
/** Protected functions and members*/ /** Protected functions and members*/
protected: protected:
#if defined _WIN32
typedef uintptr_t SocketType;
#else if
typedef int SocketType;
#endif
/** /**
* @brief An extended verison of the string class, which allows for low-level length and string modification. * @brief An extended verison of the string class, which allows for low-level length and string modification.
*/ */
@ -549,14 +555,14 @@ namespace Jupiter
* *
* @return A raw socket descriptor. * @return A raw socket descriptor.
*/ */
int getDescriptor() const; SocketType getDescriptor() const;
/** /**
* @brief Used by class extensions to set the appropriate socket descriptor. * @brief Used by class extensions to set the appropriate socket descriptor.
* *
* @param descript Socket descriptor. * @param descript Socket descriptor.
*/ */
void setDescriptor(int descript); void setDescriptor(SocketType descript);
/** Private members */ /** Private members */
private: private:

Loading…
Cancel
Save