Skip to content

Instantly share code, notes, and snippets.

@lgliducik
Created February 1, 2012 16:19
Show Gist options
  • Save lgliducik/1717808 to your computer and use it in GitHub Desktop.
Save lgliducik/1717808 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <ti/ndk/inc/netmain.h>
/* BIOS6 include */
#include <ti/sysbios/BIOS.h>
/* Platform utilities include */
#include "ti/platform/platform.h"
#include <stdlib.h>
uint32_t addr = 0x0;
uint32_t size;
//функция для работы с портом 7 по умолчанию,
//принимает начальный адрес(куда записывать данные из файла) и размер файла
int dtask_tcp( SOCKET s, UINT32 unused )
{
struct timeval to;
int I;
char* buf;
(void)unused;
HANDLE hBuffer;
// Configure our socket timeout to be 5 seconds
to.tv_sec = 5;
to.tv_usec = 0;
setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof(to) );
setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof(to) );
I = 1;
setsockopt( s, IPPROTO_TCP, TCP_NOPUSH, &I, 4 );
for(;;)
{
//recv address
I = (int)recvnc(s, (void **)&buf, 0, &hBuffer );
//I = recv( s, &buf, sizeof(uint32_t), MSG_WAITALL);
addr = strtol(buf,NULL,16);
if(addr == 0x10800000)
{
//send echo
// response 1, if data is transfered
char one = 0x1;
if(I > 0)
{
if(send( s, &one, 1, 0) < 0 )
break;
recvncfree( hBuffer );
}
else
break;
}
//recv size
I = (int)recvnc(s, (void **)&buf, 0, &hBuffer );
//I = recv( s, &buf, sizeof(uint32_t), MSG_WAITALL);
size = strtol(buf,NULL,10);
if(size == 60)
{
//send echo
// response 1, if data is transfered
char one = 0x1;
if(I > 0)
{
if(send( s, &one, 1, 0) < 0 )
break;
recvncfree( hBuffer );
}
else
break;
}
}
fdClose( s );
// Return "0" since we closed the socket
return(0);
}
//забирает данные из файла из порта 2010 по умолчанию,
int dtask_tcp_Data( SOCKET s, UINT32 unused )
{
struct timeval to;
int I;
char *pBuf = (char*)addr;
(void)unused;
HANDLE hBuffer;
// Configure our socket timeout to be 5 seconds
to.tv_sec = 5;
to.tv_usec = 0;
setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof(to) );
setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof(to) );
I = 1;
setsockopt( s, IPPROTO_TCP, TCP_NOPUSH, &I, 4 );
for(;;)
{
I = recv( s, pBuf, size, 0);
//I = (int)recvnc( s, (void **)&pBuf, 0, &hBuffer );
// response 1, if data is transfered
char one = 0x1;
if(I > 0)
{
if(send( s, &one, 1, 0) < 0 )
break;
recvncfree( hBuffer );
}
else
break;
}
fdClose( s );
// Return "0" since we closed the socket
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment