Made shared memory or shared files implementation a compile flag, fixed various compile warnings.

This commit is contained in:
Thulinma 2014-12-30 22:11:42 +01:00
parent 6d41cb96d5
commit 6a61b3be08
11 changed files with 102 additions and 139 deletions

View file

@ -13,6 +13,10 @@ endif
CPPFLAGS = -Wall -g -O2 -fPIC
override CPPFLAGS += -funsigned-char -DDEBUG="$(DEBUG)" -DPACKAGE_VERSION="\"$(PACKAGE_VERSION)\""
ifndef NOSHM
override CPPFLAGS += -DSHM_ENABLED=1
endif
LDLIBS = -lcrypto
THREADLIB = -lpthread -lrt
LDLIBS = -lcrypto $(THREADLIB)

View file

@ -22,7 +22,6 @@ static const char * DBG_LVL_LIST[] = {"NONE", "FAIL", "ERROR", "WARN", "INFO", "
#if !defined(__APPLE__) && !defined(__MACH__) && defined(__GNUC__)
#include <errno.h>
extern char * program_invocation_short_name;
#if DEBUG >= DLVL_DEVEL
#define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s|%s|%d|%s:%d|" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, getpid(), __FILE__, __LINE__, ##__VA_ARGS__);}

View file

@ -993,7 +993,7 @@ bool DTSC::File::seek_time(unsigned int ms, unsigned int trackNo, bool forceSeek
}
//check if packetID matches, if not, skip size + 8 bytes.
int packSize = ntohl(((int *)header)[1]);
int packID = ntohl(((int *)header)[2]);
unsigned int packID = ntohl(((int *)header)[2]);
if (memcmp(header, Magic_Packet2, 4) != 0 || packID != trackNo) {
if (memcmp(header, "DT", 2) != 0) {
DEBUG_MSG(DLVL_WARN, "Invalid header during seek to %u in track %d @ %lld - resetting bytePos from %lld to zero", ms, trackNo, lastreadpos, tmpPos.bytePos);

View file

@ -1042,7 +1042,7 @@ namespace DTSC {
}
if (trackRef.isMember("keysizes") && trackRef["keysizes"].isString()) {
std::string tmp = trackRef["keysizes"].asStringRef();
for (int i = 0; i < tmp.size(); i += 4){
for (unsigned int i = 0; i < tmp.size(); i += 4){
keySizes.push_back((((long unsigned)tmp[i]) << 24) | (((long unsigned)tmp[i+1]) << 16) | (((long unsigned int)tmp[i+2]) << 8) | tmp[i+3]);
}
}
@ -1127,7 +1127,7 @@ namespace DTSC {
}
if (trackRef.isMember("keysizes") && trackRef["keysizes"].isString()) {
std::string tmp = trackRef["keysizes"].asStringRef();
for (int i = 0; i < tmp.size(); i += 4){
for (unsigned int i = 0; i < tmp.size(); i += 4){
keySizes.push_back((((long unsigned)tmp[i]) << 24) | (((long unsigned)tmp[i+1]) << 16) | (((long unsigned int)tmp[i+2]) << 8) | tmp[i+3]);
}
}
@ -1175,7 +1175,7 @@ namespace DTSC {
char * tmp = 0;
unsigned int tmplen = 0;
trackRef.getMember("keysizes").getString(tmp, tmplen);
for (int i = 0; i < tmplen; i += 4){
for (unsigned int i = 0; i < tmplen; i += 4){
keySizes.push_back((((long unsigned)tmp[i]) << 24) | (((long unsigned)tmp[i+1]) << 16) | (((long unsigned int)tmp[i+2]) << 8) | tmp[i+3]);
}
}
@ -1184,8 +1184,8 @@ namespace DTSC {
///\brief Updates a track and its metadata given new packet properties.
///Will also insert keyframes on non-video tracks, and creates fragments
void Track::update(long long packTime, long long packOffset, long long packDataSize, long long packBytePos, bool isKeyframe, long long packSendSize, unsigned long segment_size) {
if (packTime < lastms) {
DEBUG_MSG(DLVL_WARN, "Received packets for track %d in wrong order (%lld < %d) - ignoring!", (int)trackID, packTime, (int)lastms);
if ((unsigned long long)packTime < lastms) {
DEBUG_MSG(DLVL_WARN, "Received packets for track %u in wrong order (%lld < %llu) - ignoring!", trackID, packTime, lastms);
return;
}
Part newPart;
@ -1218,7 +1218,7 @@ namespace DTSC {
keys.push_back(newKey);
keySizes.push_back(0);
firstms = keys[0].getTime();
if (!fragments.size() || (packTime > segment_size && packTime - segment_size >= (unsigned long long)getKey(fragments.rbegin()->getNumber()).getTime())) {
if (!fragments.size() || ((unsigned long long)packTime > segment_size && (unsigned long long)packTime - segment_size >= (unsigned long long)getKey(fragments.rbegin()->getNumber()).getTime())) {
//new fragment
Fragment newFrag;
newFrag.setDuration(0);
@ -1642,7 +1642,7 @@ namespace DTSC {
writePointer(p, convertInt(keySizes.size() * 4), 4);
std::string tmp;
tmp.reserve(keySizes.size() * 4);
for (int i = 0; i < keySizes.size(); i++){
for (unsigned int i = 0; i < keySizes.size(); i++){
tmp += ((char)keySizes[i] >> 24);
tmp += ((char)keySizes[i] >> 16);
tmp += ((char)keySizes[i] >> 8);
@ -1706,7 +1706,7 @@ namespace DTSC {
conn.SendNow(convertInt(keySizes.size() * 4), 4);
std::string tmp;
tmp.reserve(keySizes.size() * 4);
for (int i = 0; i < keySizes.size(); i++){
for (unsigned int i = 0; i < keySizes.size(); i++){
tmp += ((char)keySizes[i] >> 24);
tmp += ((char)keySizes[i] >> 16);
tmp += ((char)keySizes[i] >> 8);
@ -1774,7 +1774,7 @@ namespace DTSC {
writePointer(p, convertInt(keySizes.size() * 4), 4);
std::string tmp;
tmp.reserve(keySizes.size() * 4);
for (int i = 0; i < keySizes.size(); i++){
for (unsigned int i = 0; i < keySizes.size(); i++){
tmp += ((char)keySizes[i] >> 24);
tmp += ((char)keySizes[i] >> 16);
tmp += ((char)keySizes[i] >> 8);
@ -1844,7 +1844,7 @@ namespace DTSC {
conn.SendNow(convertInt(keySizes.size() * 4), 4);
std::string tmp;
tmp.reserve(keySizes.size() * 4);
for (int i = 0; i < keySizes.size(); i++){
for (unsigned int i = 0; i < keySizes.size(); i++){
tmp += ((char)keySizes[i] >> 24);
tmp += ((char)keySizes[i] >> 16);
tmp += ((char)keySizes[i] >> 8);
@ -2049,7 +2049,7 @@ namespace DTSC {
if (keySizes.size()){
std::string tmp;
tmp.reserve(keySizes.size() * 4);
for (int i = 0; i < keySizes.size(); i++){
for (unsigned int i = 0; i < keySizes.size(); i++){
tmp += ((char)(keySizes[i] >> 24));
tmp += ((char)(keySizes[i] >> 16));
tmp += ((char)(keySizes[i] >> 8));
@ -2099,7 +2099,7 @@ namespace DTSC {
result["keys"] = tmp;
tmp = "";
tmp.reserve(keySizes.size() * 4);
for (int i = 0; i < keySizes.size(); i++){
for (unsigned int i = 0; i < keySizes.size(); i++){
tmp += ((char)(keySizes[i] >> 24));
tmp += ((char)(keySizes[i] >> 16));
tmp += ((char)(keySizes[i] >> 8));

View file

@ -95,8 +95,6 @@ std::string & HTTP::Parser::BuildResponse(std::string code, std::string message)
/// Returns a string containing a valid HTTP 1.0 or 1.1 response, ready for sending.
/// The response is partly build from internal variables set before this call is made.
/// To be precise, protocol, headers and body are used.
/// \param code The HTTP response code. Usually you want 200.
/// \param message The HTTP response message. Usually you want "OK".
/// \return A string containing a valid HTTP 1.0 or 1.1 response, ready for sending.
/// This function calls this->BuildResponse(this->method,this->url)
std::string & HTTP::Parser::BuildResponse() {

View file

@ -105,7 +105,7 @@ namespace MP4 {
} else if (size == 0) {
fseek(newData, 0, SEEK_END);
}
DEBUG_MSG(DLVL_DEVEL, "skipping size 0x%0.8lX", size);
DEBUG_MSG(DLVL_DEVEL, "skipping size 0x%.8lX", size);
if (fseek(newData, pos + size, SEEK_SET) == 0) {
return true;
} else {

View file

@ -19,7 +19,7 @@ namespace OGG {
std::deque<unsigned int> decodeXiphSize(char * data, size_t len){
std::deque<unsigned int> res;
res.push_back(0);
for (int i = 0; i < len; i++){
for (unsigned int i = 0; i < len; i++){
*res.rbegin() += data[i];
if (data[i] != 0xFF){
res.push_back(0);
@ -98,7 +98,7 @@ namespace OGG {
unsigned int Page::calcPayloadSize(){
unsigned int retVal = 0;
for (int i = 0; i < segments.size(); i++){
for (unsigned int i = 0; i < segments.size(); i++){
retVal += segments[i].size();
}
return retVal;
@ -301,7 +301,7 @@ namespace OGG {
r << std::string(indent + 2, ' ') << "Checksum: " << getCRCChecksum() << std::endl;
r << std::string(indent + 2, ' ') << (int)getPageSegments() << " segments:" << std::endl;
r << std::string(indent + 3, ' ');
for (int i = 0; i < segments.size(); i++){
for (unsigned int i = 0; i < segments.size(); i++){
r << " " << segments[i].size();
}
r << std::endl;
@ -405,7 +405,7 @@ namespace OGG {
int Page::getPayloadSize(){
size_t res = 0;
for (int i = 0; i < segments.size(); i++){
for (unsigned int i = 0; i < segments.size(); i++){
res += segments[i].size();
}
return res;
@ -536,7 +536,7 @@ namespace OGG {
char tableSize = 0;
//char table[255];
char * table = (char *)malloc(255);
int bytesLeft = 0;
unsigned int bytesLeft = 0;
for (unsigned int i = 0; i < numSegments; i++){
//calculate amount of 255 bytes needed to store size (remainder not counted)
temp = (oggSegments[i].dataString.size() / 255);

View file

@ -184,7 +184,35 @@ namespace IPC {
}
#if !defined __APPLE__
///brief Creates a shared page
///\param name_ The name of the page to be created
///\param len_ The size to make the page
///\param master_ Whether to create or merely open the page
///\param autoBackoff When only opening the page, wait for it to appear or fail
sharedPage::sharedPage(std::string name_, unsigned int len_, bool master_, bool autoBackoff){
handle = 0;
len = 0;
master = false;
mapped = 0;
init(name_, len_, master_, autoBackoff);
}
///\brief Creates a copy of a shared page
///\param rhs The page to copy
sharedPage::sharedPage(const sharedPage & rhs) {
handle = 0;
len = 0;
master = false;
mapped = 0;
init(rhs.name, rhs.len, rhs.master);
}
///\brief Default destructor
sharedPage::~sharedPage() {
close();
}
#ifdef SHM_ENABLED
///\brief Unmaps a shared page if allowed
void sharedPage::unmap() {
if (mapped && len) {
@ -214,26 +242,6 @@ namespace IPC {
}
}
///brief Creates a shared page
///\param name_ The name of the page to be created
///\param len_ The size to make the page
///\param master_ Whether to create or merely open the page
///\param autoBackoff When only opening the page, wait for it to appear or fail
sharedPage::sharedPage(std::string name_, unsigned int len_, bool master_, bool autoBackoff) : handle(0), len(0), master(false), mapped(0) {
init(name_, len_, master_, autoBackoff);
}
///\brief Creates a copy of a shared page
///\param rhs The page to copy
sharedPage::sharedPage(const sharedPage & rhs) {
handle = 0;
len = 0;
master = false;
mapped = 0;
init(rhs.name, rhs.len, rhs.master);
}
///\brief Returns whether the shared page is valid or not
sharedPage::operator bool() const {
return mapped != 0;
@ -327,45 +335,6 @@ namespace IPC {
}
}
///\brief Default destructor
sharedPage::~sharedPage() {
close();
}
#else
///brief Creates a shared page
///\param name_ The name of the page to be created
///\param len_ The size to make the page
///\param master_ Whether to create or merely open the page
///\param autoBackoff When only opening the page, wait for it to appear or fail
sharedPage::sharedPage(std::string name_, unsigned int len_, bool master_, bool autoBackoff) {
handle = 0;
len = 0;
master = false;
mapped = 0;
init(name_, len_, master_, autoBackoff);
}
///\brief Creates a copy of a shared page
///\param rhs The page to copy
sharedPage::sharedPage(const sharedPage & rhs) {
handle = 0;
len = 0;
master = false;
mapped = 0;
init(rhs.name, rhs.len, rhs.master);
}
///\brief Default destructor
sharedPage::~sharedPage() {
unmap();
close(handle);
if (master && name != "") {
unlink(name.c_str());
}
}
#endif
///brief Creates a shared file
@ -414,20 +383,25 @@ namespace IPC {
}
}
/// Unmaps, closes and unlinks (if master and name is set) the shared file.
void sharedFile::close() {
unmap();
if (handle > 0) {
::close(handle);
if (master && name != "") {
unlink(name.c_str());
}
handle = 0;
}
}
///\brief Initialize a page, de-initialize before if needed
///\param name_ The name of the page to be created
///\param len_ The size to make the page
///\param master_ Whether to create or merely open the page
///\param autoBackoff When only opening the page, wait for it to appear or fail
void sharedFile::init(std::string name_, unsigned int len_, bool master_, bool autoBackoff) {
unmap();
if (master) {
unlink(name.c_str());
}
if (handle > 0) {
close(handle);
}
handle = 0;
close();
name = name_;
len = len_;
master = master_;
@ -475,13 +449,7 @@ namespace IPC {
///\brief Default destructor
sharedFile::~sharedFile() {
unmap();
if (master) {
unlink(name.c_str());
}
if (handle > 0) {
close(handle);
}
close();
}

View file

@ -83,7 +83,33 @@ namespace IPC {
semaphore * mySemaphore;
};
#if !defined __APPLE__
///\brief A class for managing shared files.
class sharedFile {
public:
sharedFile(std::string name_ = "", unsigned int len_ = 0, bool master_ = false, bool autoBackoff = true);
sharedFile(const sharedFile & rhs);
~sharedFile();
operator bool() const;
void init(std::string name_, unsigned int len_, bool master_ = false, bool autoBackoff = true);
void operator =(sharedFile & rhs);
bool operator < (const sharedFile & rhs) const {
return name < rhs.name;
}
void close();
void unmap();
///\brief The fd handle of the opened shared file
int handle;
///\brief The name of the opened shared file
std::string name;
///\brief The size in bytes of the opened shared file
long long int len;
///\brief Whether this class should unlink the shared file upon deletion or not
bool master;
///\brief A pointer to the payload of the file file
char * mapped;
};
#ifdef SHM_ENABLED
///\brief A class for managing shared memory pages.
class sharedPage {
public:
@ -98,13 +124,13 @@ namespace IPC {
}
void unmap();
void close();
#ifdef __CYGWIN__
#ifdef __CYGWIN__
///\brief The handle of the opened shared memory page
HANDLE handle;
#else
#else
///\brief The fd handle of the opened shared memory page
int handle;
#endif
#endif
///\brief The name of the opened shared memory page
std::string name;
///\brief The size in bytes of the opened shared memory page
@ -115,41 +141,7 @@ namespace IPC {
char * mapped;
};
#else
class sharedPage;
#endif
#if !defined __APPLE__
///\brief A class for managing shared files in the same form as shared memory pages
#else
///\brief A class for managing shared files.
#endif
class sharedFile {
public:
sharedFile(std::string name_ = "", unsigned int len_ = 0, bool master_ = false, bool autoBackoff = true);
sharedFile(const sharedFile & rhs);
~sharedFile();
operator bool() const;
void init(std::string name_, unsigned int len_, bool master_ = false, bool autoBackoff = true);
void operator =(sharedFile & rhs);
bool operator < (const sharedFile & rhs) const {
return name < rhs.name;
}
void unmap();
///\brief The fd handle of the opened shared file
int handle;
///\brief The name of the opened shared file
std::string name;
///\brief The size in bytes of the opened shared file
long long int len;
///\brief Whether this class should unlink the shared file upon deletion or not
bool master;
///\brief A pointer to the payload of the file file
char * mapped;
};
#ifdef __APPLE__
///\brief A class for handling shared memory pages.
///
///Uses shared files at its backbone, defined for portability
class sharedPage: public sharedFile {
public:

View file

@ -526,6 +526,7 @@ unsigned int Socket::Connection::iwrite(const void * buffer, int len) {
/// returning the amount of bytes it actually read.
/// \param buffer Location of the buffer to read to.
/// \param len Amount of bytes to read.
/// \param flags Flags to use in the recv call. Ignored on fake sockets.
/// \returns The amount of bytes actually read.
int Socket::Connection::iread(void * buffer, int len, int flags) {
if (!connected() || len < 1) {
@ -570,6 +571,7 @@ int Socket::Connection::iread(void * buffer, int len, int flags) {
/// Data is read using iread (which is nonblocking if the Socket::Connection itself is),
/// then appended to end of buffer.
/// \param buffer Socket::Buffer to append data to.
/// \param flags Flags to use in the recv call. Ignored on fake sockets.
/// \return True if new data arrived, false otherwise.
bool Socket::Connection::iread(Buffer & buffer, int flags) {
char cbuffer[BUFFER_BLOCKSIZE];

View file

@ -62,7 +62,7 @@ namespace theora {
return false;
}
if (! newData[0] & 0x80){
DEBUG_MSG(DLVL_FAIL, "newdata != 0x80: %0.2X", newData[0]);
DEBUG_MSG(DLVL_FAIL, "newdata != 0x80: %.2X", newData[0]);
return false;
}
if (memcmp(newData + 1, "theora", 6) != 0){