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:
2014-08-27 16:24:39 +02:00
parent 9e898d1476
commit 8f704ebab9
5 changed files with 116 additions and 4 deletions

View File

@ -4,6 +4,11 @@
* copyright: see file COPYRIGHT
*
* 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 <string.h>
@ -15,6 +20,7 @@ typedef struct __RWBuffer {
int length;
int startPtr;
int endPtr;
int maxSize;
} RWBuffer;
/*----------------------------------------------------------------------*/
prwBuffer MakeRWPuffer(int size)
@ -32,9 +38,18 @@ prwBuffer MakeRWPuffer(int size)
self->length = size;
self->startPtr = 0;
self->endPtr = 0;
self->maxSize = size;
return self;
}
/*------------------------------------------------------------------------*/
prwBuffer MakeBigRWPuffer(int size, int maxSize)
{
prwBuffer result = MakeRWPuffer(size);
if(result != NULL){
result->maxSize = maxSize;
}
return result;
}
/*------------------------------------------------------------------------*/
void KillRWBuffer(prwBuffer self)
{
@ -46,16 +61,51 @@ void KillRWBuffer(prwBuffer 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 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) {
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) {
memmove(self->data, self->data + self->startPtr, length);