Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix to build with current GCC 11.2.0 on MSYS2 #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ check the `manual`_ for a full description of the protocol

.. _manual: https://github.com/graphstream/gs-netstream/wiki/NetStream-Manual

Building for C++
----------------

For C++, you can build gs-netstream using the code in the `c++` directory. Just run 'make'.

This has been tested to build with gcc 11.2.0 on MSYS2 (as of Nov 2021) and with gcc 9.3 on Ubuntu 20.04. Only building was tested.
6 changes: 6 additions & 0 deletions c++/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
netstream-main
*.exe
*.dll
*.so
*.o
*.a
3 changes: 2 additions & 1 deletion c++/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ CDBG = -g $(CWARN) -fno-inline
CFLAGS = -I$(INCDIR) -O3
DFLAGS = -I$(INCDIR) -g $(CWARN) -fno-inline -DDEBUG=1

ifeq ($(shell uname),MINGW32_NT-6.1)
# https://stackoverflow.com/questions/714100/os-detecting-makefile
ifeq ($(OS),Windows_NT)
SOCKET_LIB = -lwsock32
else
SOCKET_LIB =
Expand Down
20 changes: 20 additions & 0 deletions c++/src/netstream-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,19 @@ namespace netstream{
* An array of bytes. Followed by first, a 16-bits integer for the number
* of integers and then, a list of signed bytes.
*/

const unsigned char TYPE_BYTE_ARRAY=0x53;
/**
* Followed by an 16-bit signed integer (a short)
*/
const unsigned char TYPE_SHORT=0x54;

/**
* An array of shorts. Followed by first, a 16-bits integer for the number
* of integers and then, a list of 16-bit signed shorts
*/
const unsigned char TYPE_SHORT_ARRAY=0x55;

/**
* Followed by an 32-bit signed integer
*/
Expand All @@ -173,6 +176,7 @@ namespace netstream{
* of integers and then, a list of 32-bit signed integers
*/
const unsigned char TYPE_INT_ARRAY=0x57;

/**
* Followed by an 64-bit signed integer
*/
Expand All @@ -182,6 +186,9 @@ namespace netstream{
* longs and then, a list of 62-bit signed integers
*/
const unsigned char TYPE_LONG_ARRAY=0x59;

/** NOTE: see also LONGLONG below, out of order */

/**
* Followed by a single precision 32-bits floating point number
*/
Expand Down Expand Up @@ -219,6 +226,19 @@ namespace netstream{
*/
const unsigned char TYPE_ARRAY=0x60;

/**
* Followed by an 64-bit signed integer
*/
const unsigned char TYPE_LONGLONG=0x61;
/**
* An array of longs. Followed by first, a 16-bits integer for the number of
* longs and then, a list of 62-bit signed integers
*/
const unsigned char TYPE_LONGLONG_ARRAY=0x62;




}// end netstream namespace

#endif
95 changes: 77 additions & 18 deletions c++/src/netstream-sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ void NetStreamSender::init()
std::cout<<"."<<std::flush;
wait_for_server++;
#ifdef WIN32
Sleep(ms);
Sleep(1); //milliseconds
#else
usleep(1000);
usleep(1000);//microseconds
#endif
}
}
Expand All @@ -74,21 +74,40 @@ int NetStreamSender::_getType(char object){
}

int NetStreamSender::_getType(bool object){
if(debug){
cerr<<" NetStreamSender: _getType : bool"<<endl;
}
return TYPE_BOOLEAN;
}

int NetStreamSender::_getType(short object){
if(debug){
cerr<<" NetStreamSender: _getType : bool"<<endl;
cerr<<" NetStreamSender: _getType : short"<<endl;
}
return TYPE_BOOLEAN;}
return TYPE_SHORT;}

int NetStreamSender::_getType(int object){
if(debug){
cerr<<" NetStreamSender: _getType : int"<<endl;
if(debug){
cerr<<" NetStreamSender: _getType : int"<<endl;
}
return TYPE_INT;
}
return TYPE_INT;}

int NetStreamSender::_getType(long object){
if(debug){
cerr<<" NetStreamSender: _getType : long"<<endl;
if(debug){
cerr<<" NetStreamSender: _getType : long"<<endl;
}
return TYPE_INT;
}


int NetStreamSender::_getType(long long object){
if(debug){
cerr<<" NetStreamSender: _getType : long long" <<endl;
}
return TYPE_LONG;
}
return TYPE_LONG;}

