Repository navigation
Expand file tree
/
Copy pathsocket_feed.c
More file actions
113 lines (94 loc) · 2.81 KB
/
Copy pathsocket_feed.c
File metadata and controls
113 lines (94 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include "main.h"
#include "sdr.h"
#include "socket.h"
#include "buffer.h"
#include "socket_feed.h"
extern buffer_t tcp_samples_buffer;
extern buffer_t rtltcp_samples_buffer;
extern netclient_t tcp_clients[TCP_CLIENTS_MAX];
extern netclient_t rtltcp_clients[RTLTCP_CLIENTS_MAX];
void *rx_tcp_feed(void* arg)
{
(void) arg;
int i, r;
tcp_samples_t *tcp_samples;
int tcp_samples_size = ( sizeof(tcp_samples_t)/sizeof(char) );
while(1)
{
Buffer_WaitPop(&tcp_samples_buffer, (void **)&tcp_samples);
for(i = 0; i < TCP_CLIENTS_MAX; i++)
{
if(tcp_clients[i].sock <= 0) continue;
r = send(tcp_clients[i].sock, tcp_samples, tcp_samples_size, 0);
if(r < 0)
{
if(errno == EAGAIN || errno == EWOULDBLOCK)
{
/* The socket is busy, we should try again later */
/* but for now, drop the connection i
netclient_t tcp_clients[TCP_CLIENTS_MAX];
netclient_t rtltcp_clients[RTLTCP_CLIENTS_MAX];mmediately */
fprintf(stderr, "TCP Client Socket blocked, dropped.\n");
Socket_close(&tcp_clients[i]);
break;
}
/* An error has occured. Drop the connection */
fprintf(stderr, "TCP Client Socket errored, dropped.\n");
Socket_close(&tcp_clients[i]);
break;
}
}
}
}
void *rx_rtltcp_feed(void* arg)
{
(void) arg;
int i, r;
rtltcp_samples_t *rtltcp_samples;
int rtltcp_samples_size = ( sizeof(rtltcp_samples_t)/sizeof(char) );
//int j=0;
while(1)
{
Buffer_WaitPop(&rtltcp_samples_buffer, (void **)&rtltcp_samples);
//fprintf(stdout, "%d\n", j++);
/*fprintf(stdout, "%d | %d (%d)\n"
, Buffer_Head(&rtltcp_samples_buffer)
, Buffer_Tail(&rtltcp_samples_buffer)
, Buffer_Loss(&rtltcp_samples_buffer)
);*/
for(i = 0; i < RTLTCP_CLIENTS_MAX; i++)
{
if(rtltcp_clients[i].sock <= 0) continue;
/* DEBUG print of samples */ /*
fprintf(stdout, "\nNET 500:\n");
for(int i=0; i<500; i++)
{
fprintf(stdout, "%d,", ((uint8_t *)rtltcp_samples)[i]);
} */
r = send(rtltcp_clients[i].sock, (void *)rtltcp_samples, rtltcp_samples_size, 0);
if(r < 0)
{
if(errno == EAGAIN || errno == EWOULDBLOCK)
{
/* The socket is busy, we should try again later */
/* but for now, drop the connection immediately */
fprintf(stderr, "RTLTCP Client Socket blocked, dropped.\n");
Socket_close(&rtltcp_clients[i]);
break;
}
/* An error has occured. Drop the connection */
fprintf(stderr, "RTLTCP Client Socket errored, dropped.\n");
Socket_close(&rtltcp_clients[i]);
break;
}
}
}
}