Skip to content

Commit a11b063

Browse files
committed
Send/Receive buffer sizes adjustable in cmake + added warnings on overflow
1 parent a891944 commit a11b063

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

server/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ if (ISAAC_GST)
7878
add_definitions(-DISAAC_GST)
7979
endif (ISAAC_GST)
8080

81+
82+
83+
set(ISAAC_MAX_RECEIVE "8388608" CACHE STRING "The size of the reserved buffers for sending and receiving, default of 8 MB should work for up to 4K" )
84+
set(ISAAC_DEFINITIONS ${ISAAC_DEFINITIONS} -DISAAC_MAX_RECEIVE=${ISAAC_MAX_RECEIVE})
85+
add_definitions(${ISAAC_DEFINITIONS})
86+
8187
option(ISAAC_JPEG "Use JPEG compression between visualization and isaac server. Deactivating will not work with big images. And with big I am talking about bigger than 800x600." ON)
8288
if (ISAAC_JPEG)
8389
find_package(JPEG REQUIRED)

server/src/Common.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ typedef int ClientRef;
2525
typedef int ObserverRef;
2626
typedef int errorCode;
2727

28-
#define ISAAC_MAX_RECEIVE 4194304 //4 MB
29-
3028
typedef enum
3129
{
3230
FORCE_EXIT = -1,

server/src/InsituConnectorMaster.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ errorCode InsituConnectorMaster::run()
124124
{
125125
int add = recv(fd_array[i].fd,&(con_array[i]->connector->jlcb.buffer[con_array[i]->connector->jlcb.count]),4096,MSG_DONTWAIT);
126126
if (add > 0)
127+
{
127128
con_array[i]->connector->jlcb.count += add;
129+
if(con_array[i]->connector->jlcb.count > ISAAC_MAX_RECEIVE)
130+
{
131+
fprintf(stderr,"Fatal error: Socket received %d bytes but buffer is only %d bytes! To increase the allowed size set ISAAC_MAX_RECEIVE to a higher value.\n",
132+
con_array[i]->connector->jlcb.count, ISAAC_MAX_RECEIVE);
133+
return -1;
134+
}
135+
}
128136
else
129137
break;
130138
}

server/src/WebSocketDataConnector.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <sys/stat.h>
2424
#include <fcntl.h>
2525
#include <assert.h>
26+
#include <vector>
2627

2728
#include <syslog.h>
2829
#include <sys/time.h>
@@ -97,7 +98,7 @@ static int callback_isaac(
9798
size_t len )
9899
{
99100
int n, m;
100-
101+
101102
struct per_session_data__isaac *pss = (struct per_session_data__isaac *)user;
102103
Broker** broker_ptr = (Broker**)lws_context_user(lws_get_context(wsi));
103104
Broker* broker = NULL;
@@ -115,10 +116,6 @@ static int callback_isaac(
115116
case LWS_CALLBACK_SERVER_WRITEABLE:
116117
if (pss->client)
117118
{
118-
char* buf = new char[LWS_SEND_BUFFER_PRE_PADDING + ISAAC_MAX_RECEIVE +
119-
LWS_SEND_BUFFER_POST_PADDING];
120-
121-
char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
122119
MessageContainer* message = NULL;
123120
int l = 0;
124121
do
@@ -130,6 +127,7 @@ static int callback_isaac(
130127
{
131128
printf("WebSocketDataConnector: Dropped one dropable package!\n");
132129
delete message;
130+
message = NULL;
133131
l--;
134132
}
135133
if (message) //New message from master sama!
@@ -138,6 +136,17 @@ static int callback_isaac(
138136
char* buffer = json_dumps( message->json_root, 0 );
139137
pthread_mutex_unlock(&MessageContainer::deep_copy_mutex);
140138
n = strlen(buffer);
139+
140+
std::vector<char> buf(LWS_SEND_BUFFER_PRE_PADDING + n + LWS_SEND_BUFFER_POST_PADDING + 1);
141+
if(buf.size() > ISAAC_MAX_RECEIVE)
142+
{
143+
printf("The maximum set size of %d bytes per lws packet was exceeded! To increase the allowed package size set ISAAC_MAX_RECEIVE to a higher value. \n",
144+
ISAAC_MAX_RECEIVE);
145+
fflush(stdout);
146+
}
147+
148+
char *p = buf.data() + LWS_SEND_BUFFER_PRE_PADDING;
149+
141150
sprintf(p,"%s",buffer);
142151
m = lws_write(wsi, (unsigned char*)p, n, LWS_WRITE_TEXT);
143152
free(buffer);
@@ -148,10 +157,10 @@ static int callback_isaac(
148157
return -1;
149158
}
150159
delete message;
160+
message = NULL;
151161
}
152162
}
153163
while (l > 1 && !lws_send_pipe_choked(wsi));
154-
delete[] buf;
155164
}
156165
break;
157166
//case LWS_CALLBACK_CLOSED:

0 commit comments

Comments
 (0)