int NetStreamSender::_getType(float object){
if(debug){
cerr<<" NetStreamSender: _getType : float"<<endl;
Expand All @@ -115,16 +134,35 @@ if(debug){
cerr<<" NetStreamSender: _getType : bool*"<<endl;
}
return TYPE_BOOLEAN_ARRAY;}

int NetStreamSender::_getType(const vector<short> & object){
if(debug){
cerr<<" NetStreamSender: _getType : short*"<<endl;
}
return TYPE_SHORT_ARRAY;
}

int NetStreamSender::_getType(const vector<int> & object){
if(debug){
cerr<<" NetStreamSender: _getType : int*"<<endl;
if(debug){
cerr<<" NetStreamSender: _getType : int*"<<endl;
}
return TYPE_INT_ARRAY;
}
return TYPE_INT_ARRAY;}

int NetStreamSender::_getType(const vector<long> & object){
if(debug){
cerr<<" NetStreamSender: _getType : long*"<<endl;
if(debug){
cerr<<" NetStreamSender: _getType : long*" <<endl;
}
return TYPE_LONG_ARRAY;
}

int NetStreamSender::_getType(const vector<long long> & object){
if(debug){
cerr<<" NetStreamSender: _getType : long long*" <<endl;
}
return TYPE_LONGLONG_ARRAY;
}
return TYPE_LONG_ARRAY;}

int NetStreamSender::_getType(const vector<float> & object){
if(debug){
cerr<<" NetStreamSender: _getType : float*"<<endl;
Expand All @@ -146,12 +184,20 @@ void NetStreamSender::_encode(NetStreamStorage & event, char value){
void NetStreamSender::_encode(NetStreamStorage & event, bool value){
event.writeByte(value?1:0);
}
void NetStreamSender::_encode(NetStreamStorage & event, short value){
event.writeVarint(value);
}
void NetStreamSender::_encode(NetStreamStorage & event, int value){
event.writeVarint(value);
}
void NetStreamSender::_encode(NetStreamStorage & event, long value){
event.writeVarint(value);
}

void NetStreamSender::_encode(NetStreamStorage & event, long long value){
event.writeVarint(value);
}

void NetStreamSender::_encode(NetStreamStorage & event, float value){
event.writeFloat(value);
}
Expand All @@ -173,18 +219,31 @@ void NetStreamSender::_encode(NetStreamStorage & event, const vector<bool> & val
event.writeByte((*i));
}
}
void NetStreamSender::_encode(NetStreamStorage & event, const vector<short> & value){
event.writeUnsignedVarint(value.size());
for(vector<short>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeVarint((*i));
}
}
void NetStreamSender::_encode(NetStreamStorage & event, const vector<int> & value){
event.writeUnsignedVarint(value.size());
for(vector<int>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeVarint((*i));
}
}
}
void NetStreamSender::_encode(NetStreamStorage & event, const vector<long> & value){
event.writeUnsignedVarint(value.size());
for(vector<long>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeVarint((*i));
}
}
void NetStreamSender::_encode(NetStreamStorage & event, const vector<long long> & value){
event.writeUnsignedVarint(value.size());
for(vector<long long>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeVarint((*i));
}
}

void NetStreamSender::_encode(NetStreamStorage & event, const vector<float> & value){
event.writeUnsignedVarint(value.size());
for(vector<float>::const_iterator i = value.begin(); i != value.end(); i++){
Expand Down Expand Up @@ -304,4 +363,4 @@ void NetStreamSender::removeEdgeAttribute(const string & source_id, long time_id
event.writeString(attribute);
_sendEvent(event);
}
}
}
38 changes: 32 additions & 6 deletions c++/src/netstream-sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,35 @@
#define NETSTREAM_SENDER_H




#ifndef WIN32
#include <unistd.h>
#else
#include <windows.h>
#endif

#include <sys/cdefs.h>
#define STATIC_ASSERT(condition) typedef char __static_assert##__LINE__[(condition)?1:-1]

#include <iostream>

#ifdef _WIN32
STATIC_ASSERT(sizeof(short)==sizeof(int16_t));
STATIC_ASSERT(sizeof(int)==sizeof(int32_t));
STATIC_ASSERT(sizeof(long)==sizeof(int32_t));
STATIC_ASSERT(sizeof(long long)==sizeof(int64_t));
STATIC_ASSERT(sizeof(void*)==sizeof(int64_t));
#define GS_LONG long long
#else
STATIC_ASSERT(sizeof(short)==sizeof(int16_t));
STATIC_ASSERT(sizeof(int)==sizeof(int32_t));
STATIC_ASSERT(sizeof(long)==sizeof(int64_t));
STATIC_ASSERT(sizeof(long long)==sizeof(int64_t));
STATIC_ASSERT(sizeof(void*)==sizeof(int64_t));
#define GS_LONG long
#endif

#define GS_STRINGIFY(VAR) #VAR

#include "netstream-storage.h"
#include "netstream-socket.h"
#include "netstream-constants.h"
Expand Down Expand Up @@ -59,15 +77,19 @@ class NetStreamSender{

int _getType(char object);
int _getType(bool object);
int _getType(short object);
int _getType(int object);
int _getType(long object);
int _getType(long long object);
int _getType(float object);
int _getType(double object);
int _getType(const string & object);
int _getType( const vector<char> & object);
int _getType( const vector<bool> & object);
int _getType( const vector<short> & object);
int _getType( const vector<int> & object);
int _getType( const vector<long> & object);
int _getType( const vector<long long> & object);
int _getType( const vector<float> & object);
int _getType( const vector<double> & object);

Expand All @@ -81,18 +103,22 @@ class NetStreamSender{
}
void _encode(NetStreamStorage & event, char value);
void _encode(NetStreamStorage & event, bool value);
void _encode(NetStreamStorage & event, short value);
void _encode(NetStreamStorage & event, int value);
void _encode(NetStreamStorage & event, long value);
void _encode(NetStreamStorage & event, long long value);
void _encode(NetStreamStorage & event, float value);
void _encode(NetStreamStorage & event, double value);
void _encode(NetStreamStorage & event, const string & value);

void _encode(NetStreamStorage & event, const vector<char> & value);
void _encode(NetStreamStorage & event, const vector<bool> & value);
void _encode(NetStreamStorage & event, const vector<short> & value);
void _encode(NetStreamStorage & event, const vector<int> & value);
void _encode(NetStreamStorage & event, const vector <long> & value);
void _encode(NetStreamStorage & event, const vector <float> & value);
void _encode(NetStreamStorage & event, const vector <double> & value);
void _encode(NetStreamStorage & event, const vector<long> & value);
void _encode(NetStreamStorage & event, const vector<long long> & value);
void _encode(NetStreamStorage & event, const vector<float> & value);
void _encode(NetStreamStorage & event, const vector<double> & value);


void _sendEvent(NetStreamStorage &);
Expand Down Expand Up @@ -211,4 +237,4 @@ class NetStreamSender{
};

}
#endif
#endif
Loading