mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-29 08:37:36 -04:00
merged with latest master before creating PR
This commit is contained in:
commit
9193d3579b
294 changed files with 13080 additions and 8470 deletions
|
@ -1,27 +0,0 @@
|
|||
|
||||
RS_TOP_DIR = ..
|
||||
##### Define any flags that are needed for this section #######
|
||||
###############################################################
|
||||
|
||||
###############################################################
|
||||
include $(RS_TOP_DIR)/scripts/config.mk
|
||||
###############################################################
|
||||
|
||||
RSOBJ = rsthreads.o rsprint.o rsnet.o rsdebug.o rsdir.o rsversion.o
|
||||
|
||||
TESTOBJ = dirtest.o dir2test.o
|
||||
|
||||
TESTS = dirtest dir2test
|
||||
|
||||
all: librs tests
|
||||
|
||||
dirtest: $(OBJ) dirtest.o
|
||||
$(CC) $(CFLAGS) -o dirtest dirtest.o $(OBJ) $(LIBS)
|
||||
|
||||
dir2test: $(OBJ) dir2test.o
|
||||
$(CC) $(CFLAGS) -o dir2test dir2test.o $(OBJ) $(LIBS)
|
||||
|
||||
###############################################################
|
||||
include $(RS_TOP_DIR)/scripts/rules.mk
|
||||
###############################################################
|
||||
|
|
@ -141,9 +141,15 @@ namespace
|
|||
inline OptionHolder(char s,
|
||||
const char* l,
|
||||
const char* desc);
|
||||
#ifdef __APPLE__
|
||||
friend OptionHolder help(char s,
|
||||
const char* l,
|
||||
const char* desc);
|
||||
#else
|
||||
friend OptionHolder help(char s='h',
|
||||
const char* l="help",
|
||||
const char* desc="Display this help");
|
||||
#endif
|
||||
private:
|
||||
std::string shortName_;
|
||||
std::string longName_;
|
||||
|
|
|
@ -62,25 +62,33 @@ void *solveDNSEntries(void *p)
|
|||
|
||||
if(!next_call.empty())
|
||||
{
|
||||
hostent *pHost = gethostbyname(next_call.c_str());
|
||||
in_addr in ;
|
||||
|
||||
bool succeed = rsGetHostByName(next_call.c_str(),in);
|
||||
|
||||
{
|
||||
RsStackMutex mut(dnsr->_rdnsMtx) ;
|
||||
|
||||
{
|
||||
RsStackMutex mut(dnsr->_rdnsMtx) ;
|
||||
DNSResolver::AddrInfo &info = (*dnsr->_addr_map)[next_call];
|
||||
|
||||
DNSResolver::AddrInfo &info = (*dnsr->_addr_map)[next_call];
|
||||
|
||||
if(pHost)
|
||||
if(succeed)
|
||||
{
|
||||
info.state = DNSResolver::DNS_HAVE ;
|
||||
// IPv4 for the moment.
|
||||
struct sockaddr_in *addrv4p = (struct sockaddr_in *) &(info.addr);
|
||||
addrv4p->sin_family = AF_INET;
|
||||
addrv4p->sin_addr= in ;
|
||||
addrv4p->sin_port = htons(0);
|
||||
|
||||
std::cerr << "LOOKUP succeeded: " << next_call.c_str() << " => " << rs_inet_ntoa(addrv4p->sin_addr) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
info.state = DNSResolver::DNS_HAVE ;
|
||||
// IPv4 for the moment.
|
||||
struct sockaddr_in *addrv4p = (struct sockaddr_in *) &(info.addr);
|
||||
addrv4p->sin_family = AF_INET;
|
||||
addrv4p->sin_addr.s_addr = *(unsigned long*) (pHost->h_addr);
|
||||
addrv4p->sin_port = htons(0);
|
||||
}
|
||||
else
|
||||
info.state = DNSResolver::DNS_LOOKUP_ERROR ;
|
||||
}
|
||||
|
||||
std::cerr << "DNSResolver: lookup error for address \"" << next_call.c_str() << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,15 +101,18 @@ void *solveDNSEntries(void *p)
|
|||
|
||||
void DNSResolver::start_request()
|
||||
{
|
||||
{
|
||||
RsStackMutex mut(_rdnsMtx) ;
|
||||
*_thread_running = true ;
|
||||
}
|
||||
{
|
||||
RsStackMutex mut(_rdnsMtx) ;
|
||||
*_thread_running = true ;
|
||||
}
|
||||
|
||||
void *data = (void *)this;
|
||||
pthread_t tid ;
|
||||
pthread_create(&tid, 0, &solveDNSEntries, data);
|
||||
pthread_detach(tid); /* so memory is reclaimed in linux */
|
||||
void *data = (void *)this;
|
||||
pthread_t tid ;
|
||||
|
||||
if(! pthread_create(&tid, 0, &solveDNSEntries, data))
|
||||
pthread_detach(tid); /* so memory is reclaimed in linux */
|
||||
else
|
||||
std::cerr << "(EE) Could not start DNS resolver thread!" << std::endl;
|
||||
}
|
||||
|
||||
void DNSResolver::reset()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "util/rsstring.h"
|
||||
#include "util/rsmemory.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#include <netdb.h>
|
||||
|
@ -58,7 +59,6 @@ static void getPage(const std::string& server_name,std::string& page)
|
|||
int sockfd,n=0; // socket descriptor
|
||||
struct sockaddr_in serveur; // server's parameters
|
||||
memset(&serveur.sin_zero, 0, sizeof(serveur.sin_zero));
|
||||
struct hostent *hostinfo=NULL; // structure for storing the server's ip
|
||||
|
||||
char buf[1024];
|
||||
char request[1024];
|
||||
|
@ -78,20 +78,21 @@ static void getPage(const std::string& server_name,std::string& page)
|
|||
|
||||
// get server's ipv4 adress
|
||||
|
||||
hostinfo = gethostbyname(server_name.c_str());
|
||||
|
||||
if (hostinfo == NULL) /* l'hôte n'existe pas */
|
||||
in_addr in ;
|
||||
|
||||
if(!rsGetHostByName(server_name.c_str(),in)) /* l'hôte n'existe pas */
|
||||
{
|
||||
std::cerr << "ExtAddrFinder: Unknown host " << server_name << std::endl;
|
||||
unix_close(sockfd);
|
||||
return ;
|
||||
}
|
||||
serveur.sin_addr = *(struct in_addr*) hostinfo->h_addr;
|
||||
serveur.sin_addr = in ;
|
||||
serveur.sin_port = htons(80);
|
||||
|
||||
#ifdef EXTADDRSEARCH_DEBUG
|
||||
printf("Connection attempt\n");
|
||||
#endif
|
||||
std::cerr << "ExtAddrFinder: resolved hostname " << server_name << " to " << rs_inet_ntoa(in) << std::endl;
|
||||
|
||||
if(unix_connect(sockfd,(struct sockaddr *)&serveur, sizeof(serveur)) == -1)
|
||||
{
|
||||
|
@ -104,12 +105,18 @@ static void getPage(const std::string& server_name,std::string& page)
|
|||
#endif
|
||||
|
||||
// envoi
|
||||
sprintf( request,
|
||||
if(snprintf( request,
|
||||
1024,
|
||||
"GET / HTTP/1.0\r\n"
|
||||
"Host: %s:%d\r\n"
|
||||
"Connection: Close\r\n"
|
||||
"\r\n",
|
||||
server_name.c_str(), 80);
|
||||
server_name.c_str(), 80) > 1020)
|
||||
{
|
||||
std::cerr << "ExtAddrFinder: buffer overrun. The server name \"" << server_name << "\" is too long. This is quite unexpected." << std::endl;
|
||||
unix_close(sockfd);
|
||||
return ;
|
||||
}
|
||||
|
||||
if(send(sockfd,request,strlen(request),0)== -1)
|
||||
{
|
||||
|
@ -202,8 +209,11 @@ void ExtAddrFinder::start_request()
|
|||
{
|
||||
void *data = (void *)this;
|
||||
pthread_t tid ;
|
||||
pthread_create(&tid, 0, &doExtAddrSearch, data);
|
||||
pthread_detach(tid); /* so memory is reclaimed in linux */
|
||||
|
||||
if(! pthread_create(&tid, 0, &doExtAddrSearch, data))
|
||||
pthread_detach(tid); /* so memory is reclaimed in linux */
|
||||
else
|
||||
std::cerr << "(EE) Could not start ExtAddrFinder thread." << std::endl;
|
||||
}
|
||||
|
||||
bool ExtAddrFinder::hasValidIP(struct sockaddr_storage &addr)
|
||||
|
|
|
@ -598,7 +598,7 @@ bool RetroDb::tableExists(const std::string &tableName)
|
|||
/********************** RetroCursor ************************/
|
||||
|
||||
RetroCursor::RetroCursor(sqlite3_stmt *stmt)
|
||||
: mStmt(NULL), mCount(0), mPosCounter(0) {
|
||||
: mStmt(NULL) {
|
||||
|
||||
open(stmt);
|
||||
}
|
||||
|
@ -635,7 +635,6 @@ bool RetroCursor::moveToFirst(){
|
|||
rc = sqlite3_step(mStmt);
|
||||
|
||||
if(rc == SQLITE_ROW){
|
||||
mPosCounter = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -673,17 +672,10 @@ bool RetroCursor::moveToLast(){
|
|||
return false;
|
||||
|
||||
}else{
|
||||
mPosCounter = mCount;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
int RetroCursor::getResultCount() const {
|
||||
|
||||
if(isOpen())
|
||||
return mCount;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
int RetroCursor::columnCount() const {
|
||||
|
||||
if(isOpen())
|
||||
|
@ -704,8 +696,6 @@ bool RetroCursor::close(){
|
|||
|
||||
int rc = sqlite3_finalize(mStmt);
|
||||
mStmt = NULL;
|
||||
mPosCounter = 0;
|
||||
mCount = 0;
|
||||
|
||||
return (rc == SQLITE_OK);
|
||||
}
|
||||
|
@ -725,12 +715,6 @@ bool RetroCursor::open(sqlite3_stmt *stm){
|
|||
int rc = sqlite3_reset(mStmt);
|
||||
|
||||
if(rc == SQLITE_OK){
|
||||
|
||||
while((rc = sqlite3_step(mStmt)) == SQLITE_ROW)
|
||||
mCount++;
|
||||
|
||||
sqlite3_reset(mStmt);
|
||||
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
|
@ -753,7 +737,6 @@ bool RetroCursor::moveToNext(){
|
|||
int rc = sqlite3_step(mStmt);
|
||||
|
||||
if(rc == SQLITE_ROW){
|
||||
mPosCounter++;
|
||||
return true;
|
||||
|
||||
}else if(rc == SQLITE_DONE){ // no more results
|
||||
|
@ -772,16 +755,6 @@ bool RetroCursor::moveToNext(){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t RetroCursor::getPosition() const {
|
||||
|
||||
if(isOpen())
|
||||
return mPosCounter;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int32_t RetroCursor::getInt32(int columnIndex){
|
||||
return sqlite3_column_int(mStmt, columnIndex);
|
||||
}
|
||||
|
|
|
@ -239,12 +239,6 @@ public:
|
|||
*/
|
||||
bool moveToLast();
|
||||
|
||||
/*!
|
||||
* gets current position of cursor
|
||||
* @return current position of cursor
|
||||
*/
|
||||
int32_t getPosition() const;
|
||||
|
||||
/* data retrieval */
|
||||
|
||||
/*!
|
||||
|
@ -260,11 +254,10 @@ public:
|
|||
|
||||
/*!
|
||||
*
|
||||
* @return -1 if cursor is in error, otherwise number of rows in result
|
||||
* @return -1 if cursor is in error, otherwise number of columns in result
|
||||
*/
|
||||
int32_t getResultCount() const;
|
||||
|
||||
int32_t columnCount() const ;
|
||||
|
||||
/*!
|
||||
* Current statement is closed and discarded (finalised)
|
||||
* before actual opening occurs
|
||||
|
@ -274,8 +267,6 @@ public:
|
|||
bool open(sqlite3_stmt* stm);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/*!
|
||||
* Returns the value of the requested column as a String.
|
||||
* @param columnIndex the zero-based index of the target column.
|
||||
|
@ -326,17 +317,8 @@ public:
|
|||
getString(columnIndex, temp);
|
||||
str = T(temp);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
sqlite3_stmt* mStmt;
|
||||
int mCount; /// number of results
|
||||
int mPosCounter;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // RSSQLITE_H
|
||||
|
|
|
@ -61,7 +61,10 @@ bool RsAES::aes_crypt_8_16(const uint8_t *input_data,uint32_t input_data_length,
|
|||
int f_len = 0;
|
||||
|
||||
if(output_data_length < (uint32_t)c_len)
|
||||
return false ;
|
||||
{
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
/* update ciphertext, c_len is filled with the length of ciphertext generated,
|
||||
*len is the size of plaintext in bytes */
|
||||
|
@ -69,6 +72,7 @@ bool RsAES::aes_crypt_8_16(const uint8_t *input_data,uint32_t input_data_length,
|
|||
if(!EVP_EncryptUpdate(&e_ctx, output_data, &c_len, input_data, input_data_length))
|
||||
{
|
||||
std::cerr << "RsAES: decryption failed at end. Check padding." << std::endl;
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
@ -76,6 +80,7 @@ bool RsAES::aes_crypt_8_16(const uint8_t *input_data,uint32_t input_data_length,
|
|||
if(!EVP_EncryptFinal_ex(&e_ctx, output_data+c_len, &f_len))
|
||||
{
|
||||
std::cerr << "RsAES: decryption failed at end. Check padding." << std::endl;
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
@ -112,7 +117,10 @@ bool RsAES::aes_decrypt_8_16(const uint8_t *input_data,uint32_t input_data_lengt
|
|||
int f_len = 0;
|
||||
|
||||
if(output_data_length < (uint32_t)c_len)
|
||||
{
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
output_data_length = c_len ;
|
||||
|
||||
|
@ -122,6 +130,7 @@ bool RsAES::aes_decrypt_8_16(const uint8_t *input_data,uint32_t input_data_lengt
|
|||
if(! EVP_DecryptUpdate(&e_ctx, output_data, &c_len, input_data, input_data_length))
|
||||
{
|
||||
std::cerr << "RsAES: decryption failed." << std::endl;
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
@ -129,6 +138,7 @@ bool RsAES::aes_decrypt_8_16(const uint8_t *input_data,uint32_t input_data_lengt
|
|||
if(!EVP_DecryptFinal_ex(&e_ctx, output_data+c_len, &f_len))
|
||||
{
|
||||
std::cerr << "RsAES: decryption failed at end. Check padding." << std::endl;
|
||||
EVP_CIPHER_CTX_cleanup(&e_ctx) ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
// Includes for directory creation.
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util/rsdir.h"
|
||||
|
|
|
@ -21,29 +21,37 @@
|
|||
//
|
||||
class RsTemporaryMemory
|
||||
{
|
||||
public:
|
||||
RsTemporaryMemory(size_t s)
|
||||
{
|
||||
_mem = (unsigned char *)malloc(s) ;
|
||||
}
|
||||
public:
|
||||
RsTemporaryMemory(size_t s)
|
||||
{
|
||||
_mem = (unsigned char *)malloc(s) ;
|
||||
|
||||
operator unsigned char *() { return _mem ; }
|
||||
if(_mem)
|
||||
_size = s ;
|
||||
else
|
||||
_size = 0 ;
|
||||
}
|
||||
|
||||
~RsTemporaryMemory()
|
||||
{
|
||||
if(_mem != NULL)
|
||||
{
|
||||
free(_mem) ;
|
||||
_mem = NULL ;
|
||||
}
|
||||
}
|
||||
operator unsigned char *() { return _mem ; }
|
||||
|
||||
size_t size() const { return _size ; }
|
||||
|
||||
private:
|
||||
unsigned char *_mem ;
|
||||
~RsTemporaryMemory()
|
||||
{
|
||||
if(_mem != NULL)
|
||||
{
|
||||
free(_mem) ;
|
||||
_mem = NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
// make it noncopyable
|
||||
RsTemporaryMemory& operator=(const RsTemporaryMemory&) { return *this ;}
|
||||
RsTemporaryMemory(const RsTemporaryMemory&) {}
|
||||
private:
|
||||
unsigned char *_mem ;
|
||||
size_t _size ;
|
||||
|
||||
// make it noncopyable
|
||||
RsTemporaryMemory& operator=(const RsTemporaryMemory&) { return *this ;}
|
||||
RsTemporaryMemory(const RsTemporaryMemory&) {}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "util/rsnet.h"
|
||||
#include "util/rsthreads.h"
|
||||
#include "util/rsstring.h"
|
||||
#include "util/rsmemory.h"
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
#else
|
||||
|
@ -72,6 +73,40 @@ void sockaddr_clear(struct sockaddr_in *addr)
|
|||
addr->sin_family = AF_INET;
|
||||
}
|
||||
|
||||
bool rsGetHostByName(const std::string& hostname, in_addr& returned_addr)
|
||||
{
|
||||
#if defined(WINDOWS_SYS) || defined(__APPLE__) || defined(__HAIKU__)
|
||||
hostent *result = gethostbyname(hostname.c_str()) ;
|
||||
#else
|
||||
RsTemporaryMemory mem(8192) ;
|
||||
|
||||
if(!mem)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": Cannot allocate memory!" << std::endl;
|
||||
return false; // Do something.
|
||||
}
|
||||
|
||||
int error = 0;
|
||||
struct hostent pHost;
|
||||
struct hostent *result;
|
||||
|
||||
if(gethostbyname_r(hostname.c_str(), &pHost, (char*)(unsigned char*)mem, mem.size(), &result, &error) != 0)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": cannot call gethostname_r. Internal error reported. Check buffer size." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
#endif
|
||||
if(!result)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": gethostname returned null result." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
// Use contents of result.
|
||||
|
||||
returned_addr.s_addr = *(unsigned long*) (result->h_addr);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool isValidNet(const struct in_addr *addr)
|
||||
{
|
||||
|
|
|
@ -70,6 +70,9 @@ bool isLoopbackNet(const struct in_addr *addr);
|
|||
bool isPrivateNet(const struct in_addr *addr);
|
||||
bool isExternalNet(const struct in_addr *addr);
|
||||
|
||||
// uses a re-entrant version of gethostbyname
|
||||
bool rsGetHostByName(const std::string& hostname, in_addr& returned_addr) ;
|
||||
|
||||
std::ostream& operator<<(std::ostream& o,const struct sockaddr_in&) ;
|
||||
|
||||
/* thread-safe version of inet_ntoa */
|
||||
|
@ -104,8 +107,6 @@ bool operator<(const struct sockaddr_storage &a, const struct sockaddr_storage &
|
|||
bool sockaddr_storage_same(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
bool sockaddr_storage_samefamily(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
bool sockaddr_storage_sameip(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
bool sockaddr_storage_samenet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
bool sockaddr_storage_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
|
||||
// string,
|
||||
std::string sockaddr_storage_tostring(const struct sockaddr_storage &addr);
|
||||
|
|
|
@ -56,14 +56,10 @@ bool sockaddr_storage_ipv6_setport(struct sockaddr_storage &addr, uint16_t port)
|
|||
bool sockaddr_storage_ipv4_lessthan(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
bool sockaddr_storage_ipv4_same(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
bool sockaddr_storage_ipv4_sameip(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
bool sockaddr_storage_ipv4_samenet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
bool sockaddr_storage_ipv4_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
|
||||
bool sockaddr_storage_ipv6_lessthan(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
bool sockaddr_storage_ipv6_same(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
bool sockaddr_storage_ipv6_sameip(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
bool sockaddr_storage_ipv6_samenet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
bool sockaddr_storage_ipv6_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2);
|
||||
|
||||
|
||||
/********************************* Output ***********************************/
|
||||
|
@ -373,62 +369,6 @@ bool sockaddr_storage_sameip(const struct sockaddr_storage &addr, const struct s
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool sockaddr_storage_samenet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_samenet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (!sockaddr_storage_samefamily(addr, addr2))
|
||||
return false;
|
||||
|
||||
switch(addr.ss_family)
|
||||
{
|
||||
case AF_INET:
|
||||
return sockaddr_storage_ipv4_samenet(addr, addr2);
|
||||
break;
|
||||
case AF_INET6:
|
||||
return sockaddr_storage_ipv6_samenet(addr, addr2);
|
||||
break;
|
||||
default:
|
||||
std::cerr << "sockaddr_storage_samenet() INVALID Family - error";
|
||||
std::cerr << std::endl;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sockaddr_storage_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_samesubnet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (!sockaddr_storage_samefamily(addr, addr2))
|
||||
return false;
|
||||
|
||||
switch(addr.ss_family)
|
||||
{
|
||||
case AF_INET:
|
||||
return sockaddr_storage_ipv4_samesubnet(addr, addr2);
|
||||
break;
|
||||
case AF_INET6:
|
||||
return sockaddr_storage_ipv6_samesubnet(addr, addr2);
|
||||
break;
|
||||
default:
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_samesubnet() INVALID Family - error";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/********************************* Output ***********************************/
|
||||
|
||||
std::string sockaddr_storage_tostring(const struct sockaddr_storage &addr)
|
||||
|
@ -813,38 +753,6 @@ bool sockaddr_storage_ipv4_sameip(const struct sockaddr_storage &addr, const str
|
|||
return (ptr1->sin_addr.s_addr == ptr2->sin_addr.s_addr);
|
||||
}
|
||||
|
||||
|
||||
bool sockaddr_storage_ipv4_samenet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
(void) addr;
|
||||
(void) addr2;
|
||||
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_samenet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
|
||||
const struct sockaddr_in *ptr2 = to_const_ipv4_ptr(addr2);
|
||||
return sameNet(&(ptr1->sin_addr),&(ptr2->sin_addr));
|
||||
}
|
||||
|
||||
bool sockaddr_storage_ipv4_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
(void) addr;
|
||||
(void) addr2;
|
||||
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv4_samesubnet() using pqinetwork::isSameSubnet()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
const struct sockaddr_in *ptr1 = to_const_ipv4_ptr(addr);
|
||||
const struct sockaddr_in *ptr2 = to_const_ipv4_ptr(addr2);
|
||||
return isSameSubnet((struct in_addr *) &(ptr1->sin_addr),(struct in_addr *) &(ptr2->sin_addr));
|
||||
}
|
||||
|
||||
// IPV6
|
||||
bool sockaddr_storage_ipv6_lessthan(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
|
@ -906,34 +814,6 @@ bool sockaddr_storage_ipv6_sameip(const struct sockaddr_storage &addr, const str
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool sockaddr_storage_ipv6_samenet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
(void) addr;
|
||||
(void) addr2;
|
||||
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv6_samenet() TODO";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sockaddr_storage_ipv6_samesubnet(const struct sockaddr_storage &addr, const struct sockaddr_storage &addr2)
|
||||
{
|
||||
(void) addr;
|
||||
(void) addr2;
|
||||
|
||||
#ifdef SS_DEBUG
|
||||
std::cerr << "sockaddr_storage_ipv6_samesubnet() TODO";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/********************************* Output ***********************************/
|
||||
std::string sockaddr_storage_ipv4_iptostring(const struct sockaddr_storage &addr)
|
||||
{
|
||||
|
|
|
@ -158,6 +158,15 @@ void FixedAllocator::deallocate(void *p)
|
|||
_chunks.pop_back();
|
||||
}
|
||||
}
|
||||
uint32_t FixedAllocator::currentSize() const
|
||||
{
|
||||
uint32_t res = 0 ;
|
||||
|
||||
for(uint32_t i=0;i<_chunks.size();++i)
|
||||
res += (_numBlocks - _chunks[i]->_blocksAvailable) * _blockSize ;
|
||||
|
||||
return res ;
|
||||
}
|
||||
void FixedAllocator::printStatistics() const
|
||||
{
|
||||
std::cerr << " numBLocks=" << (int)_numBlocks << std::endl;
|
||||
|
@ -181,10 +190,17 @@ SmallObjectAllocator::~SmallObjectAllocator()
|
|||
{
|
||||
RsStackMutex m(SmallObject::_mtx) ;
|
||||
|
||||
for(std::map<int,FixedAllocator*>::const_iterator it(_pool.begin());it!=_pool.end();++it)
|
||||
delete it->second ;
|
||||
|
||||
//std::cerr << __PRETTY_FUNCTION__ << " not deleting. Leaving it to the system." << std::endl;
|
||||
|
||||
_active = false ;
|
||||
|
||||
uint32_t still_allocated = 0 ;
|
||||
|
||||
for(std::map<int,FixedAllocator*>::const_iterator it(_pool.begin());it!=_pool.end();++it)
|
||||
still_allocated += it->second->currentSize() ;
|
||||
//delete it->second ;
|
||||
|
||||
std::cerr << "Memory still in use at end of program: " << still_allocated << " bytes." << std::endl;
|
||||
}
|
||||
|
||||
void *SmallObjectAllocator::allocate(size_t bytes)
|
||||
|
|
|
@ -68,8 +68,9 @@ namespace RsMemoryManagement
|
|||
return p >= c._data && (static_cast<unsigned char *>(p)-c._data)/_blockSize < _numBlocks ;
|
||||
}
|
||||
|
||||
void printStatistics() const ;
|
||||
private:
|
||||
void printStatistics() const ;
|
||||
uint32_t currentSize() const;
|
||||
private:
|
||||
size_t _blockSize ;
|
||||
unsigned char _numBlocks ;
|
||||
std::vector<Chunk*> _chunks ;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue