Improvements for BOA
- Allowed write buffers to become very large in asynnet. Thus in order to allow for the transfer of large images. tested ub to 2kx2k, 16MB - Handle lack of space in the write buffer more gracefully: just skip the image
This commit is contained in:
18
asynnet.c
18
asynnet.c
@ -45,7 +45,8 @@
|
|||||||
#define MAXCONNECTIONS 1024
|
#define MAXCONNECTIONS 1024
|
||||||
#define RBUFFERSIZE 262144 /* 256kb */
|
#define RBUFFERSIZE 262144 /* 256kb */
|
||||||
#define WBUFFERSIZE 20*262144
|
#define WBUFFERSIZE 20*262144
|
||||||
/* #define WBUFFERSIZE 100*262144 /*
|
/* #define WBUFFERSIZE 100*262144 */
|
||||||
|
#define MAXWBUFFERSIZE 128*1000*1024
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int socket;
|
int socket;
|
||||||
@ -204,7 +205,7 @@ int ANETregisterSocket(int socket)
|
|||||||
flags =1;
|
flags =1;
|
||||||
setsockopt(socket,IPPROTO_TCP,TCP_NODELAY,(char *) &flags, sizeof(int));
|
setsockopt(socket,IPPROTO_TCP,TCP_NODELAY,(char *) &flags, sizeof(int));
|
||||||
socke.readBuffer = MakeRWPuffer(RBUFFERSIZE);
|
socke.readBuffer = MakeRWPuffer(RBUFFERSIZE);
|
||||||
socke.writeBuffer = MakeRWPuffer(WBUFFERSIZE);
|
socke.writeBuffer = MakeBigRWPuffer(WBUFFERSIZE, MAXWBUFFERSIZE);
|
||||||
if (socke.readBuffer == NULL || socke.writeBuffer == NULL) {
|
if (socke.readBuffer == NULL || socke.writeBuffer == NULL) {
|
||||||
return ANETMEM;
|
return ANETMEM;
|
||||||
}
|
}
|
||||||
@ -498,7 +499,20 @@ int ANETinfo(int handle, char *hostname, int hostnameLen)
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int ANETcanWrite(int handle, void *buffer, int count)
|
||||||
|
{
|
||||||
|
pSocketDescriptor con = NULL;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
con = findSocketDescriptor(handle);
|
||||||
|
if (con == NULL) {
|
||||||
|
return ANETDISCONNECTED;
|
||||||
|
} else {
|
||||||
|
ANETprocess();
|
||||||
|
return CanStoreRWBuffer(con->writeBuffer, buffer, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int ANETwrite(int handle, void *buffer, int count)
|
int ANETwrite(int handle, void *buffer, int count)
|
||||||
{
|
{
|
||||||
|
@ -145,6 +145,14 @@ int ANETinfo(int handle, char *hostname, int hostNameLen);
|
|||||||
* \return 1 on success, 0 on failure
|
* \return 1 on success, 0 on failure
|
||||||
*/
|
*/
|
||||||
int ANETwrite(int handle, void *buffer, int count);
|
int ANETwrite(int handle, void *buffer, int count);
|
||||||
|
/**
|
||||||
|
* \brief Test if the buffer can be written to the network
|
||||||
|
* \param handle The handle for the connection
|
||||||
|
* \param buffer A pointer to the data to write
|
||||||
|
* \param count The number of bytes to write.
|
||||||
|
* \return 1 when possible, 0 when buffer overrun
|
||||||
|
*/
|
||||||
|
int ANETcanWrite(int handle, void *buffer, int count);
|
||||||
/**
|
/**
|
||||||
* \brief copy at max bufferLength bytes into buffer. The data is not deleted from
|
* \brief copy at max bufferLength bytes into buffer. The data is not deleted from
|
||||||
* the read buffer yet.
|
* the read buffer yet.
|
||||||
|
25
conman.c
25
conman.c
@ -1178,6 +1178,8 @@ int SCWriteZipped(SConnection * self, char *pName, void *pData,
|
|||||||
SCWrite(self, "ERROR: no data to write in SCWriteZiped", eError);
|
SCWrite(self, "ERROR: no data to write in SCWriteZiped", eError);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pBuf = malloc(iDataLen*sizeof(char));
|
pBuf = malloc(iDataLen*sizeof(char));
|
||||||
memset(pBuf,0,iDataLen*sizeof(char));
|
memset(pBuf,0,iDataLen*sizeof(char));
|
||||||
|
|
||||||
@ -1204,6 +1206,19 @@ int SCWriteZipped(SConnection * self, char *pName, void *pData,
|
|||||||
}
|
}
|
||||||
compressedLength = compStream.total_out;
|
compressedLength = compStream.total_out;
|
||||||
|
|
||||||
|
/*
|
||||||
|
If data is large, test if we can do it
|
||||||
|
*/
|
||||||
|
if(compressedLength > 2*1000*1024) {
|
||||||
|
if(!ANETcanWrite(self->sockHandle,pData,compressedLength)){
|
||||||
|
SCWrite(self,"WARNING: skipping excessive data in SCWriteZipped",eLogError);
|
||||||
|
deflateEnd(&compStream);
|
||||||
|
free(pBuf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* write header line */
|
/* write header line */
|
||||||
memset(outBuf, 0, 65536);
|
memset(outBuf, 0, 65536);
|
||||||
@ -1270,6 +1285,16 @@ int SCWriteBinary(SConnection * self, char *pName, void *pData,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
If data is large, test if we can do it
|
||||||
|
*/
|
||||||
|
if(iDataLen > 2*1000*1024) {
|
||||||
|
if(!ANETcanWrite(self->sockHandle,pData,iDataLen)){
|
||||||
|
SCWrite(self,"WARNING: skipping excessive data in SCWriteBinary",eLogError);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* write header line */
|
/* write header line */
|
||||||
memset(outBuf, 0, 65536);
|
memset(outBuf, 0, 65536);
|
||||||
|
|
||||||
|
54
rwpuffer.c
54
rwpuffer.c
@ -4,6 +4,11 @@
|
|||||||
* copyright: see file COPYRIGHT
|
* copyright: see file COPYRIGHT
|
||||||
*
|
*
|
||||||
* Mark Koennecke, January 2009
|
* Mark Koennecke, January 2009
|
||||||
|
*
|
||||||
|
* added resizing option and MakeBigRWPuffer in order to support transfer
|
||||||
|
* of large amounts of image data on few connections
|
||||||
|
*
|
||||||
|
* Mark Koennecke, August 2014
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -15,6 +20,7 @@ typedef struct __RWBuffer {
|
|||||||
int length;
|
int length;
|
||||||
int startPtr;
|
int startPtr;
|
||||||
int endPtr;
|
int endPtr;
|
||||||
|
int maxSize;
|
||||||
} RWBuffer;
|
} RWBuffer;
|
||||||
/*----------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------*/
|
||||||
prwBuffer MakeRWPuffer(int size)
|
prwBuffer MakeRWPuffer(int size)
|
||||||
@ -32,9 +38,18 @@ prwBuffer MakeRWPuffer(int size)
|
|||||||
self->length = size;
|
self->length = size;
|
||||||
self->startPtr = 0;
|
self->startPtr = 0;
|
||||||
self->endPtr = 0;
|
self->endPtr = 0;
|
||||||
|
self->maxSize = size;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
prwBuffer MakeBigRWPuffer(int size, int maxSize)
|
||||||
|
{
|
||||||
|
prwBuffer result = MakeRWPuffer(size);
|
||||||
|
if(result != NULL){
|
||||||
|
result->maxSize = maxSize;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
void KillRWBuffer(prwBuffer self)
|
void KillRWBuffer(prwBuffer self)
|
||||||
{
|
{
|
||||||
@ -46,16 +61,51 @@ void KillRWBuffer(prwBuffer self)
|
|||||||
}
|
}
|
||||||
free(self);
|
free(self);
|
||||||
}
|
}
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
int CanStoreRWBuffer(prwBuffer self, void *data, int count)
|
||||||
|
{
|
||||||
|
int length;
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
length = self->endPtr - self->startPtr;
|
||||||
|
if (count + length >= self->length ) {
|
||||||
|
if(self->length < self->maxSize){
|
||||||
|
ptr = calloc(self->maxSize,sizeof(char));
|
||||||
|
if(ptr == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
memcpy(ptr,self->data, length*sizeof(char));
|
||||||
|
free(self->data);
|
||||||
|
self->data = ptr;
|
||||||
|
self->length = self->maxSize;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
int StoreRWBuffer(prwBuffer self, void *data, int count)
|
int StoreRWBuffer(prwBuffer self, void *data, int count)
|
||||||
{
|
{
|
||||||
int length;
|
int length;
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
length = self->endPtr - self->startPtr;
|
length = self->endPtr - self->startPtr;
|
||||||
if (count + length >= self->length ) {
|
if (count + length >= self->length ) {
|
||||||
|
if(self->length < self->maxSize){
|
||||||
|
ptr = calloc(self->maxSize,sizeof(char));
|
||||||
|
if(ptr == NULL) {
|
||||||
printf("HELP: RWBuffer overrun!!!!\n");
|
printf("HELP: RWBuffer overrun!!!!\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
memcpy(ptr,self->data, length*sizeof(char));
|
||||||
|
free(self->data);
|
||||||
|
self->data = ptr;
|
||||||
|
self->length = self->maxSize;
|
||||||
|
} else {
|
||||||
|
printf("HELP: RWBuffer overrun!!!!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (count + self->endPtr > self->length) {
|
if (count + self->endPtr > self->length) {
|
||||||
memmove(self->data, self->data + self->startPtr, length);
|
memmove(self->data, self->data + self->startPtr, length);
|
||||||
|
15
rwpuffer.h
15
rwpuffer.h
@ -16,6 +16,13 @@ typedef struct __RWBuffer *prwBuffer;
|
|||||||
* \return NULL on success, else a pointer to t a new rwPuffer
|
* \return NULL on success, else a pointer to t a new rwPuffer
|
||||||
*/
|
*/
|
||||||
prwBuffer MakeRWPuffer(int size);
|
prwBuffer MakeRWPuffer(int size);
|
||||||
|
/**
|
||||||
|
* \brief create a RW buffer which can grow.
|
||||||
|
* \param size The size of the buffer.
|
||||||
|
* \param maxSize The maximum size of the buffer.
|
||||||
|
* \return NULL on success, else a pointer to t a new rwPuffer
|
||||||
|
*/
|
||||||
|
prwBuffer MakeBigRWPuffer(int size, int maxSize);
|
||||||
/**
|
/**
|
||||||
* \brief delete a rw buffer.
|
* \brief delete a rw buffer.
|
||||||
* \param self The rwPuffer to delete.
|
* \param self The rwPuffer to delete.
|
||||||
@ -29,6 +36,14 @@ void KillRWBuffer(prwBuffer self);
|
|||||||
* \return 1 on success, 0 on failure
|
* \return 1 on success, 0 on failure
|
||||||
*/
|
*/
|
||||||
int StoreRWBuffer(prwBuffer self, void *data, int count);
|
int StoreRWBuffer(prwBuffer self, void *data, int count);
|
||||||
|
/**
|
||||||
|
* \brief Test if the data can be stored in the rwBuffer
|
||||||
|
* \param self The rw buffer to store the data in
|
||||||
|
* \param data pointer to the data to store
|
||||||
|
* \param count The number of bytes to store
|
||||||
|
* \return 1 when OK, 0 when buffer full
|
||||||
|
*/
|
||||||
|
int CanStoreRWBuffer(prwBuffer self, void *data, int count);
|
||||||
/**
|
/**
|
||||||
* \brief Get a pointer to the current buffer data
|
* \brief Get a pointer to the current buffer data
|
||||||
* \param self the buffer to get the data from
|
* \param self the buffer to get the data from
|
||||||
|
Reference in New Issue
Block a user