char fbuf[512];
int fbuf_cnt;
int http_head_read(unsigned char *buf, int len, int ff) {
int flg_head = 0;
int n, ret = 0;
fbuf_cnt = 0;
if ((n = read(ff, buf, len)) <= 0) return 0;
if(n > 11 && *((u32 *)buf) == 0x50545448) { // "HTTP" // HTTP/1.0 200 OK
int x;
for(x = 3; x < n && buf[x] != ' '; x++);
while(x < n && buf[x] == ' ') x++;
if(x < n) ret = atoi(&buf[x]);
int cnt = 0;
x = 0;
while(ret) {
int z = 0;
while (x < n) {
if (cnt++ > 16384) return 600; // Header Too Large
if (buf[x++] == ((flg_head & 1) ? 0x0a : 0x0d)) {
if ((flg_head & 3) == 1) {
#if DEBUG_MAIN_LEVEL > 0
buf[x-1] = 0;
DBG_8195A("%s\n", &buf[z]);
#endif
z = x;
}
if (flg_head >= 3) {
if (n - x > 0) {
fbuf_cnt = n - x;
rtl_memcpy(&fbuf, &buf[x], fbuf_cnt);
}
#if DEBUG_MAIN_LEVEL > 2
DBG_8195A("TST: Skip HTTP head in %d bytes\n\n", cnt);
#endif
return ret;
}
flg_head++;
}
else flg_head = 0;
}
x = 0;
while(z < n) buf[x++] = buf[z++];
if ((n = read(ff, &buf[x], len - x)) <= 0) return 601; // content ??
n += x;
};
}
fbuf_cnt = n;
// rtl_memcpy(&fbuf, &buf[x], fbuf_cnt); // RamFifoWrite(&buf[x], n - x);
// else RamFifoWrite(buf, n);
return ret;
}
void test_socked(void)
{
struct sockaddr_in remote_ip;
int sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock == -1) {
DBG_8195A("TST: Not open socket!\n");
vTaskDelete(NULL);
return;
}
rtl_memset(&remote_ip, 0, sizeof(remote_ip));
remote_ip.sin_family = AF_INET;
remote_ip.sin_addr.s_addr = нужный IP;
remote_ip.sin_port = htons(нужный порт);
DiagPrintf("\nSocked connect at start %d ms.\n", xTaskGetTickCount());
if (connect(sock, (struct sockaddr * )(&remote_ip), sizeof(struct sockaddr)) != 00) {
close(sock);
DBG_8195A("TST: Connect error!\n");
vTaskDelete(NULL);
return;
}
sprintf(&fbuf,"GET / HTTP/1.1/\r\nTime at start %d ms.\r\n\r\n", xTaskGetTickCount());
int x = strlen(&fbuf);
write(sock, &fbuf, x);
if ((x = http_head_read(fbuf, sizeof(fbuf), sock)) != 200) {
DBG_8195A("TST: HTTP error %d\n", x);
}
close(sock);
DiagPrintf("\nSocked close at start %d ms.\n", xTaskGetTickCount());
vTaskDelete(NULL);
}
void connect_start(void)
{
if (pdTRUE != xTaskCreate( test_socked, (const signed char * const)"socked", SOCKET_STACK_SIZE, NULL, SOCKET_PRIORITY, NULL))
}