aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorMartin Peach <mrpeach@users.sourceforge.net>2013-05-19 06:13:51 +0000
committerMartin Peach <mrpeach@users.sourceforge.net>2013-05-19 06:13:51 +0000
commit79e1b8050cd2bc4199d90dbf86c9bdc5fc87cf09 (patch)
tree4914f45d2a6d9f001c5c2b9cd685fc44da0ba0b7 /net
parent812922a639c8540d5ef78d9fcdbabd23d09d9025 (diff)
Check for space before accepting incoming connection, increased MAX_CONNECT.
Also changed print format for size_t from %d to %lu And commented out some unused variables. svn path=/trunk/externals/mrpeach/; revision=17142
Diffstat (limited to 'net')
-rw-r--r--net/tcpserver.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/net/tcpserver.c b/net/tcpserver.c
index 72f9b95..379a7ec 100644
--- a/net/tcpserver.c
+++ b/net/tcpserver.c
@@ -63,7 +63,7 @@
#define snprintf sprintf_s
#endif
-#define MAX_CONNECT 32 /* maximum number of connections */
+#define MAX_CONNECT 1024 /* maximum number of connections to reserve space for */
#define INBUFSIZE 65536L /* was 4096: size of receiving data buffer */
#define MAX_UDP_RECEIVE 65536L /* longer than data in maximum UDP packet */
@@ -195,7 +195,7 @@ static t_tcpserver_socketreceiver *tcpserver_socketreceiver_new(void *owner, t_t
t_tcpserver_socketreceiver *x = (t_tcpserver_socketreceiver *)getbytes(sizeof(*x));
if (!x)
{
- error("%s_socketreceiver: unable to allocate %d bytes", objName, sizeof(*x));
+ error("%s_socketreceiver: unable to allocate %lu bytes", objName, sizeof(*x));
}
else
{
@@ -388,7 +388,7 @@ static void tcpserver_send_bytes(int client, t_tcpserver *x, int argc, t_atom *a
ttsp = (t_tcpserver_send_params *)getbytes(sizeof(t_tcpserver_send_params));
if (ttsp == NULL)
{
- error("%s: unable to allocate %d bytes for t_tcpserver_send_params", objName, sizeof(t_tcpserver_send_params));
+ error("%s: unable to allocate %lu bytes for t_tcpserver_send_params", objName, sizeof(t_tcpserver_send_params));
goto failed;
}
ttsp->client = client;
@@ -442,7 +442,7 @@ static void tcpserver_send_bytes(int client, t_tcpserver *x, int argc, t_atom *a
ttsp = (t_tcpserver_send_params *)getbytes(sizeof(t_tcpserver_send_params));
if (ttsp == NULL)
{
- error("%s: unable to allocate %d bytes for t_tcpserver_send_params", objName, sizeof(t_tcpserver_send_params));
+ error("%s: unable to allocate %lu bytes for t_tcpserver_send_params", objName, sizeof(t_tcpserver_send_params));
goto failed;
}
ttsp->client = client;
@@ -484,7 +484,7 @@ static void tcpserver_send_bytes(int client, t_tcpserver *x, int argc, t_atom *a
ttsp = (t_tcpserver_send_params *)getbytes(sizeof(t_tcpserver_send_params));
if (ttsp == NULL)
{
- error("%s: unable to allocate %d bytes for t_tcpserver_send_params", objName, sizeof(t_tcpserver_send_params));
+ error("%s: unable to allocate %lu bytes for t_tcpserver_send_params", objName, sizeof(t_tcpserver_send_params));
goto failed;
}
ttsp->client = client;
@@ -754,7 +754,7 @@ static void tcpserver_buf_size(t_tcpserver *x, t_symbol *s, int argc, t_atom *ar
{
int client = -1;
float buf_size = 0;
- t_atom output_atom[3];
+// t_atom output_atom[3];
if(x->x_nconnections <= 0)
{
@@ -809,11 +809,11 @@ static void *tcpserver_broadcast_thread(void *arg)
int sockfd = 0;
char fpath[FILENAME_MAX];
FILE *fptr;
- t_atom output_atom[3];
- t_tcpserver_send_params *ttsp;
- pthread_t sender_thread;
- pthread_attr_t sender_attr;
- int sender_thread_result;
+// t_atom output_atom[3];
+// t_tcpserver_send_params *ttsp;
+// pthread_t sender_thread;
+// pthread_attr_t sender_attr;
+// int sender_thread_result;
int result;
for (i = j = 0; i < ttbp->argc; ++i)
@@ -1003,7 +1003,7 @@ static void tcpserver_broadcast(t_tcpserver *x, t_symbol *s, int argc, t_atom *a
ttbp = (t_tcpserver_broadcast_params *)getbytes(sizeof(t_tcpserver_broadcast_params));
if (ttbp == NULL)
{
- error("%s_broadcast: unable to allocate %d bytes for t_tcpserver_broadcast_params", objName, sizeof(t_tcpserver_broadcast_params));
+ error("%s_broadcast: unable to allocate %lu bytes for t_tcpserver_broadcast_params", objName, sizeof(t_tcpserver_broadcast_params));
}
else
{
@@ -1060,11 +1060,17 @@ static void tcpserver_connectpoll(t_tcpserver *x)
{
struct sockaddr_in incomer_address;
unsigned int sockaddrl = sizeof( struct sockaddr );
- int fd = accept(x->x_connectsocket, (struct sockaddr*)&incomer_address, &sockaddrl);
+ int fd;
int i;
int optVal;
unsigned int optLen = sizeof(int);
+ if (MAX_CONNECT <= x->x_nconnections)
+ { /* no more free space for t_tcpserver_socketreceiver pointers, maybe increase MAX_CONNECT? */
+ post("%s: too many connections (MAX_CONNECT is %d)", objName, x->x_nconnections);
+ return;
+ }
+ fd = accept(x->x_connectsocket, (struct sockaddr*)&incomer_address, &sockaddrl);
if (fd < 0) post("%s: accept failed", objName);
else
{