Skip to content

Commit

Permalink
TCP with MD magic and hopefully fast flush
Browse files Browse the repository at this point in the history
  • Loading branch information
scexao6 committed Dec 10, 2024
1 parent 6da3eb6 commit 4cb58ef
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions src/COREMOD_memory/stream_TCP.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ static int TCPTRANSFERKW = 1;

typedef struct
{
long magic;
long cnt0;
long cnt1;
} TCP_BUFFER_METADATA;

long FRAME_MD_MAGIC = 0x12341234ff; // Doesn't matter.

// ==========================================
// Forward declaration(s)
// ==========================================
Expand Down Expand Up @@ -265,8 +268,8 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit(
int slice, oldslice;
int NBslices;

TCP_BUFFER_METADATA *frame_md;
long framesize1; // pixel data + metadata
TCP_BUFFER_METADATA frame_md = {0};
long framesize1; // pixel data + metadata
long framesizeall; // total frame size : pixel data + metadata + kw
char *buff; // transmit buffer

Expand Down Expand Up @@ -406,8 +409,6 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit(
if(loopOK == 1)
{
ptr0 = (char *) img_p->array.raw;

frame_md = (TCP_BUFFER_METADATA *) malloc(sizeof(TCP_BUFFER_METADATA));
framesize1 = framesize + sizeof(TCP_BUFFER_METADATA);

if(TCPTRANSFERKW == 0)
Expand Down Expand Up @@ -504,8 +505,9 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit(

if(semr == 0)
{
frame_md->cnt0 = img_p->md->cnt0;
frame_md->cnt1 = img_p->md->cnt1;
frame_md.magic = FRAME_MD_MAGIC;
frame_md.cnt0 = img_p->md->cnt0;
frame_md.cnt1 = img_p->md->cnt1;

slice = img_p->md->cnt1;
if(slice > oldslice + 1)
Expand All @@ -522,14 +524,15 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit(
slice = 0;
}

frame_md->cnt1 = slice;
frame_md.cnt1 = slice;

ptr1 =
ptr0 +
framesize *
slice; //img_p->md->cnt1; // frame that was just written
memcpy(buff, ptr1, framesize);
memcpy(buff + framesize, frame_md, sizeof(TCP_BUFFER_METADATA));
*(TCP_BUFFER_METADATA *)(buff + framesize) = frame_md;
//memcpy(buff + framesize, &frame_md, sizeof());

if(TCPTRANSFERKW == 1)
{
Expand Down Expand Up @@ -582,8 +585,6 @@ imageID COREMOD_MEMORY_image_NETWORKtransmit(
printf("port %d closed\n", port);
fflush(stdout);

free(frame_md);

return ID;
}

Expand Down Expand Up @@ -623,10 +624,10 @@ imageID COREMOD_MEMORY_image_NETWORKreceive(int port,

imgmd = (IMAGE_METADATA *) malloc(sizeof(IMAGE_METADATA));

TCP_BUFFER_METADATA *frame_md;
TCP_BUFFER_METADATA *frame_md_p;
long framesize1; // pixel data + metadata
long framesizefull; // pixel data + metadata + kw
char *buff; // buffer
char *buff; // buffer

//size_t flushsize;
char *socket_flush_buff;
Expand Down Expand Up @@ -952,7 +953,7 @@ imageID COREMOD_MEMORY_image_NETWORKreceive(int port,

buff = (char *) malloc(sizeof(char) * framesizefull);

frame_md = (TCP_BUFFER_METADATA *)(buff + framesize);
frame_md_p = (TCP_BUFFER_METADATA *)(buff + framesize);

if(data.processinfo == 1)
{
Expand Down Expand Up @@ -1036,15 +1037,21 @@ imageID COREMOD_MEMORY_image_NETWORKreceive(int port,

if(socketOpen == 1)
{
frame_md = (TCP_BUFFER_METADATA *)(buff + framesize);
frame_md_p = (TCP_BUFFER_METADATA *)(buff + framesize);
if(frame_md_p->magic != FRAME_MD_MAGIC)
{
printf("Bad magic! Looping fast.\n");
continue;
}

img_p->md->write = 1;
img_p->md->cnt1 = frame_md->cnt1;
img_p->md->cnt1 = frame_md_p->cnt1;


// copy pixel data
if(NBslices > 1)
{
memcpy(ptr0 + framesize * frame_md->cnt1, buff, framesize);
memcpy(ptr0 + framesize * frame_md_p->cnt1, buff, framesize);
}
else
{
Expand All @@ -1059,29 +1066,29 @@ imageID COREMOD_MEMORY_image_NETWORKreceive(int port,
img_p->md->NBkw * sizeof(IMAGE_KEYWORD));
}

frameincr = (long) frame_md->cnt0 - cnt0previous;
frameincr = (long) frame_md_p->cnt0 - cnt0previous;
if(frameincr > 1)
{
printf("Skipped %ld frame(s) at index %ld %ld\n",
frameincr - 1,
(long)(frame_md->cnt0),
(long)(frame_md->cnt1));
(long)(frame_md_p->cnt0),
(long)(frame_md_p->cnt1));
}

cnt0previous = frame_md->cnt0;
cnt0previous = frame_md_p->cnt0;

if(monitorindex == monitorinterval)
{
printf(
"[%5ld] input %20ld (+ %8ld) output %20ld (+ "
"%8ld)\n",
monitorloopindex,
frame_md->cnt0,
frame_md->cnt0 - minputcnt,
frame_md_p->cnt0,
frame_md_p->cnt0 - minputcnt,
img_p->md->cnt0,
img_p->md->cnt0 - moutputcnt);

minputcnt = frame_md->cnt0;
minputcnt = frame_md_p->cnt0;
moutputcnt = img_p->md->cnt0;

monitorloopindex++;
Expand Down

0 comments on commit 4cb58ef

Please sign in to comment.